How can AI tracing help identify and reduce wasted AI agent spend?
Summary
- AI tracing records each step of an agent run (model calls, tool calls, retrieval) with its inputs, outputs, latency and token usage, so you can see where spend goes inside a task, not just how much a task cost in total.
- Most wasted agent spend hides inside tasks that succeed: failed tool calls the agent retries, loops, context that grows turn after turn, and expensive models used for trivial steps. Aggregate dashboards show this only as usage growth.
- The working loop is trace, rank, fix, verify: query traces for the patterns that burn the most tokens, fix the tool, prompt or model choice behind them, and rerun the same query to confirm.
- On Databricks, MLflow Tracing captures application traces into Unity Catalog tables, and Unity Gateway's unified trace table (Beta) captures gateway and coding-agent traces in OpenTelemetry format.
How can AI tracing help identify and reduce wasted AI agent spend?
Tracing turns an agent's bill into an itemized receipt. A trace breaks each run into spans, one per model call, tool call or retrieval, and records the tokens, latency, inputs and outputs of each. That lets you attribute spend to the specific tool, error, prompt or model that caused it, instead of staring at a monthly total. Once waste has a name and a location, you can fix it and prove the fix worked by running the same query again.
What kinds of waste do traces reveal?
Agents rarely fail loudly. When something goes wrong, they retry, guess and work around it, and the task still completes. Databricks' engineers found exactly this when they traced their own agents' tool calls: from outside, the waste looked like ordinary usage growth. Traces expose it.
| Waste pattern | What it looks like in a trace | Typical fix |
|---|---|---|
| Failing tool calls | Repeated tool spans with errors, and many turns after the first failure | Make the tool accept natural input variations and return errors that say what to change |
| Repeated calls | The same tool call failing again in one session, which the blog measures as a repeat rate | Fix the tool or prompt that triggers the retry |
| Context bloat | Input tokens climbing turn over turn; large tool results | Compact context more often and cut tool verbosity |
| Oversized models | A high-capability model on simple steps | Route routine steps to a lower-cost model |
| Cache misses | Few cached reads against many cache writes in per-request token details | Tune prompt-caching settings for your workload |
| Slow steps | Long spans that leave developers waiting; the blog counts agent wait time as a cost | Find the cause of the delay and fix it |
The context row matters more than it looks. Databricks' write-up on managing AI coding costs notes that the user's request is a small fraction of what reaches the model; gathered context, tool output and instructions dominate the cost.
What should you look for in a tracing setup?
- Per-span token data. Cost questions need tokens on every step, not just per request.
- Tool arguments and results. You can't tell whether the tool or the model is at fault without them.
- Session grouping. Counting turns to recover from an error needs calls tied to a session.
- Queryable, governed storage. Traces in tables can be joined with billing and usage data, and access stays controlled.
- Open format. OpenTelemetry lets one table hold spans from your apps, your gateway and your agents.
How Databricks approaches agent tracing for cost
MLflow Tracing is the open-source tracing layer in MLflow. On Databricks it records the inputs, outputs, latency, token usage and cost of every intermediate step of an agent. One mlflow.<framework>.autolog() call instruments supported frameworks. Databricks recommends storing traces in Unity Catalog as Delta tables in OpenTelemetry format, where you can query them with SQL, build AI/BI dashboards and drive alerts.
Unity Gateway unified trace table (Beta). Unity Gateway is generally available; the unified trace table is in Beta and enabled through the Enhanced Unity Gateway preview. A metastore admin sets it up once, and it captures requests and responses across Unity Gateway model and MCP services in one Unity Catalog table. Model spans carry attributes such as gen_ai.usage.input_tokens and gen_ai.request.model, and tool spans carry gen_ai.tool.name and gen_ai.tool.call.arguments. With tracing turned on in the coding agent configuration (also Beta), Claude Code and Codex launched through ug send client-side traces to the same table.
Analysis. The docs list reducing token usage among its common uses: run AI functions over the trace table to find common error patterns in LLM and MCP calls. Genie Code can write the SQL from a plain-English question. Pair the traces with system.ai_gateway.usage, whose token_details field records cache reads and writes per request.
Keep it fixed. MLflow production monitoring (Beta) runs scorers on a sample of live traces, so a regression shows up as a quality signal, not just a cost spike.
FAQs
How is tracing different from usage tracking?
Usage tracking records metrics per request, such as tokens, latency and requester. Tracing records the structure of a run: which steps happened, in what order, with what inputs and outputs. You need both to see what was spent and why.
Do I have to change my agent code?
Little or none. MLflow autolog instruments supported frameworks with one call, and Unity Gateway's unified trace table logs gateway traffic with no per-endpoint setup once it's enabled.
Are traces sensitive?
Yes. Spans can include full request payloads and requester identity. By default only the metastore admin who creates the unified trace table can read it; Databricks recommends ABAC row filter policies before granting wider access.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.