Skip to content

Commit 465b45e

Browse files
authored
fix(realtime): include tool arguments in RealtimeToolStart/RealtimeToolEnd events (#2028)
1 parent 15ad038 commit 465b45e

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/agents/realtime/events.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class RealtimeToolStart:
6969
"""The agent that updated."""
7070

7171
tool: Tool
72+
"""The tool being called."""
73+
74+
arguments: str
75+
"""The arguments passed to the tool as a JSON string."""
7276

7377
info: RealtimeEventInfo
7478
"""Common info for all events, such as the context."""
@@ -86,6 +90,9 @@ class RealtimeToolEnd:
8690
tool: Tool
8791
"""The tool that was called."""
8892

93+
arguments: str
94+
"""The arguments passed to the tool as a JSON string."""
95+
8996
output: Any
9097
"""The output of the tool call."""
9198

src/agents/realtime/session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ async def _handle_tool_call(
411411
info=self._event_info,
412412
tool=function_map[event.name],
413413
agent=agent,
414+
arguments=event.arguments,
414415
)
415416
)
416417

@@ -436,6 +437,7 @@ async def _handle_tool_call(
436437
tool=func_tool,
437438
output=result,
438439
agent=agent,
440+
arguments=event.arguments,
439441
)
440442
)
441443
elif event.name in handoff_map:

tests/realtime/test_session.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,13 +986,15 @@ async def test_function_tool_execution_success(
986986
assert isinstance(tool_start_event, RealtimeToolStart)
987987
assert tool_start_event.tool == mock_function_tool
988988
assert tool_start_event.agent == mock_agent
989+
assert tool_start_event.arguments == '{"param": "value"}'
989990

990991
# Check tool end event
991992
tool_end_event = await session._event_queue.get()
992993
assert isinstance(tool_end_event, RealtimeToolEnd)
993994
assert tool_end_event.tool == mock_function_tool
994995
assert tool_end_event.output == "function_result"
995996
assert tool_end_event.agent == mock_agent
997+
assert tool_end_event.arguments == '{"param": "value"}'
996998

997999
@pytest.mark.asyncio
9981000
async def test_function_tool_with_multiple_tools_available(self, mock_model, mock_agent):
@@ -1111,6 +1113,7 @@ async def test_function_tool_exception_handling(
11111113
assert session._event_queue.qsize() == 1
11121114
tool_start_event = await session._event_queue.get()
11131115
assert isinstance(tool_start_event, RealtimeToolStart)
1116+
assert tool_start_event.arguments == "{}"
11141117

11151118
# But no tool output should have been sent and no end event queued
11161119
assert len(mock_model.sent_tool_outputs) == 0
@@ -1133,10 +1136,20 @@ async def test_tool_call_with_complex_arguments(
11331136

11341137
await session._handle_tool_call(tool_call_event)
11351138

1136-
# Verify arguments were passed correctly
1139+
# Verify arguments were passed correctly to tool
11371140
call_args = mock_function_tool.on_invoke_tool.call_args
11381141
assert call_args[0][1] == complex_args
11391142

1143+
# Verify tool_start event includes arguments
1144+
tool_start_event = await session._event_queue.get()
1145+
assert isinstance(tool_start_event, RealtimeToolStart)
1146+
assert tool_start_event.arguments == complex_args
1147+
1148+
# Verify tool_end event includes arguments
1149+
tool_end_event = await session._event_queue.get()
1150+
assert isinstance(tool_end_event, RealtimeToolEnd)
1151+
assert tool_end_event.arguments == complex_args
1152+
11401153
@pytest.mark.asyncio
11411154
async def test_tool_call_with_custom_call_id(self, mock_model, mock_agent, mock_function_tool):
11421155
"""Test that tool context receives correct call_id"""

0 commit comments

Comments
 (0)