-
Notifications
You must be signed in to change notification settings - Fork 581
fix(openai-agents): Patch functions following library refactor #5439
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
base: master
Are you sure you want to change the base?
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 6.47s All tests are passing successfully. ❌ Patch coverage is 1.14%. Project has 13731 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
There was a problem hiding this comment.
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.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| """Patched _run_single_turn that creates agent invocation spans""" | ||
| return await _single_turn(original_run_single_turn, *args, **kwargs) | ||
|
|
||
| agents.run.run_single_turn = patched_run_single_turn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Patch targets wrong module for v0.8+ single turn
High Severity
_patch_run_loop_run_single_turn patches agents.run.run_single_turn but the function lives in agents.run_internal.run_loop. Every other v0.8+ patch function targets agents.run_internal.* — the streaming counterpart _patch_run_loop_run_single_turn_streamed correctly patches agents.run_internal.run_loop.run_single_turn_streamed. This means the non-streaming single-turn instrumentation is applied to the wrong module attribute and won't intercept actual library calls on v0.8+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know but you have the patch the reference used by the library.
|
|
||
| def _patch_run_get_all_tools() -> None: | ||
| agents.run.get_all_tools = _create_run_internal_get_all_tools_wrapper( | ||
| run_loop.get_all_tools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Patch targets wrong module for v0.8+ tools
High Severity
_patch_run_get_all_tools patches agents.run.get_all_tools but reads the original from run_loop.get_all_tools (i.e., agents.run_internal.run_loop). The analogous v0.8+ function _patch_run_internal_get_model correctly patches agents.run_internal.run_loop.get_model. This mismatch means tool wrapping instrumentation won't intercept actual library calls on v0.8+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know but you have the patch the reference used by the library.
| exc_info = sys.exc_info() | ||
| with capture_internal_exceptions(): | ||
| _close_streaming_workflow_span(agent) | ||
| reraise(*exc_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The patch for run_single_turn is applied to agents.run.run_single_turn but should be applied to agents.run_internal.run_loop.run_single_turn, causing instrumentation to fail silently.
Severity: HIGH
Suggested Fix
Update the patch locations to match where the original functions were retrieved from. For run_single_turn, change the patch target from agents.run.run_single_turn to agents.run_internal.run_loop.run_single_turn. A similar fix is needed for get_all_tools.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry_sdk/integrations/openai_agents/patches/agent_run.py#L143
Potential issue: For `openai-agents` v0.8+, the patching logic for `run_single_turn` and
`get_all_tools` is incorrect. The code retrieves the original functions from the
`agents.run_internal.run_loop` module but applies the patches to the `agents.run`
module. Because the library calls the functions from their original
`agents.run_internal.run_loop` location, the patched versions are never invoked. This
will cause the instrumentation to silently fail for agent invocations and tool
executions, meaning no spans will be created for these operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know but you have the patch the reference used by the library.


Description
With the commit below, functions were moved and converted from class methods to standalone functions.
Introduce a top-level version check in
setup_once()to only patch the functions that exist depending on the library version.openai/openai-agents-python@3ce7c24#diff-7470b3a5c5cbe2fcbb2703dc24f326f45a5819d853be2b1f395d122d278cd911
Issues
Closes #5433
Closes #5429
Reminders
tox -e linters.feat:,fix:,ref:,meta:)