Skip to content

Enhance on_tool_start Hook to Include Tool Call Arguments #252

Open
@yanmxa

Description

@yanmxa

Please read this first

  • Have you read the docs?Agents SDK docs - Yes
  • Have you searched for related issues? Others may have had similar requesrs - Yes

Describe the feature

Currently, the on_tool_start hook in the Agents SDK only provides access to the Agent, Tool (definition), and context, but does not include the actual tool call arguments.

This limitation makes it difficult to trace and debug the agent's lifecycle, as there's no way to inspect the exact parameters passed to the tool before execution.

Proposed Enhancement:

Modify the on_tool_start hook definition to include the tool call arguments, providing full visibility into the tool invocation process.

  • Current Definition
async def on_tool_start(
    self,
    context: RunContextWrapper[TContext],
    agent: Agent[TContext],
    tool: Tool,
) -> None:
    """Called before a tool is invoked."""
    pass
  • Suggested Update
async def on_tool_start(
    self,
    context: RunContextWrapper[TContext],
    agent: Agent[TContext],
    action: Action, # Include the tool and the tool_call(arguments)
) -> None:
    """Called before a tool is invoked."""
    pass

Why This Improvement Matters:

  1. Improved Debugging & Tracing: Developers can log and analyze tool inputs before execution.
  2. Greater Flexibility: Hooks can validate or preprocess tool arguments before they are used.
  3. More Context for Hooks: Allows hooks to monitor execution flows with full tool call details.

Activity

linked a pull request that will close this issue on Mar 20, 2025
MrJarnould

MrJarnould commented on Mar 25, 2025

@MrJarnould

Until the linked PR is accepted, is there any other way to obtain the tool call arguments using hooks before the agent calls the tool?

vanhtuan0409

vanhtuan0409 commented on Mar 25, 2025

@vanhtuan0409

Until the linked PR is accepted, is there any other way to obtain the tool call arguments using hooks before the agent calls the tool?

Some workaround I think of is either using LLM tracing, put logging in tool implement or hijack the network call

yanmxa

yanmxa commented on Mar 28, 2025

@yanmxa
Author

@MrJarnould @vanhtuan0409 Yes, I do it in the tool calling internal for now. But it's more reasonable to put this in the tracing hook :)

MrJarnould

MrJarnould commented on Mar 28, 2025

@MrJarnould

I hope your PR gets reviewed soon!

Kalai9976

Kalai9976 commented on Apr 17, 2025

@Kalai9976

Any idea when this enhancement will be released ?

yanmxa

yanmxa commented on Apr 26, 2025

@yanmxa
Author

@rm-openai Could you please take a look at this issue? Thanks!

BarAshkenazi

BarAshkenazi commented on May 26, 2025

@BarAshkenazi

Very important. For now, I used the Runner.run_streamed to catch the tools calls, and I can get the args:

async for event in result.stream_events():
    if event.type == "run_item_stream_event" and event.item.type == "tool_call_item":
        print(event.item.raw_item.arguments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @BarAshkenazi@vanhtuan0409@yanmxa@MrJarnould@Kalai9976

      Issue actions

        Enhance `on_tool_start` Hook to Include Tool Call Arguments · Issue #252 · openai/openai-agents-python