Skip to content

feat(sdk-openai-agents): add the python openai agents integration and tool call ids - #233

Merged
aikins01 merged 2 commits into
mainfrom
feat/openai-agents-tool-call-id
Nov 21, 2026
Merged

aikins01 merged 2 commits into
mainfrom
feat/openai-agents-tool-call-id

Conversation

@aikins01

Copy link
Copy Markdown
Contributor

Adds telemetry-dev-openai-agents, the Python twin of @telemetry-dev/openai-agents, and gives tool spans in both packages their call id.

The Python package is a TracingProcessor for openai-agents 0.25 and later. Users call telemetry_dev.init(), as with the other Python integrations, then register it with add_trace_processor or set_trace_processors. It follows the same span mapping as the TypeScript processor: one root per Agents trace, invoke_agent and execute_tool spans, turns, chat spans that alone carry token usage, handoffs, guardrails, and sandbox.* spans with sandbox.operation and sandbox.backend. The OpenAI Agents section of docs/sdk-conformance.md now covers both languages and lists where they differ:

  • The Python Agents SDK ends the trace even when a run raises, so only TypeScript needs the rule that a failed top-level task or agent span ends the root.
  • Python sandbox.exec spans carry the exit code, which becomes process.exit.code. The Agents SDK marks a non-zero exit as an error, and the processor clears that error, matching the rule for the shell tool spans.
  • Python records the backend on every sandbox session operation, while TypeScript records it only on create and resume.

Neither Agents SDK puts a call id on its tool spans. Both processors now take it from the model call that asked for the tool: when a model call ends, its function_call items (or Chat Completions tool_calls, or the response a streamed Chat Completions call builds) are held under its parent span, and each tool span under that parent claims the call with the same name and arguments, falling back to the same name. Parallel calls of one tool get the right ids even when they finish out of order. This needs the model output, which the Agents SDK records only with sensitive data on, its default.

The Python processor guards its state with a reentrant lock. Starting or ending a span can run the core SDK's mask and on_error, and an on_error that starts an Agents span on the same thread deadlocked a plain lock.

Before the first Python release, PyPI needs a trusted publisher for telemetry-dev-openai-agents as RELEASING.md describes. Otherwise the release's publish step fails. Release Please gives the package 0.1.0 on its first release.

Known gaps: in Python, a tool in a namespace gets no call id, because its span is named ns.tool while the call item keeps the name and namespace apart.

Tests run: vp test run in packages/openai-agents (26), pnpm run py:check and pnpm run py:test (all Python packages, 14 new tests running real agents against a faked OpenAI HTTP API), .github/scripts/python_dependency_bounds.sh sdks/python-openai-agents at the lowest and highest versions, and .github/scripts/release_test.sh.

The Agents SDK puts no call id on its tool spans. Each tool span now
takes gen_ai.tool.call.id from the call of the same name and arguments,
else the same name, in the output of the model call under the same turn.
Matching on arguments keeps parallel calls of one tool apart when they
finish out of order.

The conformance doc gets the span mapping of the Agents SDK, which a
Python integration will follow.
Adds telemetry-dev-openai-agents, a tracing processor for the Python
OpenAI Agents SDK (openai-agents 0.25 and later), registered with
add_trace_processor or set_trace_processors after telemetry_dev.init().
It follows the same span mapping as @telemetry-dev/openai-agents:
invoke_agent and execute_tool spans, turns, chat spans that alone carry
token usage, handoffs, guardrails, and sandbox.* spans with
sandbox.operation and sandbox.backend.

Tool spans get the call id of the matching function call in the model's
output, from Responses, Chat Completions, and streamed Chat Completions
calls. Shell tool spans and sandbox.exec spans get process.exit.code,
and a non-zero exit is not an error. Roots end with their trace, or at
force_flush and shutdown once the trace has no open span, and are kept
for the 10,000 most recently active traces.

The conformance doc's OpenAI Agents section now covers both languages
and where they differ.
@aikins01 aikins01 self-assigned this Nov 21, 2026
@aikins01
aikins01 merged commit 47397f9 into main Nov 21, 2026
11 checks passed
@aikins01
aikins01 deleted the feat/openai-agents-tool-call-id branch November 21, 2026 21:36
@aikins01 aikins01 mentioned this pull request Nov 21, 2026
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.

1 participant