Mickiesoft
AI

Agentic AI in Production: Observability, Reliability, and Cost Control

Jun 7, 2026
8 min read
Agentic AI in Production: Observability, Reliability, and Cost Control

Introduction

Shipping an AI agent to production is not like deploying a deterministic microservice. Agents make chains of LLM calls, invoke external tools, accumulate state over time, and can produce wildly different outputs for identical inputs. Standard APM dashboards were not built for this.

This article covers what reliable agentic AI looks like in practice: the observability stack you need, the failure modes you will encounter, cost guardrails that prevent runaway spend, and the runbook patterns that let on-call engineers respond when things go wrong.

Agentic Failure Modes

Before instrumentation, understand what can fail. Agentic systems have failure modes that don't exist in request/response APIs:

  • Infinite loops: An agent that cannot make progress keeps calling itself or cycling between nodes, burning tokens until a budget cap or timeout fires.
  • Hallucinated tool calls: The model generates a tool name or parameter that doesn't exist, causing exceptions that the agent then tries to "fix" in ways that make things worse.
  • Context poisoning: An earlier tool call returns malformed or adversarial content that skews subsequent model behavior for the rest of the session.
  • Latency tail explosion: Most runs complete in 3 seconds; 1% of runs hit a reasoning loop that takes 2 minutes. p99 latency is meaningless without loop detection.
  • Cost spikes: A single misbehaving agent run can consume more tokens than a thousand normal runs. Without spend guardrails, a production incident can become a billing incident simultaneously.

The Observability Stack

Trace Every LLM Call

Use LangSmith, Langfuse, or OpenTelemetry with a custom span schema to capture each LLM invocation: model, input token count, output token count, latency, finish reason, and the full prompt/response for debugging. Never log in production without truncation and PII scrubbing.

import { trace, SpanStatusCode } from "@opentelemetry/api"

const tracer = trace.getTracer("ai-agent")

async function callLLM(messages: Message[]) {
  return tracer.startActiveSpan("llm.invoke", async (span) => {
    try {
      span.setAttributes({
        "llm.model": "claude-sonnet-4-6",
        "llm.input_tokens": countTokens(messages),
      })
      const response = await anthropic.messages.create({ model: "claude-sonnet-4-6", messages })
      span.setAttributes({ "llm.output_tokens": response.usage.output_tokens })
      return response
    } catch (err) {
      span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) })
      throw err
    } finally {
      span.end()
    }
  })
}

Key Metrics to Track

  • agent.run.duration_ms — histogram, alert at p99 > 30s
  • agent.run.step_count — histogram, alert if median exceeds expected; high step counts indicate loops
  • agent.llm.tokens_per_run — histogram, alert at p95 to catch runaway sessions before they hit budget
  • agent.tool.error_rate — counter by tool name; spikes indicate upstream breakage or model hallucination
  • agent.run.success_rate — the headline reliability metric; track by agent type and user segment

Structured Logging

Every agent step should emit a structured JSON log line with: run ID, step number, node name, tool called (if any), token counts, latency, and outcome. Attach the run ID to all downstream service calls so you can reconstruct the full agent trace from any service log.

Cost Guardrails

Token costs compound across agent steps. A 10-step agent run that averages 2,000 tokens per step costs 10× a single call at the same input size. Implement hard limits at multiple layers:

  • Per-run budget: Reject any run that exceeds a max token limit. Return a graceful error rather than letting the agent continue.
  • Per-user daily cap: Rate-limit token spend per user ID with a sliding window counter in Redis.
  • Model routing: Route classification and routing steps to cheaper models (Haiku). Only invoke expensive frontier models for deep reasoning nodes.
  • Prompt caching: Use Anthropic's prompt caching for long system prompts that are shared across many runs. Cache hits are billed at 10% of normal input token cost.
const MAX_TOKENS_PER_RUN = 100_000

function checkBudget(state: AgentState): string {
  if (state.totalTokensUsed > MAX_TOKENS_PER_RUN) {
    return "budget_exceeded"  // route to terminal error node
  }
  return "continue"
}

Reliability Patterns

Timeouts at Every Layer

Set explicit timeouts on LLM API calls (network timeout), on individual agent steps (step timeout), and on the full run (run timeout). The run timeout is your last line of defense against infinite loops.

Retry with Exponential Backoff

Transient API errors (rate limits, 529s) are normal. Retry with jitter and exponential backoff up to 3 attempts. Do not retry on agent logic failures — a hallucinated tool call will fail the same way on retry and waste tokens.

Circuit Breakers for Tool Dependencies

If a downstream tool (database, external API) fails repeatedly, open a circuit breaker and return the agent to a graceful degraded state. An agent that can acknowledge missing tool availability is more reliable than one that loops indefinitely trying to use a broken tool.

On-Call Runbooks

Before launch, write runbooks for the failure modes you identified. At minimum:

  • High latency: Check step count metrics first. If steps are high, look for a routing loop. Check tool error rates for the failed-tool loop pattern.
  • Cost spike: Identify the top-spending run IDs from your token metrics. Pull their traces. Look for the step where the token count jumped and determine if it was a legitimate workload or a hallucination loop.
  • Low success rate: Segment by agent type and tool. A single broken tool often drives a disproportionate failure rate.

Conclusion

Production agentic AI is an operational discipline, not just an engineering one. Trace every LLM call, set hard cost limits before launch, and write runbooks before you're paged at 2am. The teams that invest in this infrastructure ship agents that run reliably and stay within budget — the ones that don't spend most of their time firefighting.

Launching AI agents in production?

Mickiesoft helps teams design observable, reliable, and cost-efficient agentic AI systems ready for enterprise workloads.

Talk to Our Engineers

Frequently Asked Questions

Find answers to common questions about our services, process, and capabilities.

Tags:AIAI agentsObservabilityReliabilityProductionLLM2026 Trends