Add gen_ai.agent.turn.count to invoke_agent spans - #451
Open
Zhuoxi2000 wants to merge 2 commits into
Open
Zhuoxi2000 wants to merge 2 commits into
Zhuoxi2000 wants to merge 2 commits into
Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-09-21 17:47 UTC Resolve merge conflicts. Respond to 2 review items (e.g. link a commit, explain why not, ask a follow-up): Status above doesn't look right?
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the GenAI semantic conventions by introducing a new agent-level attribute, gen_ai.agent.turn.count, intended to summarize how many agent-loop turns (model inference + any requested tool executions) occurred during an invoke_agent span, and updates the OpenAI Agents reference scenario plus generated artifacts accordingly.
Changes:
- Add
gen_ai.agent.turn.countto the attribute registry and to the sharedinvoke_agentattribute group with a conditional recommendation. - Emit the new attribute in the
openai-agentsreference scenario and update its scenariodata.json. - Regenerate derived docs and reference reports, and add a Towncrier fragment.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| reference/scenarios/openai-agents/scenario.py | Emits gen_ai.agent.turn.count on the invoke_agent span based on run-loop inference count. |
| reference/scenarios/openai-agents/data.json | Declares the new attribute as expected for the gen_ai.invoke_agent.internal signal in this scenario. |
| reference/reports/invoke-agent-internal-span.md | Generated report now lists openai-agents as supporting gen_ai.agent.turn.count. |
| reference/reports/invoke-agent-client-span.md | Generated report shows no client-span library support yet for gen_ai.agent.turn.count. |
| model/gen-ai/spans.yaml | Adds gen_ai.agent.turn.count to the invoke_agent common attribute group as conditionally recommended. |
| model/gen-ai/registry.yaml | Registers the new gen_ai.agent.turn.count attribute definition and guidance. |
| docs/registry/attributes/gen-ai.md | Generated registry page update reflecting the new attribute. |
| docs/gen-ai/gen-ai-agent-spans.md | Generated agent-span documentation updated to include the new attribute. |
| changelog.d/+.enhancement.md | Adds a Towncrier fragment entry for the consumer-visible convention change. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -0,0 +1 @@ | |||
| Add `gen_ai.agent.turn.count` to the `invoke_agent` spans, recording the number of agent turns completed during the invocation. | |||
Comment on lines
+122
to
+124
| - ref: gen_ai.agent.turn.count | ||
| requirement_level: | ||
| recommended: If the agent loop is observable to the instrumentation. |
Zhuoxi2000
force-pushed
the
genai-agent-turn-count
branch
from
August 20, 2026 20:04
c892243 to
90a15b0
Compare
This comment has been minimized.
This comment has been minimized.
This branch has not been deployed
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.
Description
Part of #332 — this PR takes the
gen_ai.agent.turn.countpiece agreed there. The per-turnindexon child spans remains tracked separately in the issue.gen_ai.agent.turn.count(int, development) to the attribute registry: the number of agent turns completed during an invocation, where one turn is one agent-loop cycle consisting of a model inference and any tool executions it requests.invoke_agentattribute group for client and internal spans,Recommendedwhen the agent loop is observable to instrumentation.make generate-alland add the Towncrier fragment.Motivation
The main use cases are incident triage and cost/latency analysis. Having the turn count directly on the
invoke_agentspan lets a backend answer questions like “did this invocation loop more than expected?” or “what does a turn cost on average?” without reconstructing the loop from child spans, whose topology can vary across frameworks.I ran into this while building TraceLake, an OTLP GenAI ingestion pipeline into Iceberg, where turn count is a useful aggregation key for per-turn latency/cost rollups and detecting runaway loops.
There is also precedent across agent runtimes: OpenAI Agents SDK exposes individual inference responses and
max_turns, Claude Agent SDK reportsnum_turns, and LangGraph bounds loops withrecursion_limit. Observability tools such as LangSmith and Langfuse similarly expose per-run step counts.Prototype
The
openai-agentsreference scenario now records the attribute on theinvoke_agentspan usingRunResult.raw_responses, which contains one entry per model inference performed by the runner.I re-ran the scenario against the mock server; the Weaver live check reports no violations, and
data.jsonplus the coverage reports are regenerated in this PR.Checklist
changelog.d/for any change to the conventions that a consumer would care about. Editorial changes (typos, pure rewording, repo tooling) don't need an entry.See [CONTRIBUTING.md]