Skip to content

Conversation

@alexander-alderman-webb
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Feb 12, 2026

Description

The AgentRunner._get_model() class method has been moved to the function agents.run_internal.turn_preparation.get_model().

Patch the new function by re-using existing wrapper logic.

Issues

Reminders

@alexander-alderman-webb alexander-alderman-webb changed the title fix(openai-agents): Patch tool functions following library refactor fix(openai-agents): Patch models functions following library refactor Feb 12, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

Openai Agents

  • Patch models functions following library refactor by alexander-alderman-webb in #5449
  • Patch tool functions following library refactor by alexander-alderman-webb in #5445

Other

  • (celery) Close the connection we're reading driver_type from by sentrivana in #5427

Documentation 📚

  • Document openai-agents control-flow by alexander-alderman-webb in #5447

Internal Changes 🔧

  • (ci) Improve Craft config with title stripping and artifact filtering by BYK in #5444
  • (openai-agents) Avoid calling SDK-internal functions by alexander-alderman-webb in #5437
  • Remove references to unsupported attribute types by alexander-alderman-webb in #5425
  • Pin setuptools for linting and chalice tests by alexander-alderman-webb in #5438

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

Codecov Results 📊

25 failed | Total: 25 | Pass Rate: 0% | Execution Time: 1m 54s

❌ Patch coverage is 0.00%. Project has 17827 uncovered lines.

