feat(usage): add agent_name and model_name to RequestUsage (#2100)#4
Open
adityasingh2400 wants to merge 151 commits into
Open
feat(usage): add agent_name and model_name to RequestUsage (#2100)#4adityasingh2400 wants to merge 151 commits into
adityasingh2400 wants to merge 151 commits into
Conversation
…enai#2714) Co-authored-by: Kazuhiro Sera <seratch@openai.com>
**Default guidance in public documentation** https://openai.github.io/openai-agents-python/ **Before** The public Agents SDK docs still mostly pointed realtime users at gpt-realtime, so new users were landing on stale guidance instead of the recommended gpt-realtime-1.5 path. This showed up in the top-level docs entry points and the English realtime quickstart/guide. **After** The public documentation now points new realtime users to gpt-realtime-1.5 in the top-level discovery pages and the English realtime quickstart/guide. The SDK’s implicit runtime default was intentionally left unchanged, so this updates guidance without changing behavior for existing integrations that omit model_name.
…er reasoning removal (openai#2728)
Co-authored-by: Kazuhiro Sera <seratch@openai.com>
Co-authored-by: Kazuhiro Sera <seratch@openai.com>
…esource on MCPServer (openai#2721)
This pull request improves sandbox backend persistence by extracting the common ephemeral mount teardown and restore flow into a shared session helper. Cloudflare and Vercel persistence now use the shared lifecycle wrapper for persist and hydrate operations while preserving existing archive error precedence and corruption context metadata.
This pull request improves sandbox workspace persistence internals by sharing the shell `tar --exclude` argument generation used by Blaxel, Daytona, and E2B sandbox sessions. It adds a small common helper under `src/agents/sandbox/session/` and keeps each provider's existing private `_tar_exclude_args()` surface as a thin delegate, preserving the generated command strings while removing duplicated quoting, sorting, and path-normalization logic. Direct unit coverage was added for empty/dot paths, stable sorting, shell quoting, dot-prefixed patterns, and absolute-path normalization.
This pull request improves the sandbox session implementation by moving archive extraction, manifest application, and snapshot lifecycle logic out of `BaseSandboxSession` into focused helper modules. The existing `BaseSandboxSession` method surface remains in place and delegates to the new helpers, preserving provider overrides and compatibility while reducing the size and responsibility concentration of the base session class.
Automated update of translated documentation. Triggered by commit: [4c5112c](openai@4c5112c). Message: `feat: add BoxMount support (openai#2988) ### Summary This pull request adds Box as an rclone-backed sandbox mount provider. - Adds `BoxMount` with Docker rclone volume-driver support and in-container `RcloneMountPattern` config generation. - Wires Box into the sandbox entry exports and provider docs. - Updates rclone-backed sandbox extension wording for Daytona, E2B, and Runloop. - Adds Docker and rclone mount config tests for Box auth/path options. ### Test plan - `bash .agents/skills/code-change-verification/scripts/run.sh` *(format and lint passed; typecheck failed on pre-existing local ignored `tests/local` symlink files and unrelated Temporal example dependency typing)* - `uv run pyright --project pyrightconfig.json src/agents/sandbox src/agents/extensions/sandbox tests/sandbox/test_mounts.py tests/sandbox/test_docker.py` - `uv run mypy src/agents/sandbox src/agents/extensions/sandbox tests/sandbox/test_mounts.py tests/sandbox/test_docker.py` - `uv run pytest -q tests/sandbox/test_mounts.py tests/sandbox/test_docker.py` ### Issue number N/A ### Checks - [x] I've added new tests (if relevant) - [x] I've added/updated the relevant documentation - [x] I've run `make lint` and `make format` - [x] I've made sure tests pass Co-authored-by: Carter Rabasa <carter.rabasa@gmail.com>` Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
### Release readiness review (v0.14.3 -> TARGET ba3b177) This is a release readiness report done by `$final-release-review` skill. ### Diff openai/openai-agents-python@v0.14.3...ba3b177 ### Release call: **🟢 GREEN LIGHT TO SHIP** Patch bump to `0.14.4` with additive sandbox capability and broad compatibility-focused test coverage; no concrete release-blocking issues found in the diff. ### Scope summary: - 34 files changed (+2236/-536); key areas touched: `src/agents/sandbox/session/` refactors/extractions, new `BoxMount` support in sandbox mount providers, provider integrations (`cloudflare`, `vercel`, `daytona`, `e2b`, `blaxel`), sandbox docs, and substantial sandbox compatibility/regression tests. - Commit range reviewed (oldest to newest): docs cleanup/translation updates, sandbox compatibility guards, snapshot default fix, Box mount feature, shared mount lifecycle refactor, shared tar exclude refactor, session helper extraction, version bump to `0.14.4`. ### Risk assessment (ordered by impact): No material risks identified. ### Notes: - Base tag determined from local tags only per instruction: `v0.14.3`. - Target resolved from current `HEAD`: `ba3b17740b280c00330d9cd61158f88a34d28d2a`. - Assessment is based on diff/log/code inspection and added tests in-range; no additional local test execution was performed in this CI review step. Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
adityasingh2400
added a commit
that referenced
this pull request
Apr 22, 2026
…, defensive _get_model_name Three small follow-ups from the CodeRabbit review of PR #4: * test_multi_agent_run_attributes_usage_to_correct_agents now sets a distinct model attribute on each FakeModel and asserts model_name on both the triage and specialist RequestUsage entries, so a regression that drops or cross-wires model_name during handoff aggregation will surface here too. * Adds test_serialize_deserialize_roundtrip_preserves_agent_and_model_names that builds a Usage with both a named and an unnamed RequestUsage entry, runs serialize_usage then deserialize_usage, and asserts both fields survive on the named entry while staying None on the unnamed one. This exercises both branches of the conditional emit in serialize_usage. * Hardens _get_model_name against custom Model implementations whose descriptors or properties raise on attribute access: the helper now swallows exceptions, falls back to model_name when model is missing, and rejects empty strings. This keeps usage accounting from ever crashing the run on a third-party Model.
…tool items (openai#3027) Co-authored-by: Daniel Cufiño <dancufino@gmail.com>
- Added optional `agent_name: str | None = None` and `model_name: str | None = None` fields to the `RequestUsage` dataclass (backward-compatible) - Modified `Usage.add()` to accept keyword-only `agent_name` and `model_name` parameters and annotate the resulting `RequestUsage` entry with them - Added `_get_model_name()` helper in run_loop.py to safely extract the model name string from any Model implementation via duck-typing - Updated both `run_single_turn_streamed` and `get_new_response` call-sites in run_loop.py to pass agent.name and the resolved model name when adding usage - When merging pre-existing `request_usage_entries`, agent/model names are applied to entries that don't already have them set (existing names preserved) - Updated `serialize_usage` / `deserialize_usage` in usage.py to round-trip the new fields through JSON - Added 9 new tests covering: default None values (backward compat), explicit field population, Usage.add() propagation, entry merge semantics, single-agent runner integration, model_name detection, and multi-agent per-agent attribution scenario - Full test suite passes (2198 tests); lint and pyright clean Closes openai#2100
The elif branch in Usage.add() was mutating agent_name/model_name directly on the RequestUsage objects inside other.request_usage_entries, bypassing the non-overwrite guard and causing silent mis-attribution when the same Usage instance was added to multiple aggregators. Fix: create a new RequestUsage copy for each entry with the annotation applied, leaving the originals unchanged. Adds a regression test that verifies the original entries are not mutated.
…, defensive _get_model_name Three small follow-ups from the CodeRabbit review of PR #4: * test_multi_agent_run_attributes_usage_to_correct_agents now sets a distinct model attribute on each FakeModel and asserts model_name on both the triage and specialist RequestUsage entries, so a regression that drops or cross-wires model_name during handoff aggregation will surface here too. * Adds test_serialize_deserialize_roundtrip_preserves_agent_and_model_names that builds a Usage with both a named and an unnamed RequestUsage entry, runs serialize_usage then deserialize_usage, and asserts both fields survive on the named entry while staying None on the unnamed one. This exercises both branches of the conditional emit in serialize_usage. * Hardens _get_model_name against custom Model implementations whose descriptors or properties raise on attribute access: the helper now swallows exceptions, falls back to model_name when model is missing, and rejects empty strings. This keeps usage accounting from ever crashing the run on a third-party Model.
5ac2475 to
fa0a85f
Compare
…add() When other.requests == 1 but other.request_usage_entries is already populated, merge those entries (with the same agent_name/model_name annotation rules as the multi-entry path) instead of creating a fresh RequestUsage that only used add() kwargs and dropped prior attribution. Adds regression test for Codex review on PR openai#2914.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds optional
agent_nameandmodel_namefields toRequestUsageso developers can attribute token usage and costs to specific agents and models in multi-agent workflows.Problem
In complex multi-agent systems,
result.context_wrapper.usage.request_usage_entriescontains oneRequestUsageper LLM call, but there is no way to know which agent or model generated each entry. This makes per-agent cost attribution impossible.Solution
agent_name: str | None = Noneandmodel_name: str | None = NonetoRequestUsage(backward-compatible — defaults toNone)Usage.add()to accept keyword-onlyagent_nameandmodel_nameparameters and annotate the resultingRequestUsageentry_get_model_name()helper that safely duck-types the model name from anyModelimplementation (e.g.OpenAIResponsesModel.model,OpenAIChatCompletionsModel.model)run_single_turn_streamedandget_new_responsecall-sites inrun_loop.pyto passagent.nameand resolved model namerequest_usage_entries, agent/model names are applied only to entries that don't already have them (existing names preserved)serialize_usage/deserialize_usageto round-trip the new fields through JSONRequestUsageor callingUsage.add()without these fields continues to workBefore / After
Usage Example
Files Changed
src/agents/usage.pyagent_name/model_namefields toRequestUsage; updatedUsage.add(),serialize_usage,deserialize_usagesrc/agents/run_internal/run_loop.py_get_model_name()helper; updated bothusage.add()call-sitestests/test_usage.pyTest Plan
RequestUsagefield population (explicit + default None)Usage.add()propagation and backward compat testsagent_nameis set.modelattributeRequestUsageentry has the correctagent_nameCloses openai#2100
Summary by CodeRabbit
New Features
Tests