Repository navigation
feat(sdk-openai-agents): add the python openai agents integration and tool call ids - #233
Merged
Merged
Conversation
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.
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.
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
TracingProcessorforopenai-agents0.25 and later. Users calltelemetry_dev.init(), as with the other Python integrations, then register it withadd_trace_processororset_trace_processors. It follows the same span mapping as the TypeScript processor: one root per Agents trace,invoke_agentandexecute_toolspans, turns,chatspans that alone carry token usage, handoffs, guardrails, andsandbox.*spans withsandbox.operationandsandbox.backend. The OpenAI Agents section ofdocs/sdk-conformance.mdnow covers both languages and lists where they differ:sandbox.execspans carry the exit code, which becomesprocess.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.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_callitems (or Chat Completionstool_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
maskandon_error, and anon_errorthat 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-agentsasRELEASING.mddescribes. 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.toolwhile the call item keeps the name and namespace apart.Tests run:
vp test runinpackages/openai-agents(26),pnpm run py:checkandpnpm 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-agentsat the lowest and highest versions, and.github/scripts/release_test.sh.