Skip to content

arguments in tool_called streaming event with 0.2.10 #1629

@nasirus

Description

@nasirus

Summary

When using Runner.run_streamed() with tool calls, the arguments field in event.item.raw_item.arguments is empty during streaming events, despite the tool function receiving the correct arguments and executing properly.

Bug Description

In streaming mode, accessing tool call arguments through event.item.raw_item.arguments returns an empty string, while the actual tool function receives and processes the arguments correctly. This creates inconsistent behavior between what's visible in the stream events and what's actually passed to the tool.

Steps to Reproduce

  1. Create a simple agent with a tool that takes structured arguments
  2. Use Runner.run_streamed() to execute a query that triggers the tool
  3. Inspect the arguments field in streaming events of type tool_call_item

Minimal Reproduction Code

import asyncio
from agents import Agent, Runner, function_tool
from pydantic import BaseModel

class Location(BaseModel):
    lat: float
    long: float

@function_tool
async def fetch_weather(location: Location) -> str:
    """Fetch the weather for a given location.
    
    Args:
        location: The location to fetch the weather for.
    """
    print(f"Arguments from inside the function: {location.model_dump_json()}")
    return "sunny"

async def main():
    agent = Agent(
        name="Weather Agent",
        instructions="You are a helpful assistant.",
        tools=[fetch_weather],
    )
    
    result = Runner.run_streamed(agent, input="what is the weather in Tokyo?")
    async for event in result.stream_events():
        if event.type == "run_item_stream_event":
            if event.item.type == "tool_call_item":
                print(f"Tool call: {event.item.raw_item.name}")
                print(f"Arguments from outside the function: {event.item.raw_item.arguments}")

if __name__ == "__main__":
    asyncio.run(main())

Expected Behavior

The event.item.raw_item.arguments should contain the JSON string of the arguments being passed to the tool function, such as:

Arguments from outside the function: {"lat":35.6895,"long":139.6917}

Actual Behavior

The event.item.raw_item.arguments is empty:

Tool call: fetch_weather
Arguments from outside the function: 
Arguments from inside the function: {"lat":35.6895,"long":139.6917}

Environment Details

  • OpenAI Agents SDK version: 0.2.10
  • Python version: 3.12.0
  • Operating System: Windows

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