Skip to content

feat: #2886 add convenience properties (tool_name, call_id) to tool items#3027

Merged
seratch merged 1 commit intoopenai:mainfrom
jawwad-ali:feat/2886-tool-call-convenience-properties
Apr 26, 2026
Merged

feat: #2886 add convenience properties (tool_name, call_id) to tool items#3027
seratch merged 1 commit intoopenai:mainfrom
jawwad-ali:feat/2886-tool-call-convenience-properties

Conversation

@jawwad-ali
Copy link
Copy Markdown
Contributor

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`:

  • `ToolCallItem.tool_name` — pulls `.name` (or `["name"]`) off the raw item, `None` for hosted tools that don't carry a name.
  • `ToolCallItem.call_id` — pulls `.call_id` (or `["call_id"]`), falling back to `.id`.
  • `ToolCallOutputItem.call_id` — same fallback chain on the output item.

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:

  • `tool_name` from a typed `ResponseFunctionToolCall`, from a dict raw item, and the `None` case for hosted-tool raw items (`ResponseFileSearchToolCall`).
  • `call_id` from a typed raw item, the `call_id` → `id` fallback path, and the dict path.
  • `ToolCallOutputItem.call_id` from a `function_call_output` dict and the `None` case when neither key is present.

Verified locally:

  • `uv run ruff format` — pass
  • `uv run ruff check` — pass
  • `uv run mypy src/agents/items.py tests/test_items_helpers.py` — pass
  • `uv run pyright --project pyrightconfig.json src/agents/items.py tests/test_items_helpers.py` — pass
  • `uv run pytest tests/test_items_helpers.py` — 34 passed (26 existing + 8 new)
  • Broader sweep of `-k "tool_call or items_helpers or run_step or tool_approval"` — 217 passed; 2 unrelated tracing tests (`test_tracing_errors[_streamed].py::test_tool_call_error`) fail on clean `main` too, so they aren't caused by this change.

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

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation (auto-generated `docs/ref/items.md` picks up the new docstrings via `mkdocstrings`)
  • I've run `make lint` and `make format`
  • I've made sure tests pass

…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
@github-actions github-actions Bot added enhancement New feature or request feature:core labels Apr 25, 2026
@seratch seratch changed the title feat: add convenience properties (tool_name, call_id) to ToolCallItem and ToolCallOutputItem feat: #2886 add convenience properties (tool_name, call_id) to tool items Apr 26, 2026
@seratch seratch added this to the 0.14.x milestone Apr 26, 2026
@seratch seratch merged commit 5df41d3 into openai:main Apr 26, 2026
10 checks passed
@DanielCufino
Copy link
Copy Markdown
Contributor

Thanks @jawwad-ali for picking this up and adding the test coverage and @seratch for the co-author credit

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

Labels

enhancement New feature or request feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add convenience properties (tool_name, call_id) to ToolCallItem and ToolCallOutputItem

4 participants