Skip to content

Commit 9aa8147

Browse files
committed
Merge branch 'master' into py-2071-get-driver-type-from-broker-url
2 parents a0ffa84 + d813f5c commit 9aa8147

14 files changed

Lines changed: 611 additions & 466 deletions

File tree

.github/workflows/test-integrations-flags.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
strategy:
3333
fail-fast: false
3434
matrix:
35-
python-version: ["3.7","3.8","3.9","3.12","3.13","3.14","3.14t"]
35+
python-version: ["3.7","3.8","3.9","3.10","3.12","3.13","3.14","3.14t"]
3636
# python3.6 reached EOL and is no longer being supported on
3737
# new versions of hosted runners on Github Actions
3838
# ubuntu-20.04 is the last version that supported python3.6

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pip-wheel-metadata
2929
.mypy_cache
3030
.vscode/
3131
.claude/
32+
.serena
3233
.tool-versions
3334

3435
# for running AWS Lambda tests using AWS SAM

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# Changelog
22

3+
## 2.53.0
4+
5+
### Bug Fixes 🐛
6+
7+
#### Openai Agents
8+
9+
- Patch `execute_final_output()` functions following library refactor by @alexander-alderman-webb in [#5453](https://github.com/getsentry/sentry-python/pull/5453)
10+
- Patch `execute_handoffs()` functions following library refactor by @alexander-alderman-webb in [#5452](https://github.com/getsentry/sentry-python/pull/5452)
11+
- Patch `run_single_turn_streamed()` functions following library refactor by @alexander-alderman-webb in [#5451](https://github.com/getsentry/sentry-python/pull/5451)
12+
- Patch `run_single_turn()` functions following library refactor by @alexander-alderman-webb in [#5450](https://github.com/getsentry/sentry-python/pull/5450)
13+
- Patch models functions following library refactor by @alexander-alderman-webb in [#5449](https://github.com/getsentry/sentry-python/pull/5449)
14+
- Patch tool functions following library refactor by @alexander-alderman-webb in [#5445](https://github.com/getsentry/sentry-python/pull/5445)
15+
16+
#### Other
17+
18+
- Close the connection we're reading driver_type from by @sentrivana in [#5427](https://github.com/getsentry/sentry-python/pull/5427)
19+
20+
### Documentation 📚
21+
22+
- Document `openai-agents` control-flow by @alexander-alderman-webb in [#5447](https://github.com/getsentry/sentry-python/pull/5447)
23+
24+
### Internal Changes 🔧
25+
26+
#### Openai Agents
27+
28+
- New tool field and library error log by @alexander-alderman-webb in [#5454](https://github.com/getsentry/sentry-python/pull/5454)
29+
- Avoid calling SDK-internal functions by @alexander-alderman-webb in [#5437](https://github.com/getsentry/sentry-python/pull/5437)
30+
31+
#### Other
32+
33+
- Improve Craft config with title stripping and artifact filtering by @BYK in [#5444](https://github.com/getsentry/sentry-python/pull/5444)
34+
- Use fixed clickhouse action, remove aws-sam-cli dependency by @sentrivana in [#5457](https://github.com/getsentry/sentry-python/pull/5457)
35+
- Remove references to unsupported attribute types by @alexander-alderman-webb in [#5425](https://github.com/getsentry/sentry-python/pull/5425)
36+
- Pin setuptools for linting and chalice tests by @alexander-alderman-webb in [#5438](https://github.com/getsentry/sentry-python/pull/5438)
37+
338
## 2.52.0
439

540
### New Features ✨

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
copyright = "2019-{}, Sentry Team and Contributors".format(datetime.now().year)
3232
author = "Sentry Team and Contributors"
3333

34-
release = "2.52.0"
34+
release = "2.53.0"
3535
version = ".".join(release.split(".")[:2]) # The short X.Y version.
3636

3737

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 23 additions & 22 deletions
Large diffs are not rendered by default.

scripts/populate_tox/releases.jsonl

Lines changed: 26 additions & 27 deletions
Large diffs are not rendered by default.

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,4 +1490,4 @@ def _get_default_options() -> "dict[str, Any]":
14901490
del _get_default_options
14911491

14921492

1493-
VERSION = "2.52.0"
1493+
VERSION = "2.53.0"

sentry_sdk/integrations/openai_agents/__init__.py

Lines changed: 136 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
from functools import wraps
55

66
from .patches import (
7-
_create_get_model_wrapper,
7+
_get_model,
88
_get_all_tools,
9+
_run_single_turn,
10+
_run_single_turn_streamed,
11+
_execute_handoffs,
912
_create_run_wrapper,
1013
_create_run_streamed_wrapper,
11-
_patch_agent_run,
14+
_execute_final_output,
1215
_patch_error_tracing,
1316
)
1417

@@ -30,9 +33,18 @@
3033
try:
3134
# AgentRunner methods moved in v0.8
3235
# https://github.com/openai/openai-agents-python/commit/3ce7c24d349b77bb750062b7e0e856d9ff48a5d5#diff-7470b3a5c5cbe2fcbb2703dc24f326f45a5819d853be2b1f395d122d278cd911
33-
from agents.run_internal import run_loop
36+
from agents.run_internal import run_loop, turn_preparation, turn_resolution
3437
except ImportError:
3538
run_loop = None
39+
turn_preparation = None
40+
turn_resolution = None
41+
42+
from typing import TYPE_CHECKING
43+
44+
if TYPE_CHECKING:
45+
from typing import Any
46+
47+
from agents.run_internal.run_steps import SingleStepResult
3648

3749

3850
def _patch_runner() -> None:
@@ -48,15 +60,6 @@ def _patch_runner() -> None:
4860
agents.run.DEFAULT_AGENT_RUNNER.run_streamed
4961
)
5062

51-
# Creating the actual spans for each agent run (works for both streaming and non-streaming).
52-
_patch_agent_run()
53-
54-
55-
def _patch_model() -> None:
56-
agents.run.AgentRunner._get_model = classmethod(
57-
_create_get_model_wrapper(agents.run.AgentRunner._get_model),
58-
)
59-
6063

6164
class OpenAIAgentsIntegration(Integration):
6265
"""
@@ -73,24 +76,23 @@ class OpenAIAgentsIntegration(Integration):
7376
- `Runner.run()` and `Runner.run_streamed()` are thin wrappers for `DEFAULT_AGENT_RUNNER.run()` and `DEFAULT_AGENT_RUNNER.run_streamed()`.
7477
- `DEFAULT_AGENT_RUNNER.run()` and `DEFAULT_AGENT_RUNNER.run_streamed()` are patched in `_patch_runner()` with `_create_run_wrapper()` and `_create_run_streamed_wrapper()`, respectively.
7578
3. In a loop, the agent repeatedly calls the Responses API, maintaining a conversation history that includes previous messages and tool results, which is passed to each call.
76-
- A Model instance is created at the start of the loop by calling the `Runner._get_model()`. We patch the Model instance using `_create_get_model_wrapper()` in `_patch_model()`.
79+
- A Model instance is created at the start of the loop by calling the `Runner._get_model()`. We patch the Model instance using `patches._get_model()`.
7780
- Available tools are also deteremined at the start of the loop, with `Runner._get_all_tools()`. We patch Tool instances by iterating through the returned tools in `patches._get_all_tools()`.
78-
- In each loop iteration, `run_single_turn()` or `run_single_turn_streamed()` is responsible for calling the Responses API, patched with `patched_run_single_turn()` and `patched_run_single_turn_streamed()`.
79-
4. On loop termination, `RunImpl.execute_final_output()` is called. The function is patched with `patched_execute_final_output()`.
81+
- In each loop iteration, `run_single_turn()` or `run_single_turn_streamed()` is responsible for calling the Responses API, patched with `patches._run_single_turn()` and `patches._run_single_turn_streamed()`.
82+
4. On loop termination, `RunImpl.execute_final_output()` is called. The function is patched with `patches._execute_final_output()`.
8083
8184
Local tools are run based on the return value from the Responses API as a post-API call step in the above loop.
8285
Hosted MCP Tools are run as part of the Responses API call, and involve OpenAI reaching out to an external MCP server.
8386
An agent can handoff to another agent, also directed by the return value of the Responses API and run post-API call in the loop.
8487
Handoffs are a way to switch agent-wide configuration.
85-
- Handoffs are executed by calling `RunImpl.execute_handoffs()`. The method is patched in `patched_execute_handoffs()`
88+
- Handoffs are executed by calling `RunImpl.execute_handoffs()`. The method is patched with `patches._execute_handoffs()`
8689
"""
8790

8891
identifier = "openai_agents"
8992

9093
@staticmethod
9194
def setup_once() -> None:
9295
_patch_error_tracing()
93-
_patch_model()
9496
_patch_runner()
9597

9698
library_version = parse_version(OPENAI_AGENTS_VERSION)
@@ -109,6 +111,61 @@ async def new_wrapped_get_all_tools(
109111
)
110112

111113
agents.run.get_all_tools = new_wrapped_get_all_tools
114+
115+
@wraps(turn_preparation.get_model)
116+
def new_wrapped_get_model(
117+
agent: "agents.Agent", run_config: "agents.RunConfig"
118+
) -> "agents.Model":
119+
return _get_model(turn_preparation.get_model, agent, run_config)
120+
121+
agents.run_internal.run_loop.get_model = new_wrapped_get_model
122+
123+
@wraps(run_loop.run_single_turn)
124+
async def new_wrapped_run_single_turn(
125+
*args: "Any", **kwargs: "Any"
126+
) -> "SingleStepResult":
127+
return await _run_single_turn(run_loop.run_single_turn, *args, **kwargs)
128+
129+
agents.run.run_single_turn = new_wrapped_run_single_turn
130+
131+
@wraps(run_loop.run_single_turn_streamed)
132+
async def new_wrapped_run_single_turn_streamed(
133+
*args: "Any", **kwargs: "Any"
134+
) -> "SingleStepResult":
135+
return await _run_single_turn_streamed(
136+
run_loop.run_single_turn_streamed, *args, **kwargs
137+
)
138+
139+
agents.run.run_single_turn_streamed = new_wrapped_run_single_turn_streamed
140+
141+
original_execute_handoffs = turn_resolution.execute_handoffs
142+
143+
@wraps(original_execute_handoffs)
144+
async def new_wrapped_execute_handoffs(
145+
*args: "Any", **kwargs: "Any"
146+
) -> "SingleStepResult":
147+
return await _execute_handoffs(
148+
original_execute_handoffs, *args, **kwargs
149+
)
150+
151+
agents.run_internal.turn_resolution.execute_handoffs = (
152+
new_wrapped_execute_handoffs
153+
)
154+
155+
original_execute_final_output = turn_resolution.execute_final_output
156+
157+
@wraps(turn_resolution.execute_final_output)
158+
async def new_wrapped_final_output(
159+
*args: "Any", **kwargs: "Any"
160+
) -> "SingleStepResult":
161+
return await _execute_final_output(
162+
original_execute_final_output, *args, **kwargs
163+
)
164+
165+
agents.run_internal.turn_resolution.execute_final_output = (
166+
new_wrapped_final_output
167+
)
168+
112169
return
113170

114171
original_get_all_tools = AgentRunner._get_all_tools
@@ -122,3 +179,65 @@ async def old_wrapped_get_all_tools(
122179
return await _get_all_tools(original_get_all_tools, agent, context_wrapper)
123180

124181
agents.run.AgentRunner._get_all_tools = classmethod(old_wrapped_get_all_tools)
182+
183+
original_get_model = AgentRunner._get_model
184+
185+
@wraps(AgentRunner._get_model.__func__)
186+
def old_wrapped_get_model(
187+
cls: "agents.Runner", agent: "agents.Agent", run_config: "agents.RunConfig"
188+
) -> "agents.Model":
189+
return _get_model(original_get_model, agent, run_config)
190+
191+
agents.run.AgentRunner._get_model = classmethod(old_wrapped_get_model)
192+
193+
original_run_single_turn = AgentRunner._run_single_turn
194+
195+
@wraps(AgentRunner._run_single_turn.__func__)
196+
async def old_wrapped_run_single_turn(
197+
cls: "agents.Runner", *args: "Any", **kwargs: "Any"
198+
) -> "SingleStepResult":
199+
return await _run_single_turn(original_run_single_turn, *args, **kwargs)
200+
201+
agents.run.AgentRunner._run_single_turn = classmethod(
202+
old_wrapped_run_single_turn
203+
)
204+
205+
original_run_single_turn_streamed = AgentRunner._run_single_turn_streamed
206+
207+
@wraps(AgentRunner._run_single_turn_streamed.__func__)
208+
async def old_wrapped_run_single_turn_streamed(
209+
cls: "agents.Runner", *args: "Any", **kwargs: "Any"
210+
) -> "SingleStepResult":
211+
return await _run_single_turn_streamed(
212+
original_run_single_turn_streamed, *args, **kwargs
213+
)
214+
215+
agents.run.AgentRunner._run_single_turn_streamed = classmethod(
216+
old_wrapped_run_single_turn_streamed
217+
)
218+
219+
original_execute_handoffs = agents._run_impl.RunImpl.execute_handoffs
220+
221+
@wraps(agents._run_impl.RunImpl.execute_handoffs.__func__)
222+
async def old_wrapped_execute_handoffs(
223+
cls: "agents.Runner", *args: "Any", **kwargs: "Any"
224+
) -> "SingleStepResult":
225+
return await _execute_handoffs(original_execute_handoffs, *args, **kwargs)
226+
227+
agents._run_impl.RunImpl.execute_handoffs = classmethod(
228+
old_wrapped_execute_handoffs
229+
)
230+
231+
original_execute_final_output = agents._run_impl.RunImpl.execute_final_output
232+
233+
@wraps(agents._run_impl.RunImpl.execute_final_output.__func__)
234+
async def old_wrapped_final_output(
235+
cls: "agents.Runner", *args: "Any", **kwargs: "Any"
236+
) -> "SingleStepResult":
237+
return await _execute_final_output(
238+
original_execute_final_output, *args, **kwargs
239+
)
240+
241+
agents._run_impl.RunImpl.execute_final_output = classmethod(
242+
old_wrapped_final_output
243+
)
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
from .models import _create_get_model_wrapper # noqa: F401
1+
from .models import _get_model # noqa: F401
22
from .tools import _get_all_tools # noqa: F401
33
from .runner import _create_run_wrapper, _create_run_streamed_wrapper # noqa: F401
4-
from .agent_run import _patch_agent_run # noqa: F401
4+
from .agent_run import (
5+
_run_single_turn,
6+
_run_single_turn_streamed,
7+
_execute_handoffs,
8+
_execute_final_output,
9+
) # noqa: F401
510
from .error_tracing import _patch_error_tracing # noqa: F401

0 commit comments

Comments
 (0)