Observability for production agent applications: How we integrated MLflow for IdeaBot

by , , , | Nov 24, 2026 | AI

Imagine trying to manage a team of specialists working on a project. You wouldn’t just look at the final report; you’d want to know who did what, what resources they used, and how much time each task took. A modern AI agentic application is like that team. It’s not a single, simple tool but a collection of specialized AI agents working together. To understand its functioning, you need a specialized system.

Note: Red Hat’s Emerging Technologies blog includes posts that discuss technologies that are under active development in upstream open source communities and at Red Hat. We believe in sharing early and often the things we’re working on, but we want to note that unless otherwise stated the technologies and how-tos shared here aren’t part of supported products, nor promised to be in the future.

Why we need agent observability

Unlike deterministic software or stateless completion endpoints, multi-agent systems make dynamic routing decisions, invoke external tools, recurse through discovery loops, and consume variable numbers of tokens per session. Without robust agent application monitoring, engineering teams face critical operational blind spots:

  • Cost invisibility: Which specific subagent or tool call is burning through token budgets?
  • Trajectory blindness: Why did an agent take a specific branch or tool path during reasoning?
  • Latency bottlenecks: Is slowness caused by model inference, external API tools, or context window overhead?

To address these challenges in IdeaBot—our internal collaborative AI assistant designed to turn raw prose into structured product requirements—we built an end-to-end monitoring architecture powered by MLflow Tracing.

Here’s how we architected observability for IdeaBot, solved token accounting across provider backends, and decoupled telemetry from core business logic.

Inside IdeaBot: A multi-agent system

To monitor an agent application effectively, you must first understand its topology. IdeaBot operates as an orchestrator coordinating five specialized sub-agents:

  • Orchestration agent: Manages discovery conversations, clarifies user intent, and determines when to delegate tasks
  • Research and retrieval subagents: Query external context via specialized tools such as Web Search (Tavily/DuckDuckGo), Jira, and ArXiv
  • Consolidation agent: Deduplicates gathered evidence into clean findings without merging distinct architectural concepts
  • Gate evaluation agent: Evaluates readiness gates (e.g., target audience identified, prior art reviewed, stakeholder alignment) to provide informational readiness scores.
  • Synthesis agent: Compiles curated findings into executive summaries and structured product specifications.

Because each user interaction triggers multiple subagent executions and external API calls, tracking a request requires looking beyond simple top-level HTTP metrics.

Architecture: Integrating MLflow for telemetry

Session grouping and trace metadata

A single user session in IdeaBot can span dozens of turns over several hours. Standard APM tools treat each turn as an isolated HTTP request. In MLflow, we tag every span with unified metadata:

  • session_id: Unique identifier spanning the whole ideation workflow
  • user_id: Enables per-user quota usage analysis
  • agent_name: Distinguishes orchestrator calls from subagent runs
  • model_provider: Tracks whether requests hit OpenAI, Vertex, or local vLLM/Ollama endpoints

This tagging allows us to query MLflow for the full trajectory of a session, inspecting exact inputs, outputs, and intermediate reasoning steps for every subagent.

The shape of an IdeaBot trace

Think of a trace as the complete story of a single user request from start to finish. Each step in that story—like a call to an AI model or a query to a database—is a span. A trace is the record of one prompt-response turn. A span is one operation inside that trace. In production, the exported MLflow trace begins at the inbound HTTP request, then narrows through the agent loop, AI client, provider SDK, and tool executions. That hierarchy is what makes a costly or slow request decomposable.

To understand what’s happening, we break down every action into distinct spans. Here’s what each key span represents in the IdeaBot workflow:

SpanWhat it representsWhat it answers
HTTP request rootThe inbound request, such as POST /api/sessions/:id/messagesWhich request started the work, how long it took, and whether it succeeded
agent.runOne complete agent loop, which may contain multiple model and tool roundsWhich agent and model ran, what the outcome was, and what the loop consumed in total
ai.sendMessageOne request from the IdeaBot AI client to the selected providerWhich model and provider handled the call, how many messages and tools were supplied, and why the call stopped
ai.streamText.doStreamThe provider-call leaf emitted by the Vercel AI SDKHow the model streamed, what latency it introduced, and which usage the provider actually reported
agent.executeToolOne tool invocation inside the agent loopWhich tool was called, what arguments were used, whether it failed, and how long it took
mcp.callToolOne external tool call through the MCP layerWhich external service was used and how that call contributed to the trajectory

The provider-call leaf is deliberately special. It is the only span that keeps the canonical MLflow chat token-usage record. Wrapper spans remain useful for context and diagnostics, but they must not turn one provider call into several counted calls.

Token accounting and cost tracking

Calculating accurate operational costs in agentic applications is surprisingly nuanced due to:

  • Differences between input tokens, output tokens, and cached tokens.
  • Model pricing variance across proprietary APIs and self-hosted instances.
  • Potential double-counting bugs in automated tracing wrappers.

