Skip to content

Add tool call parameters for on_tool_start hook #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

yanmxa
Copy link

@yanmxa yanmxa commented Mar 20, 2025

Resolve: #252

@louis-sanna-eki
Copy link

louis-sanna-eki commented Apr 10, 2025

@yanmxa thanks for doing this work, very useful!

@yanmxa yanmxa requested a review from mini-peanut April 17, 2025 13:57
@yanmxa yanmxa force-pushed the br_tool_hooks branch 4 times, most recently from fccd3fa to 656f211 Compare April 26, 2025 05:55
@wesleytao
Copy link

much needed feature!

@mattmorgis
Copy link

I learned that if you use Runner.run_streamed(), they provide a RunItemStreamEvent, one of which is type tool_called. It gives you a full RunItem which has the tool arguments. I think this is the preferred approach because it uses SSE from the responses api.

Example:

result = Runner.run_streamed(
    agent,
    input,
)
async for event in result.stream_events():
    if event.type == "run_item_stream_event":
        if event.name == "tool_called":
            print(
                f"-- Tool {event.item.raw_item.name} was called with args: {event.item.raw_item.arguments} "
            )
        elif event.name == "reasoning_item_created":
            summary = event.item.raw_item.summary
            # there’s at least one summary part
            # o-series models will send this every response, it is sometimes blank
            if summary:
                text = summary[0].text
                print(f"-- Reasoning item created: {text}")
                print("--")
        elif event.name == "message_output_created":
            print(event.item.raw_item.content[0].text)
        else:
            pass  # Ignore other event types

Copy link
Collaborator

@rm-openai rm-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for missing this PR. It looks good, but is a breaking change. We could certainly make a breaking change but I'd like to avoid it unless absolutely necessary. Another option could be to add a new method for the args. Thoughts on which would be better?

Signed-off-by: myan <myan@redhat.com>
@yanmxa
Copy link
Author

yanmxa commented Jul 16, 2025

Thanks @rm-openai!

I tend to favor the breaking change approach because:

  1. Adding a new method (like on_tool_start_with_args()) creates API confusion - developers would choose between two similar hooks, and we'd maintain both forever

  2. Simple migration - users just replace tool with action, then access tool via action.function_tool

  3. Clean long-term design - one unified hook that provides complete information

The community feedback shows this is needed. A clean break now might be better than API fragmentation.

What do you think?

yanmxa and others added 3 commits July 16, 2025 10:20
- Fix import sorting in multiple files
- Remove duplicate ResponseComputerToolCall import
- Organize imports according to ruff rules

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Function tools should use tool_context (ToolContext)
- Computer/shell tools use context_wrapper (RunContextWrapper)
- This maintains consistency with original codebase

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove .vscode/ directory and all IDE-specific configuration
- These files should not be included in the repository

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance on_tool_start Hook to Include Tool Call Arguments
7 participants