Red Hat traces IdeaBot’s agent workflows without counting model tokens twice
The internal assistant keeps canonical usage on provider-call spans, while retaining wrapper spans for diagnostics and grouping turns by session.
Red Hat’s Emerging Technologies team described on Nov. 24 how it instrumented IdeaBot, an internal assistant that turns rough ideas into structured product requirements. The key design decision was not where to display token totals, but where to record them: only the span for the actual model-provider call contributes canonical token usage to MLflow.
One provider call, one usage record
A trace starts at the inbound HTTP request and follows a prompt-response turn through the agent loop, the AI client, and individual model and tool calls. Those nested spans help explain whether a turn was slow because of model streaming or a tool invocation. But several wrappers can describe the same model call. If every wrapper contributes its token numbers to a rollup, one call can appear to consume several calls’ worth of tokens.
IdeaBot keeps the canonical mlflow.chat.tokenUsage record on the provider-call span. Its MLflow export also strips generic input and output token attributes from wrapper spans so the ingestion server cannot reconstruct duplicate usage records. The wrappers retain those attributes for Jaeger and other OpenTelemetry consumers. A turn with four real model calls still counts all four; four wrappers around one call do not multiply the total.
Keep a session separate from its traces
IdeaBot uses one trace per turn and tags spans with a stable session identifier so engineers can follow a conversation across turns. Provider and agent labels let them see where a call ran and which part of the workflow made it. Pricing lives in configuration rather than the agent loop, with separate rates for input, output, cache reads, and cache creation. Red Hat treats the resulting cost as an operational estimate, not a substitute for the provider invoice. Missing cache fields stay missing rather than being recorded as zero.
What to test in your own stack
Run a turn with one provider call wrapped by several spans, then another with multiple genuine provider calls. Compare each exported total against the provider-reported usage. If your provider reports prompt caching, check cold and warm requests separately so cache writes and reads do not disappear into the ordinary input count. The Red Hat write-up documents an internal implementation, not a supported product feature or a benchmark of MLflow against other tracing systems.
sources
comments · 0