Skip to content

How to Retrieve Tool Name from tool_call_item Event in Streaming? #1264

@dh1011

Description

@dh1011

Hello,

Thank you for the excellent work on this project! I'm currently working with the following code snippet to handle streaming events:

async for event in result.stream_events():
    # We'll ignore the raw responses event deltas
    if event.type == "raw_response_event":
        continue
    # When the agent updates, print that
    elif event.type == "agent_updated_stream_event":
        print(f"Agent updated: {event.new_agent.name}")
        continue
    # When items are generated, print them
    elif event.item.type == "tool_call_item":
        print("-- Tool was called")
    elif event.item.type == "tool_call_output_item":
        print(f"-- Tool output: {event.item.output}")
    elif event.item.type == "message_output_item":
        print(f"-- Message output:\n {ItemHelpers.text_message_output(event.item)}")
    else:
        pass  # Ignore other event types

I would like to print the name of the tool within the tool_call_item event section, but I'm not sure how to access it. Does the current implementation allow for retrieving the tool name? If so, could you please guide me on how to do this, or share if there are any plans to implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion about using the SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions