-
Notifications
You must be signed in to change notification settings - Fork 614
fix(openai-agents): Patch tool functions following library refactor #5445
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
Changes from 3 commits
02af5df
a7f08cc
3679c96
0047eb3
722bf00
0a2ede8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| from sentry_sdk.integrations import DidNotEnable, Integration | ||
| from sentry_sdk.utils import parse_version | ||
|
|
||
| from .patches import ( | ||
| _create_get_model_wrapper, | ||
| _create_get_all_tools_wrapper, | ||
| _create_runner_get_all_tools_wrapper, | ||
| _create_run_loop_get_all_tools_wrapper, | ||
| _create_run_wrapper, | ||
| _create_run_streamed_wrapper, | ||
| _patch_agent_run, | ||
|
|
@@ -17,11 +19,21 @@ | |
| # after it, even if we don't use it. | ||
| import agents | ||
| from agents.run import DEFAULT_AGENT_RUNNER | ||
| from agents.version import __version__ as OPENAI_AGENTS_VERSION | ||
|
|
||
| except ImportError: | ||
| raise DidNotEnable("OpenAI Agents not installed") | ||
|
|
||
|
|
||
| try: | ||
| # AgentRunner methods moved in v0.8 | ||
| # https://github.com/openai/openai-agents-python/commit/3ce7c24d349b77bb750062b7e0e856d9ff48a5d5#diff-7470b3a5c5cbe2fcbb2703dc24f326f45a5819d853be2b1f395d122d278cd911 | ||
| from agents.run_internal import run_loop, turn_preparation | ||
| except ImportError: | ||
| run_loop = None | ||
| turn_preparation = None | ||
|
|
||
|
|
||
| def _patch_runner() -> None: | ||
| # Create the root span for one full agent run (including eventual handoffs) | ||
| # Note agents.run.DEFAULT_AGENT_RUNNER.run_sync is a wrapper around | ||
|
|
@@ -45,9 +57,15 @@ def _patch_model() -> None: | |
| ) | ||
|
|
||
|
|
||
| def _patch_tools() -> None: | ||
| def _patch_agent_runner_get_all_tools() -> None: | ||
| agents.run.AgentRunner._get_all_tools = classmethod( | ||
| _create_get_all_tools_wrapper(agents.run.AgentRunner._get_all_tools), | ||
| _create_runner_get_all_tools_wrapper(agents.run.AgentRunner._get_all_tools), | ||
| ) | ||
|
|
||
|
|
||
| def _patch_run_get_all_tools() -> None: | ||
| agents.run.get_all_tools = _create_run_loop_get_all_tools_wrapper( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're creating a lot of random indirection and cognitive overhead with these wrappers. I would just move the patching logic here in this function and remove those wrappers and just keep the |
||
| run_loop.get_all_tools | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
|
|
||
|
|
@@ -57,6 +75,15 @@ class OpenAIAgentsIntegration(Integration): | |
| @staticmethod | ||
| def setup_once() -> None: | ||
| _patch_error_tracing() | ||
| _patch_tools() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to avoid having the same if condition in all the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok then keep this for now, we'll look at the shape of the |
||
| _patch_model() | ||
| _patch_runner() | ||
|
|
||
| library_version = parse_version(OPENAI_AGENTS_VERSION) | ||
| if library_version is not None and library_version >= ( | ||
| 0, | ||
| 8, | ||
| ): | ||
| _patch_run_get_all_tools() | ||
| return | ||
|
alexander-alderman-webb marked this conversation as resolved.
|
||
|
|
||
| _patch_agent_runner_get_all_tools() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| from .models import _create_get_model_wrapper # noqa: F401 | ||
| from .tools import _create_get_all_tools_wrapper # noqa: F401 | ||
| from .tools import ( | ||
| _create_runner_get_all_tools_wrapper, | ||
| _create_run_loop_get_all_tools_wrapper, | ||
| ) # noqa: F401 | ||
| from .runner import _create_run_wrapper, _create_run_streamed_wrapper # noqa: F401 | ||
| from .agent_run import _patch_agent_run # noqa: F401 | ||
| from .error_tracing import _patch_error_tracing # noqa: F401 |
Uh oh!
There was an error while loading. Please reload this page.