Skip to content
Merged
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}