fix(openai-agents): Patch functions following library refactor#5439
fix(openai-agents): Patch functions following library refactor#5439alexander-alderman-webb wants to merge 6 commits intomasterfrom
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: 4.35s All tests are passing successfully. ❌ Patch coverage is 1.14%. Project has 13732 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
There was a problem hiding this comment.
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.
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.
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.
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.
I know but you have the patch the reference used by the library.
| agents.run_internal.run_loop.get_model = _create_turn_preparation_get_model_wrapper( | ||
| turn_preparation.get_model |
There was a problem hiding this comment.
Bug: The patch for get_model wraps turn_preparation.get_model but assigns the result to agents.run_internal.run_loop.get_model. This inconsistency may cause instrumentation to fail silently.
Severity: MEDIUM
Suggested Fix
To ensure the patch is effective, assign the wrapped function back to its original location. Change the assignment target from agents.run_internal.run_loop.get_model to turn_preparation.get_model, which is the source of the function being wrapped.
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/__init__.py#L52-L53
Potential issue: The monkeypatch for `get_model` in the `openai-agents` integration
(v0.8+) is inconsistent. It wraps the function from `turn_preparation.get_model` but
assigns the patched version to a different location,
`agents.run_internal.run_loop.get_model`. If the `openai-agents` library internally
calls the original `turn_preparation.get_model` function, the patch will not be applied.
This would cause the instrumentation to fail silently, and no model tracing data would
be captured for this function call.
There was a problem hiding this comment.
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:)