Skip to content

ref(openai-agents): Use first class tool hooks when available - #6994

Open
alexander-alderman-webb wants to merge 13 commits into
masterfrom
webb/use-tool-hooks
Open

ref(openai-agents): Use first class tool hooks when available#6994
alexander-alderman-webb wants to merge 13 commits into
masterfrom
webb/use-tool-hooks

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

Register a RunHooks instance or patch a user-provided hooks instance if it exists. Inject the resulting instance as the hooks keyword-only argument to AgentRunner.run() and AgentRunner.run_streamed().

Note that the hooks are only added starting with openai-agents version 0.3.2 as tool call arguments are unavailable in prior versions.

The openai-agents/patches/tools.py file can be removed in the next major due to redundancy with the hooks.

Rename responses_tool_call_model_responses by prefixing the fixture with nonstreaming_, and add a minimal equivalent streaming fixture. Add a variant of the test_tool_execution_span test that calls AgentRunner.run_streamed() instead of AgentRunner.run().

Issues

Closes #6988

Reminders

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

95162 passed | ⏭️ 6343 skipped | Total: 101505 | Pass Rate: 93.75% | Execution Time: 352m 59s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +180
Passed Tests 📈 +180
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 94.59%. Project has 2514 uncovered lines.
✅ Project coverage is 89.9%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
sentry_sdk/integrations/openai_agents/patches/runner.py 94.74% ⚠️ 3 Missing and 4 partials
sentry_sdk/integrations/openai_agents/patches/tools.py 87.50% ⚠️ 1 Missing and 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.88%    89.90%    +0.02%
==========================================
  Files          193       193         —
  Lines        24834     24889       +55
  Branches      8912      8936       +24
==========================================
+ Hits         22321     22375       +54
- Misses        2513      2514        +1
- Partials      1417      1419        +2

Generated by Codecov Action

Comment thread sentry_sdk/integrations/openai_agents/__init__.py Outdated
Comment thread sentry_sdk/integrations/openai_agents/patches/runner.py
Comment thread sentry_sdk/integrations/openai_agents/spans/execute_tool.py
Comment thread sentry_sdk/integrations/openai_agents/__init__.py
Comment thread sentry_sdk/integrations/openai_agents/__init__.py
Comment thread sentry_sdk/integrations/openai_agents/__init__.py
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review August 3, 2026 14:21
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code owner August 3, 2026 14:21
Comment thread sentry_sdk/integrations/openai_agents/patches/runner.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bb76a15. Configure here.

Comment thread sentry_sdk/integrations/openai_agents/patches/runner.py
Comment thread sentry_sdk/integrations/openai_agents/patches/runner.py
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as draft August 3, 2026 17:07
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review August 3, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use RunHooks.on_tool_start and RunHooks.on_tool_end

1 participant