Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ddtrace/contrib/internal/openai_agents/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ def patch():
agents._datadog_integration = integration

if OPENAI_AGENTS_VERSION >= (0, 0, 19):
wrap(agents.run.AgentRunner, "_run_single_turn", patched_run_single_turn(agents))
wrap(agents.run.AgentRunner, "_run_single_turn_streamed", patched_run_single_turn_streamed(agents))
if hasattr(agents.run.AgentRunner, "_run_single_turn"):
wrap(agents.run.AgentRunner, "_run_single_turn", patched_run_single_turn(agents))
if hasattr(agents.run.AgentRunner, "_run_single_turn_streamed"):
wrap(agents.run.AgentRunner, "_run_single_turn_streamed", patched_run_single_turn_streamed(agents))
Comment on lines +74 to +77
Copy link
Contributor

@dubloom dubloom Feb 20, 2026

Choose a reason for hiding this comment

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

Take a look at the whole workflow (with Bits).

That is super cool ! However, I'd say this looks a bit uncommon to me. As we can see in the code just above, when we have to do version specific patching, we tend to check the version instead of the "can we patch if yes we do"

else:
wrap(agents.run.Runner, "_run_single_turn", patched_run_single_turn(agents))
wrap(agents.run.Runner, "_run_single_turn_streamed", patched_run_single_turn_streamed(agents))
Expand All @@ -88,8 +90,10 @@ def unpatch():
agents._datadog_patch = False

if OPENAI_AGENTS_VERSION >= (0, 0, 19):
unwrap(agents.run.AgentRunner, "_run_single_turn")
unwrap(agents.run.AgentRunner, "_run_single_turn_streamed")
if hasattr(agents.run.AgentRunner, "_run_single_turn"):
unwrap(agents.run.AgentRunner, "_run_single_turn")
if hasattr(agents.run.AgentRunner, "_run_single_turn_streamed"):
unwrap(agents.run.AgentRunner, "_run_single_turn_streamed")
else:
unwrap(agents.run.Runner, "_run_single_turn")
unwrap(agents.run.Runner, "_run_single_turn_streamed")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
openai_agents: Fixes an ``AttributeError`` on ``openai-agents >= 0.8.0`` caused by the removal of ``AgentRunner._run_single_turn``.