feat: #2886 add convenience properties (tool_name, call_id) to tool items#3027
Merged
seratch merged 1 commit intoopenai:mainfrom Apr 26, 2026
Merged
Conversation
…llOutputItem `ToolApprovalItem` exposes ergonomic `tool_name` and `call_id` accessors so callers can inspect tool calls without poking at `raw_item` internals. `ToolCallItem` and `ToolCallOutputItem` lacked the same convenience, forcing `getattr(item.raw_item, "name", None)` chains and `isinstance` switches just to do basic things like "give me all outputs from tool X". This adds: - `ToolCallItem.tool_name` and `ToolCallItem.call_id` - `ToolCallOutputItem.call_id` All three follow the same pattern as the existing `ToolApprovalItem._extract_call_id`. Purely additive — no public-API or positional-compatibility impact. Closes openai#2886
4 tasks
seratch
approved these changes
Apr 26, 2026
Contributor
|
Thanks @jawwad-ali for picking this up and adding the test coverage and @seratch for the co-author credit |
Closed
4 tasks
Merged
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
`ToolApprovalItem` exposes ergonomic `tool_name` / `call_id` accessors for inspecting tool calls without poking at `raw_item` internals. `ToolCallItem` and `ToolCallOutputItem` lacked the same convenience, forcing callers to write `getattr(item.raw_item, "name", None)` chains and `isinstance` switches just to do basic things like "get all outputs for tool X".
This PR adds three new properties on `src/agents/items.py`, all following the same pattern as the existing `ToolApprovalItem._extract_call_id`:
All changes are additive and backward-compatible. `ToolCallOutputItem.tool_name` is intentionally left out — its raw `FunctionCallOutput` doesn't carry the tool name, and threading it through at construction time would touch the runner, which the issue itself flags as a separate concern.
Test plan
Added 8 unit tests in `tests/test_items_helpers.py` covering:
Verified locally:
Issue number
Closes #2886
Note
PR #2887 by @DanielCufino opened the same day with the same surface, but it has been a stale draft for ten days, has merge conflicts against `main`, and ships zero tests. This PR is rebased on current `main` and adds the missing test coverage. Happy to defer to the original if maintainers prefer.
Checks