-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(llmobs): span linking for oai agents sdk #13072
Conversation
|
Bootstrap import analysisComparison of import times between this PR and base. SummaryThe average import time from this PR is: 228 ± 2 ms. The average import time from base is: 232 ± 4 ms. The import time difference between this PR and base is: -3.9 ± 0.1 ms. Import time breakdownThe following import paths have shrunk:
|
BenchmarksBenchmark execution time: 2025-04-04 15:29:53 Comparing candidate commit 210c362 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 498 metrics, 2 unstable metrics. |
…nto evan.li/span-linking-agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
general logic lgtm, and the examples you provided look really nice! just a couple small style things nits and one question, will approve after it's answered!
…race-py into evan.li/span-linking-agents
Add span linking between tool & llm spans for the openai agents sdk.
We use the core dispatch api since span linking requires cross-integration communication in the case where someone selects "chat completions" as the llm api to use for the agents sdk.
Signals are dispatched
ToolCallTracker
inddtrace.llmobs._utils
contains the functions that handles these signals to add span links.Links created
[LLM output -> tool input] for the case where an LLM span chooses a tool and that tool is later executed via the agents sdk. We do this by mapping the tool name & arguments to it's tool id. When the tool call is triggered, we have access to it's name and arguments. From there, we can look up it's tool id and the LLM span that is used to generate that argument. We pop the tool name/arg from the lookup dictionary after it's used.
[Tool output -> LLM input] for the case where a tool's output is fed back into a later LLM call, either in the same agent or another agent. We can tell this since the tool_id is present in the LLM's input messages. We then use this tool id to lookup the tool span.
So the general lifecycle is:
A note on handoffs
Hand-offs are implemented as tool calls in the agents SDK, so the span linking logic is largely the same. Two notes
handoff_tool_name = "transfer_to_{}".format("_".join(oai_span.to_agent.split(" ")).lower())
{}
as the placeholder for the hand-off tool call argument. This is what's generated by the LLM when it chooses a handoff.We can improve on this by inferring these values when an LLM chooses a handoff tool, but this requires a bit more exploring
Checklist
Reviewer Checklist