Files with missing lines (184)
File Patch % Lines
utils.py 17.89% ⚠️ 748 Missing and 4 partials
langchain.py 0.00% ⚠️ 610 Missing
scope.py 28.01% ⚠️ 591 Missing and 10 partials
openai.py 0.00% ⚠️ 521 Missing
tracing_utils.py 17.06% ⚠️ 486 Missing and 1 partials
utils.py 0.00% ⚠️ 479 Missing
client.py 18.53% ⚠️ 409 Missing
__init__.py 0.00% ⚠️ 394 Missing
tracing.py 23.58% ⚠️ 363 Missing
starlette.py 0.00% ⚠️ 356 Missing
transport.py 21.01% ⚠️ 312 Missing
anthropic.py 0.00% ⚠️ 272 Missing
mcp.py 0.00% ⚠️ 267 Missing
transaction_profiler.py 21.19% ⚠️ 264 Missing
utils.py 0.00% ⚠️ 255 Missing
continuous_profiler.py 23.00% ⚠️ 241 Missing
__init__.py 0.00% ⚠️ 230 Missing
langgraph.py 0.00% ⚠️ 227 Missing
__init__.py 0.00% ⚠️ 214 Missing
span_processor.py 0.00% ⚠️ 205 Missing
aws_lambda.py 0.00% ⚠️ 200 Missing
strawberry.py 0.00% ⚠️ 199 Missing
huggingface_hub.py 0.00% ⚠️ 180 Missing
sanic.py 0.00% ⚠️ 177 Missing
aiohttp.py 0.00% ⚠️ 166 Missing
spark_driver.py 0.00% ⚠️ 166 Missing
serializer.py 11.83% ⚠️ 164 Missing
logging.py 0.00% ⚠️ 153 Missing
litestar.py 0.00% ⚠️ 146 Missing
cloud_resource_context.py 0.00% ⚠️ 145 Missing
ai_client.py 0.00% ⚠️ 145 Missing
envelope.py 26.15% ⚠️ 144 Missing
spotlight.py 0.00% ⚠️ 144 Missing
starlite.py 0.00% ⚠️ 144 Missing
rust_tracing.py 0.00% ⚠️ 143 Missing
asgi.py 0.00% ⚠️ 140 Missing
litellm.py 0.00% ⚠️ 138 Missing
stdlib.py 0.00% ⚠️ 134 Missing
flask.py 0.00% ⚠️ 128 Missing
_wsgi_common.py 0.00% ⚠️ 127 Missing
wsgi.py 0.00% ⚠️ 127 Missing
cohere.py 0.00% ⚠️ 126 Missing
falcon.py 0.00% ⚠️ 123 Missing
arq.py 0.00% ⚠️ 121 Missing
pymongo.py 0.00% ⚠️ 118 Missing
quart.py 0.00% ⚠️ 118 Missing
beat.py 0.00% ⚠️ 116 Missing
asyncpg.py 0.00% ⚠️ 112 Missing
utils.py 0.00% ⚠️ 112 Missing
dramatiq.py 0.00% ⚠️ 110 Missing
tornado.py 0.00% ⚠️ 110 Missing
agent_run.py 0.00% ⚠️ 110 Missing
pyramid.py 0.00% ⚠️ 109 Missing
asgi.py 0.00% ⚠️ 109 Missing
hub.py 45.60% ⚠️ 105 Missing and 3 partials
caching.py 0.00% ⚠️ 106 Missing
sessions.py 21.05% ⚠️ 105 Missing
bottle.py 0.00% ⚠️ 103 Missing
utils.py 0.00% ⚠️ 103 Missing
models.py 0.00% ⚠️ 101 Missing
templates.py 0.00% ⚠️ 100 Missing
gcp.py 0.00% ⚠️ 98 Missing
otlp.py 0.00% ⚠️ 97 Missing
loguru.py 0.00% ⚠️ 95 Missing
threading.py 0.00% ⚠️ 95 Missing
__init__.py 0.00% ⚠️ 93 Missing
clickhouse_driver.py 0.00% ⚠️ 91 Missing
middleware.py 0.00% ⚠️ 90 Missing
agent_run.py 0.00% ⚠️ 90 Missing
runner.py 0.00% ⚠️ 87 Missing
ray.py 0.00% ⚠️ 84 Missing
ariadne.py 0.00% ⚠️ 83 Missing
beam.py 0.00% ⚠️ 83 Missing
monitoring.py 0.00% ⚠️ 82 Missing
fastapi.py 0.00% ⚠️ 82 Missing
asyncio.py 0.00% ⚠️ 80 Missing
gql.py 0.00% ⚠️ 79 Missing
huey.py 0.00% ⚠️ 79 Missing
invoke_agent.py 0.00% ⚠️ 79 Missing
graphene.py 0.00% ⚠️ 78 Missing
rq.py 0.00% ⚠️ 78 Missing
sqlalchemy.py 0.00% ⚠️ 78 Missing
session.py 15.56% ⚠️ 76 Missing
utils.py 0.00% ⚠️ 75 Missing
boto3.py 0.00% ⚠️ 74 Missing
httpx.py 0.00% ⚠️ 73 Missing
pure_eval.py 0.00% ⚠️ 72 Missing
worker.py 22.83% ⚠️ 71 Missing
chalice.py 0.00% ⚠️ 68 Missing
transactions.py 0.00% ⚠️ 67 Missing
_queue.py 26.67% ⚠️ 66 Missing
api.py 55.70% ⚠️ 66 Missing
streaming.py 0.00% ⚠️ 62 Missing
__init__.py 33.33% ⚠️ 60 Missing and 1 partials
caches.py 0.00% ⚠️ 59 Missing
propagator.py 0.00% ⚠️ 57 Missing
server.py 0.00% ⚠️ 56 Missing
spark_worker.py 0.00% ⚠️ 56 Missing
_batcher.py 31.25% ⚠️ 55 Missing
scrubber.py 21.74% ⚠️ 54 Missing
_asgi_common.py 0.00% ⚠️ 54 Missing
graph_nodes.py 0.00% ⚠️ 52 Missing
gnu_backtrace.py 0.00% ⚠️ 51 Missing
_async_common.py 0.00% ⚠️ 51 Missing
socket.py 0.00% ⚠️ 50 Missing
views.py 0.00% ⚠️ 50 Missing
_sync_common.py 0.00% ⚠️ 50 Missing
tools.py 0.00% ⚠️ 49 Missing
__init__.py 0.00% ⚠️ 47 Missing
invoke_agent.py 0.00% ⚠️ 46 Missing
traces.py 47.06% ⚠️ 45 Missing
signals_handlers.py 0.00% ⚠️ 44 Missing
monitor.py 29.51% ⚠️ 43 Missing
utils.py 22.22% ⚠️ 42 Missing and 1 partials
client.py 0.00% ⚠️ 40 Missing
logger.py 0.00% ⚠️ 39 Missing
executing.py 0.00% ⚠️ 38 Missing
client.py 0.00% ⚠️ 38 Missing
_span_batcher.py 35.71% ⚠️ 36 Missing
serverless.py 0.00% ⚠️ 36 Missing
server.py 0.00% ⚠️ 35 Missing
redis_cluster.py 0.00% ⚠️ 34 Missing
atexit.py 0.00% ⚠️ 32 Missing
excepthook.py 0.00% ⚠️ 32 Missing
sys_exit.py 0.00% ⚠️ 32 Missing
_openai_completions_api.py 0.00% ⚠️ 31 Missing
launchdarkly.py 0.00% ⚠️ 31 Missing
queries.py 0.00% ⚠️ 31 Missing
trytond.py 0.00% ⚠️ 30 Missing
ai_client.py 0.00% ⚠️ 30 Missing
integration.py 0.00% ⚠️ 30 Missing
error_tracing.py 0.00% ⚠️ 29 Missing
__init__.py 0.00% ⚠️ 29 Missing
_compat.py 30.77% ⚠️ 27 Missing
_werkzeug.py 0.00% ⚠️ 27 Missing
dedupe.py 32.50% ⚠️ 27 Missing
tools.py 0.00% ⚠️ 27 Missing
execute_tool.py 0.00% ⚠️ 26 Missing
typer.py 0.00% ⚠️ 24 Missing
tasks.py 0.00% ⚠️ 24 Missing
_lru_cache.py 23.33% ⚠️ 23 Missing
statsig.py 0.00% ⚠️ 23 Missing
decorator.py 37.14% ⚠️ 22 Missing
_log_batcher.py 0.00% ⚠️ 21 Missing
attachments.py 27.59% ⚠️ 21 Missing
unraisablehook.py 0.00% ⚠️ 21 Missing
openfeature.py 0.00% ⚠️ 20 Missing
execute_tool.py 0.00% ⚠️ 20 Missing
redis.py 0.00% ⚠️ 20 Missing
feature_flags.py 40.63% ⚠️ 19 Missing
unleash.py 0.00% ⚠️ 19 Missing
__init__.py 0.00% ⚠️ 18 Missing
model_request.py 0.00% ⚠️ 18 Missing
modules.py 0.00% ⚠️ 17 Missing
utils.py 0.00% ⚠️ 17 Missing
argv.py 0.00% ⚠️ 16 Missing
utils.py 0.00% ⚠️ 16 Missing
redis_py_cluster_legacy.py 0.00% ⚠️ 15 Missing
_init_implementation.py 45.83% ⚠️ 13 Missing
_types.py 60.00% ⚠️ 12 Missing
types.py 0.00% ⚠️ 12 Missing
api.py 37.50% ⚠️ 10 Missing
handoff.py 0.00% ⚠️ 10 Missing
rb.py 0.00% ⚠️ 10 Missing
metrics.py 47.06% ⚠️ 9 Missing
_openai_responses_api.py 0.00% ⚠️ 9 Missing
_metrics_batcher.py 65.00% ⚠️ 7 Missing
agent_workflow.py 0.00% ⚠️ 7 Missing
consts.py 0.00% ⚠️ 7 Missing
consts.py 0.00% ⚠️ 7 Missing
debug.py 82.61% ⚠️ 4 Missing and 1 partials
__init__.py 0.00% ⚠️ 5 Missing
__init__.py 0.00% ⚠️ 5 Missing
consts.py 0.00% ⚠️ 4 Missing
__init__.py 0.00% ⚠️ 4 Missing
__init__.py 0.00% ⚠️ 3 Missing
__init__.py 0.00% ⚠️ 3 Missing
__init__.py 0.00% ⚠️ 3 Missing
__init__.py 0.00% ⚠️ 3 Missing
consts.py 99.16% ⚠️ 2 Missing
__init__.py 0.00% ⚠️ 1 Missing
consts.py 0.00% ⚠️ 1 Missing
consts.py 0.00% ⚠️ 1 Missing
consts.py 0.00% ⚠️ 1 Missing

