Skip to content

Commit 3cea592

Browse files
committed
fix(realtime): include tool arguments in RealtimeToolStart events
Fixes #1663
1 parent 0c4f2b9 commit 3cea592

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/agents/realtime/events.py

Lines changed: 4 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."""

src/agents/realtime/session.py

Lines changed: 1 addition & 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

tests/realtime/test_session.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ 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()
@@ -1111,6 +1112,7 @@ async def test_function_tool_exception_handling(
11111112
assert session._event_queue.qsize() == 1
11121113
tool_start_event = await session._event_queue.get()
11131114
assert isinstance(tool_start_event, RealtimeToolStart)
1115+
assert tool_start_event.arguments == "{}"
11141116

11151117
# But no tool output should have been sent and no end event queued
11161118
assert len(mock_model.sent_tool_outputs) == 0
@@ -1133,10 +1135,15 @@ async def test_tool_call_with_complex_arguments(
11331135

11341136
await session._handle_tool_call(tool_call_event)
11351137

1136-
# Verify arguments were passed correctly
1138+
# Verify arguments were passed correctly to tool
11371139
call_args = mock_function_tool.on_invoke_tool.call_args
11381140
assert call_args[0][1] == complex_args
11391141

1142+
# Verify tool_start event includes arguments
1143+
tool_start_event = await session._event_queue.get()
1144+
assert isinstance(tool_start_event, RealtimeToolStart)
1145+
assert tool_start_event.arguments == complex_args
1146+
11401147
@pytest.mark.asyncio
11411148
async def test_tool_call_with_custom_call_id(self, mock_model, mock_agent, mock_function_tool):
11421149
"""Test that tool context receives correct call_id"""

0 commit comments

Comments
 (0)