{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-of-gen-ai-usage-input-tokens-be-attributed-when-an-agent-span-fans-out-to-multiple-tool-calls",
  "title": "Where must an instance of gen_ai.usage.input_tokens be attributed when an agent span fans out to multiple tool calls",
  "date_of_record": "2026 November 16",
  "scope": "Applies to OpenTelemetry instrumentation of LLM agent spans (`gen_ai.operation.name = \"invoke_agent\"` or `\"chat\"`) that emit child `execute_tool` spans and per-turn model calls. Does not apply to single-shot inference spans with no tool fan-out, nor to embeddings/reranking operations where token accounting is per-request only.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-of-gen-ai-usage-input-tokens-be-attributed-when-an-agent-span-fans-out-to-multiple-tool-calls.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-of-gen-ai-usage-input-tokens-be-attributed-when-an-agent-span-fans-out-to-multiple-tool-calls.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-of-gen-ai-usage-input-tokens-be-attributed-when-an-agent-span-fans-out-to-multiple-tool-calls.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1228,
    "python_slice_tokens": 344,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of the *model inference* span. When an agent span encloses multiple model calls (a reasoning loop), there are two structurally different quantities that both look like \"input tokens\": 1. **Cumulative billed tokens** — the sum across every underlyi...",
    "what_was_observed": "Instrumenting a tool-using agent with a vendored OTel SDK, the parent `invoke_agent` span carried `gen_ai.usage.input_tokens` set to the sum of all child `chat` spans. A cost dashboard that aggregated \"tokens per trace\" by summing all spans carrying the attribute produced a 3.7x overcount versus the provider invoice. The overcount matched exactly `sum(turns) / 1` — the parent's total plus the sum of children's totals...",
    "condition_of_validity": "The invariant holds only when the following are simultaneously true: - The parent agent span is a *container* (its duration encloses ≥1 child model call). - Children emit their own `gen_ai.usage.*` attributes. - Any consumer aggregates token attributes by summing across spans in a trace without deduplication. If the parent span intentionally carries a rollup...",
    "decision_boundary": "The correct placement is: **token usage belongs to the span that represents the actual model inference request, never to a container span and never to a tool span.** For agent fan-out: - Each `chat` / `text_completion` child span carries its own `gen_ai.usage.input_tokens` / `output_tokens`. - The `invoke_agent` parent carries *no* `gen_ai.usage.*` attribute...",
    "operational_effect": "Enforcing single-owner attribution reduced the dashboard's reported token count to within 2% of the provider invoice and eliminated a class of sampling bugs where tool-heavy traces were over-retained because every span looked like an inference event. The cost of the fix is that consumers wanting per-agent totals must now sum children explicitly rather than r..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "84f47ed34fbf2ce6cfd9a08a65f5c55eeb1609db199b08d2a07789e6459c5620",
    "verified_classes": [
      "TokenAttributionError",
      "Span"
    ],
    "verified_functions": [
      "validate_attribution",
      "trace_total_tokens",
      "walk",
      "has_usage"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAttributionError"
    ],
    "sample_fail_closed_invariants": [
      "assert trace_total_tokens(good) == 2400"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
