Skip to content

Bug: run_streamed Buffers tool_call_item Events, Delaying Real-Time Feedback #1282

@habema

Description

@habema

Describe the bug

The Runner.run_streamed() method buffers tool_call_item events and only emits them when the tool actually starts executing, rather than streaming them immediately when the tool call is made. This significantly delays real-time feedback in streaming applications and defeats the purpose of using streamed execution for responsive UIs.

Debug information

  • Agents SDK version: 0.2.3
  • Python version: 3.10.16

Repro steps

import asyncio import datetime import time from agents import Agent, ItemHelpers, Runner, function_tool @function_tool def get_server_time() -> str: time.sleep(10) # Simulate a slow tool return datetime.datetime.now().isoformat() async def main(): agent = Agent( name="TimeKeeper", instructions="First call the `get_server_time` tool to get the current server time, then tell the user what time it is.", tools=[get_server_time], ) result = Runner.run_streamed(agent, input="Hello") print("=== Run starting ===") async for event in result.stream_events(): timestamp = datetime.datetime.now().strftime("%H:%M:%S.%f")[:-3] if event.type == "run_item_stream_event": if event.item.type == "tool_call_item": print(f"[{timestamp}] -- Tool was called") elif event.item.type == "tool_call_output_item": print(f"[{timestamp}] -- Tool output: {event.item.output}") print("=== Run complete ===") if __name__ == "__main__": asyncio.run(main())

Current output:

=== Run starting === [15:44:50.553] Agent updated: TimeKeeper [15:45:01.710] -- Tool was called # ← This appears AFTER the 10-second delay [15:45:01.710] -- Tool output: 2025-07-28T15:45:01.708868 === Run complete === 

Expected behavior

The tool_call_item event should be emitted immediately when the agent decides to call a tool, not when the tool starts executing. The expected output should be:

=== Run starting === [15:44:50.553] Agent updated: TimeKeeper [15:44:50.XXX] -- Tool was called # ← Should appear immediately # ... 10 second delay while tool executes ... [15:45:01.710] -- Tool output: 2025-07-28T15:45:01.708868 === Run complete === 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions