Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(realtime): report tool call arguments in the event stream (#2593)
DavdGao4c4e31804642
diff --git a/src/agentscope/agent/_realtime/_agent.py b/src/agentscope/agent/_realtime/_agent.pyindex 7a1531149..fe109cf0d 100644--- a/src/agentscope/agent/_realtime/_agent.py+++ b/src/agentscope/agent/_realtime/_agent.py@@ -34,6 +34,7 @@ from ...event import (TextBlockDeltaEvent,TextBlockEndEvent,TextBlockStartEvent,+ ToolCallDeltaEvent,ToolCallEndEvent,ToolCallStartEvent,ToolResultEndEvent,@@ -984,6 +985,15 @@ class RealtimeAgent:tool_call_name=call.name,),)+ # The provider delivers the arguments in one piece, so a single+ # delta carries them; without it consumers rebuild an empty input.+ self._emit(+ ToolCallDeltaEvent(+ reply_id=reply_id,+ tool_call_id=call.id,+ delta=call.input,+ ),+ )self._emit(ToolCallEndEvent(reply_id=reply_id, tool_call_id=call.id))try:diff --git a/tests/realtime_agent_test.py b/tests/realtime_agent_test.pyindex 8a6ab52d7..e3c6612af 100644--- a/tests/realtime_agent_test.py+++ b/tests/realtime_agent_test.py@@ -662,6 +662,58 @@ class RealtimeAgentToolTest(IsolatedAsyncioTestCase):)self.assertIn("tool_result(c1,'boom')", model.calls)+ async def test_tool_call_arguments_reach_the_event_stream(self) -> None:+ """A client rebuilding the reply from the event stream sees the+ tool call's arguments, not an empty input."""+ model = ScriptedModel([_tool_script("stream_tool")])+ agent = RealtimeAgent(+ "Friday",+ "be brief",+ model,+ toolkit=Toolkit(tools=[StreamTool()]),+ )+ rebuilt = Msg(id="r1", role="assistant", name="Friday", content=[])+ async with agent:+ transport = FakeTransport(frames=4)+ async with transport:+ async for event in agent.reply_stream(transport):+ if getattr(event, "reply_id", None) == "r1":+ rebuilt.append_event(event)++ self.assertListEqual(+ [b.model_dump() for b in rebuilt.content],+ [+ {+ "type": "tool_call",+ "id": "c1",+ "name": "stream_tool",+ "input": '{"q": "x"}',+ "state": "finished",+ "suggested_rules": [],+ "created_at": AnyString(),+ "finished_at": AnyString(),+ },+ {+ "type": "tool_result",+ "id": "c1",+ "name": "stream_tool",+ "output": [+ {+ "type": "text",+ "text": "x-ax-b",+ "id": AnyString(),+ "created_at": AnyString(),+ "finished_at": None,+ },+ ],+ "state": "success",+ "metadata": {},+ "created_at": AnyString(),+ "finished_at": AnyString(),+ },+ ],+ )+class RealtimeAgentFullStreamTest(IsolatedAsyncioTestCase):"""The complete event stream of a turn that calls a tool and then@@ -867,6 +919,15 @@ class RealtimeAgentFullStreamTest(IsolatedAsyncioTestCase):"tool_call_id": "c1","tool_call_name": "stream_tool",},+ {+ "id": AnyString(),+ "created_at": AnyString(),+ "metadata": {},+ "type": "TOOL_CALL_DELTA",+ "reply_id": "r1",+ "tool_call_id": "c1",+ "delta": '{"q": "x"}',+ },{"id": AnyString(),"created_at": AnyString(),