Skip to content

Fix handoff transfer message JSON #818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/agents/handoffs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import inspect
import json
from collections.abc import Awaitable
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Callable, Generic, cast, overload
Expand Down Expand Up @@ -99,8 +100,7 @@ class Handoff(Generic[TContext]):
"""

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

@classmethod
def default_tool_name(cls, agent: Agent[Any]) -> str:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_handoff_tool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Any

import pytest
Expand Down Expand Up @@ -276,3 +277,10 @@ def test_handoff_input_schema_is_strict():
"additionalProperties" in obj.input_json_schema
and not obj.input_json_schema["additionalProperties"]
), "Input schema should be strict and have additionalProperties=False"


def test_get_transfer_message_is_valid_json() -> None:
agent = Agent(name="foo")
obj = handoff(agent)
transfer = obj.get_transfer_message(agent)
assert json.loads(transfer) == {"assistant": agent.name}