IdeaBot separates diagnostic attributes from rollup data. OpenTelemetry wrapper spans keep their usage attributes for Jaeger and other OTel consumers. For MLflow, the canonical `mlflow.chat.tokenUsage` record is retained only on the provider-call leaf. The export copy also removes the generic input and output token attributes from wrapper spans so the MLflow ingestion server cannot reconstruct duplicate usage records from them.

That rule scales to multi-round agents. A run with four actual model calls should report four calls’ worth of usage. A run with four wrapper spans around one model call should report one. Each provider call is counted once; each additional agent round is added once. Tracking cost means tracking tokens accurately. We use specific attributes to measure every type of token consumed, from the initial prompt to what we pull from a cache as follows:

Attribute or recordWhat it measures
gen_ai.usage.input_tokensPrompt tokens consumed by the model call
gen_ai.usage.output_tokensCompletion tokens generated by the model
gen_ai.usage.cache_read.input_tokensInput tokens served from a prompt cache
gen_ai.usage.cache_creation.input_tokensInput tokens written to a prompt cache
gen_ai.usage.reasoning.output_tokensReasoning tokens reported by reasoning-capable models
agent.tokens.input and agent.tokens.outputToken totals rolled up to the agent run
agent.cost.usdCalculated cost for the agent run, derived from the model pricing table and rolled-up usage

Cost follows the same ownership rule. Model pricing lives in the LLM server registry entry, not in the agent loop. Each model can define input, output, cache-read, and cache-creation rates per million tokens. The agent runner aggregates provider-reported usage and writes agent.cost.usd to the agent.run span.

The calculation treats cached tokens as their own billing tiers. Cache-read and cache-creation tokens are subtracted from the uncached input count before their respective rates are applied. If a model has no configured pricing, the calculated cost is zero rather than an invented estimate. Provider invoices remain the source of truth for billing; agent.cost.usd is an operational attribution signal.

By decoupling cost metadata from agent execution scripts, MLflow dynamically calculates session costs based on token-usage metrics returned by the provider.

Prompt caching optimization

Agentic workflows frequently pass heavy system instructions and historical context in every sub-agent loop. By implementing prompt caching, we drastically reduced latency and cost.

Agentic systems often repeat a large system prompt on every turn. For supported Vertex AI Claude requests, IdeaBot marks the stable prompt prefix with a cache-control breakpoint. The provider can then reuse that prefix instead of re-reading and re-billing the entire block every time.

Cache telemetry appears in the same trace as ordinary token usage. A cold request may report cache-creation tokens. A later request with the same prefix may report cache-read tokens. The reported amount is the size of the cached prefix, not the entire conversation, so it can remain stable while later user messages grow. If the provider omits cache details, those fields are absent rather than filled with fabricated zeros.

IdeaBot uses a five-minute cache lifetime by default and supports a one-hour option. Prompt caching can be disabled for workloads where cache-write charges are not appropriate. The important part is that the optimization is visible: engineers can see whether a cache was written, whether it was read, and what those tokens cost.

Monitoring this in MLflow allowed us to verify cache hit rates in real-time, ensuring that repeated system prompts were reading from the context cache rather than triggering full token billing on providers like Anthropic and OpenAI.

Lessons learned and common pitfalls

  • Treat provider-reported usage as the source of truth. Wrapper spans are useful for diagnostics, but they should not create additional usage during aggregation.
  • Keep session correlation separate from trace lifetime. A per-turn trace is easier to inspect, and stable session and conversation identifiers still provide long-term grouping.
  • Keep pricing in configuration. The agent loop should consume a pricing table, not embed provider-specific rates.
  • Preserve cache semantics explicitly. Cache-read and cache-creation tokens are not the same as ordinary input tokens, and cost calculations must reflect that difference.
  • Make evaluation evidence replayable. Individual traces explain why a score changed, not merely that it changed.
  • Keep deployment and telemetry aligned. Observability infrastructure needs the same rollout reliability as the application it measures.

What’s next

Instrumenting IdeaBot with MLflow transformed our development process. Instead of guessing why an agent spent excess tokens or failed a research task, we now have complete visibility into every subagent’s decision tree, token consumption, and execution cost. 

MLflow does not replace IdeaBot’s distributed tracing, metrics, or logs. It adds a focused view of agent execution. After a request finishes, engineers can follow the trace from the HTTP route through the agent loop, see each model and tool call, compare turns in a conversation, and trust that token and cost totals represent actual provider calls.

The goal is not more telemetry; it is explainability. Users need to understand which agent made a decision, which model produced a response, which tool was called, which tokens were consumed, and what that work cost. As we move forward with open-weight model transitions, our MLflow baseline serves as the ground truth. It enables us to quantitatively compare self-hosted models (like Qwen and Llama) against frontier models in terms of both reasoning quality and cost efficiency.

Are you building or monitoring agentic applications in production? Feel free to reach out to us on Slack on our #forum-ace team channel or check out our GitHub repository: https://github.com/redhat-et/hermes