In what scenarios must an instance refuse to attribute tool-call latency to the tool, and instead book it against its own reasoning budget?
**Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that emits per-span latency and cost telemetry for multi-turn loops where LLM inference and tool execution are interleaved and instrumented by a shared tracer. Does not apply to single-shot RAG calls or to batch inference jobs with no tool loop.
Core Distinction
The failure mode is a **misattribution of wall-clock latency across the reasoning/tool seam**. In a traced agent loop, each turn produces at least two span types: an *inference span* (the model call, ending when the final token is emitted or the tool-call block is parsed) and a *tool span* (the external call, from dispatch to response). Naive tracers measure the tool span as `t_response − t_dispatch` and book the remainder of the turn as inference. This is correct only when the model's tool-call emission and the runtime's dispatch are the *same event*.
They are not. The model emits a tool-call token sequence; the runtime must (a) finish streaming the generation, (b) parse and validate the call against the tool schema, (c) serialize arguments, (d) apply policy/guardrail checks, and (e) only then dispatch. Steps (a)–(d) are **model-originated work that the runtime performs on the model's behalf**. When the model emits a large or malformed argument payload, or when the runtime's schema-validation is non-trivial, this pre-dispatch segment grows. Attributing it to the tool inflates tool p50/p99 latency, triggers false tool-degradation alerts, and — critically — corrupts per-turn cost accounting because the pre-dispatch segment is billed against *inference tokens* while being *reported as tool time*.
The invariant that must hold: **every millisecond between the inference-span start and the tool-span start belongs to the reasoning budget, not the tool budget.** A tracer that cannot prove this partition must refuse to attribute.
What Was Observed
A tool-loop agent (`search_documents` + `summarize`) showed a bimodal tool-latency distribution: a stable ~180ms mode and a fat ~2.4s mode. The 2.4s mode correlated with turns where the model requested the tool with a *large structured argument* (a 40–60 field filter object). Investigation of the trace:
- The inference span closed on `finish_reason == tool_calls`, timestamped at the last token.
- The tool span opened at `dispatch()`, timestamped *after* the runtime's `validate_against_schema()` and `apply_guardrails()`.
- Between the two timestamps sat ~2.1s of runtime work: JSON re-parse, schema validation, and a guardrail policy that inspected every argument field.
The external tool's actual server-side time was ~200ms in both modes. The 2.4s mode was **entirely runtime-side pre-dispatch work billed to the tool**. Downstream, the cost ledger double-counted: the argument tokens were charged as inference *and* the wall-clock was charged as tool latency, so the turn's "total cost" exceeded the sum of its parts — a conservation violation that broke the per-customer budget alarm.
A second, subtler trace showed the inverse: a tool that streamed its response slowly but whose *first byte* arrived fast. The tracer closed the tool span on last byte, so a slow-streaming tool with prompt first-byte looked slow, when the model was actually blocked on *its own* re-inference between tool chunks. The seam is bidirectional.
Condition of Validity
Tool-latency attribution is valid **iff** the tracer can emit a `dispatch_ready` timestamp that is causally downstream of the model's final tool-call token and upstream of any runtime-side argument processing, *and* the tool span opens at `dispatch_ready` rather than at `dispatch()`. Concretely, three conditions must all hold:
- The inference span's close timestamp is taken at the *last emitted token*, not at stream-close or at tool-response-arrival.
- A distinct `pre_dispatch` span brackets parse → validate → guardrail, and is parented under the *inference* span, not the tool span.
- The tool span's duration is measured from the transport's first write to the tool, not from the runtime's call site.
If any condition fails, the tracer must mark the turn `attribution: unverified` and route the whole inter-span gap to the reasoning budget. It must not silently default to tool attribution.
Decision Boundary
The boundary is **whether the pre-dispatch segment is model-shaped or tool-shaped**. Model-shaped work — token parsing, schema conformance of model-emitted arguments, guardrail evaluation of model-emitted content — scales with model output and belongs to the reasoning budget even though it executes in runtime code. Tool-shaped work — connection setup, retry backoff, transport — belongs to the tool. The tracer cannot infer this from timing alone; it must be told by span structure.
When the pre-dispatch segment exceeds a configurable fraction (observed threshold: >15%) of the turn's total latency, the turn crosses from "attribution noise" into "attribution error" and the runtime must escalate to `unverified` rather than emit a tool-latency sample. This is the guardrail: **do not emit a tool-latency observation you cannot causally bound.** A missing sample is recoverable; a misattributed sample poisons the p99 for every downstream consumer.
Operational Effect
Enforcing the invariant changed the tool p99 from 2.4s to 210ms and moved ~2.1s per affected turn into the reasoning budget, which is where it belongs — the model's argument verbosity is a *reasoning* cost, and the fix is prompt/schema tightening, not tool replacement. The cost ledger now reconciles: inference tokens + tool wall-clock + pre-dispatch runtime = turn total, to within measurement resolution. The conservation check (`sum(parts) ≈ total`) became the primary integrity assertion on the ledger, and any turn violating it is quarantined for attribution review rather than billed.
from dataclasses import dataclass
class AttributionConservationError(RuntimeError):
"""Raised when a turn's parts do not reconcile to its total, or when a
tool-latency sample cannot be causally bounded to the tool span."""
@dataclass
class TurnTrace:
inference_ms: float
pre_dispatch_ms: float # parse + validate + guardrail on model-emitted args
tool_ms: float # transport first-write -> last-byte
total_ms: float
pre_dispatch_fraction_threshold: float = 0.15
resolution_ms: float = 5.0
def reconcile_turn(trace: TurnTrace) -> str:
parts = trace.inference_ms + trace.pre_dispatch_ms + trace.tool_ms
if abs(parts - trace.total_ms) > trace.resolution_ms:
raise AttributionConservationError(
f"conservation violation: parts={parts:.1f}ms total={trace.total_ms:.1f}ms "
f"delta={parts - trace.total_ms:.1f}ms"
)
if trace.total_ms <= 0:
raise AttributionConservationError("zero-duration turn cannot be attributed")
frac = trace.pre_dispatch_ms / trace.total_ms
if frac > trace.pre_dispatch_fraction_threshold:
# Pre-dispatch work is model-shaped; do not emit a tool-latency sample.
return "unverified"
return "tool_attributed"
def emit_tool_sample(trace: TurnTrace) -> float:
verdict = reconcile_turn(trace)
if verdict != "tool_attributed":
raise AttributionConservationError(
"refusing to emit tool-latency sample: pre-dispatch fraction "
f"{trace.pre_dispatch_ms / trace.total_ms:.2%} exceeds bound; "
"route gap to reasoning budget instead"
)
return trace.tool_ms