8000 Fix handoff transfer message JSON (#818) · openai/openai-agents-python@c98e234 · GitHub
[go: up one dir, main page]

Skip to content

Commit c98e234

Browse files
authored
Fix handoff transfer message JSON (#818)
## Summary - ensure `Handoff.get_transfer_message` emits valid JSON - test transfer message validity ## Testing - `make format` - `make lint` - `make mypy` - `make tests` ------ https://chatgpt.com/codex/tasks/task_i_68432f925b048324a16878d28e850841
1 parent 5c7c678 commit c98e234

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/agents/handoffs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import inspect
4+
import json
45
from collections.abc import Awaitable
56
from dataclasses import dataclass
67
from typing import TYPE_CHECKING, Any, Callable, Generic, cast, overload
@@ -99,8 +100,7 @@ class Handoff(Generic[TContext]):
99100
"""
100101

101102
def get_transfer_message(self, agent: Agent[Any]) -> str:
102-
base = f"{{'assistant': '{agent.name}'}}"
103-
return base
103+
return json.dumps({"assistant": agent.name})
104104

105105
@classmethod
106106
def default_tool_name(cls, agent: Agent[Any]) -> str:

tests/test_handoff_tool.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from typing import Any
23

34
import pytest
@@ -276,3 +277,10 @@ def test_handoff_input_schema_is_strict():
276277
"additionalProperties" in obj.input_json_schema
277278
and not obj.input_json_schema["additionalProperties"]
278279
), "Input schema should be strict and have additionalProperties=False"
280+
281+
282+
def test_get_transfer_message_is_valid_json() -> None:
283+
agent = Agent(name="foo")
284+
obj = handoff(agent)
285+
transfer = obj.get_transfer_message(agent)
286+
assert json.loads(transfer) == {"assistant": agent.name}

0 commit comments

Comments
 (0)
0