Generated by Codecov Action

@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review February 12, 2026 10:38
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner February 12, 2026 10:38
Copy link
Member

@ericapisani ericapisani left a comment

Choose a reason for hiding this comment

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

Small things, but otherwise LGTM 🚀

@wraps(original_fetch_response)
async def wrapped_fetch_response(*args: "Any", **kwargs: "Any") -> "Any":
response = await original_fetch_response(*args, **kwargs)
if hasattr(response, "model") and response.model:
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: I think an alternative approach that you could take here in order to make this conditional more concise (by removing the and part of the conditional) is to do the following:

Suggested change
if hasattr(response, "model") and response.model:
if getattr(response, "model", None):

This would also make things consistent with what you have on line 119 within the wrapped_get_response function.

Copy link
Contributor Author

@alexander-alderman-webb alexander-alderman-webb Feb 13, 2026

Choose a reason for hiding this comment

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

We need to rethink this response model business because we probably shouldn't be setting response models on agent spans either.

This was put in before I knew as much about agents, but there are libraries that let you vary the request model during agent execution as well (in particular Claude Code wrapped by the Claude Agent SDK).

Created an issue to track #5458

(and the plan would be to clean up as part of that issue).

Comment on lines +136 to +137
# Uses explicit try/finally instead of context manager to ensure cleanup
# even if the consumer abandons the stream (GeneratorExit).
Copy link
Member

Choose a reason for hiding this comment

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

This comment looks like it needs to be updated or removed as there's no try/finally below and the code uses a context manager 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're completely right, and it doesn't look like we catch GeneratorExit anywhere for that matter 😅 .

I'll keep this commit atomic since we're moving the contents of wrapped_get_model() to _get_model() as is now, and follow up with a PR after this first train is merged 🚅

Comment on lines +182 to +183
if hasattr(streaming_response, "model")
and streaming_response.model
Copy link
Member

Choose a reason for hiding this comment

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

Also a nitpick but similar to the comment I left above

Base automatically changed from webb/openai-agents/tool-patches to master February 13, 2026 08:15
Copy link

@cursor cursor bot left a 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 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

) -> "agents.Model":
return _get_model(turn_preparation.get_model, agent, run_config)

agents.run_internal.run_loop.get_model = new_wrapped_get_model
Copy link

Choose a reason for hiding this comment

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

Model patch applied to wrong module

Medium Severity

In the v0.8+ branch, the wrapper is built from turn_preparation.get_model but assigned to agents.run_internal.run_loop.get_model. This leaves turn_preparation.get_model unpatched, so the new model path can bypass _get_model instrumentation in patches/models.py.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants