Tag: Reliability

  • Routing Traces, Metrics, and Logs for LLM Agents (Pipelines + Exporters) | OpenTelemetry Collector

    Routing Traces, Metrics, and Logs for LLM Agents (Pipelines + Exporters) | OpenTelemetry Collector

    OpenTelemetry Collector for LLM agents: The OpenTelemetry Collector is the most underrated piece of an LLM agent observability stack. Instrumenting your agent runtime is step 1. Step 2 (the step most teams miss) is operationalizing telemetry: routing, batching, sampling, redaction, and exporting traces/metrics/logs to the right backend without rewriting every service.

    OpenTelemetry Collector for LLM agents

    If you are building agents with tool calling, RAG, retries, and multi-step plans, your system generates a lot of spans. The Collector lets you keep what matters (errors/slow runs) while controlling cost and enforcing governance centrally.

    TL;DR

    • Think of the Collector as a programmable telemetry router: OTLP in → processors → exporters out.
    • For LLM agents, the Collector is where you enforce consistent attributes like run_id, tool.name, prompt.version, llm.model, and tenant.
    • Use tail sampling so you keep full traces for failed/slow runs and downsample successful runs.
    • Implement redaction at the Collector layer so you never leak PII/secrets into your trace backend.
    • Export via OTLP/Jaeger/Tempo/Datadog/New Relic-without touching app code.

    Table of Contents

    What is the OpenTelemetry Collector?

    The OpenTelemetry Collector is a vendor-neutral service that receives telemetry (traces/metrics/logs), processes it (batching, filtering, sampling, attribute transforms), and exports it to one or more observability backends.

    Instead of configuring exporters inside every microservice/agent/tool, you standardize on sending OTLP to the Collector. From there, your team can change destinations, apply policy, and manage cost in one place.

    Why LLM agents need the Collector (not just SDK instrumentation)

    • Central policy: enforce PII redaction, attribute schema, and retention rules once.
    • Cost control: agents generate high span volume; the Collector is where sampling and filtering becomes practical.
    • Multi-backend routing: send traces to Tempo for cheap storage, but also send error traces to Sentry/Datadog/New Relic.
    • Reliability: buffer/batch/queue telemetry so your app doesn’t block on exporter issues.
    • Consistency: align tool services, background workers, and the agent runtime under one trace model.

    Collector architecture: receivers → processors → exporters

    The Collector is configured as pipelines:

    receivers  ->  processors  ->  exporters
    (OTLP in)       (policy)       (destinations)

    Typical building blocks you’ll use for agent systems:

    • Receivers: otlp (gRPC/HTTP), sometimes jaeger or zipkin for legacy sources.
    • Processors: batch, attributes, transform, tail_sampling, memory_limiter.
    • Exporters: otlp/otlphttp to Tempo/OTel backends, Jaeger exporter, vendor exporters.

    A practical telemetry model for LLM agents

    Before you write Collector config, define a small attribute schema. This makes traces searchable and makes sampling rules possible.

    • Trace = 1 user request / 1 agent run
    • Span = a step (plan, tool call, retrieval, final response)
    • Key attributes (examples):
    • run_id: stable id you also log in your app
    • tenant / org_id: for multi-tenant systems
    • tool.name, tool.type, tool.status, tool.latency_ms
    • llm.provider, llm.model, llm.tokens_in, llm.tokens_out
    • prompt.version or prompt.hash
    • rag.top_k, rag.source, rag.hit_count (avoid raw content)

    Recommended pipelines for agents (traces, metrics, logs)

    Most agent teams should start with traces first, then add metrics/logs once the trace schema is stable.

    Minimal traces pipeline (starter)

    receivers:
      otlp:
        protocols:
          grpc:
          http:
    
    processors:
      memory_limiter:
        check_interval: 1s
        limit_mib: 512
      batch:
        timeout: 2s
        send_batch_size: 2048
    
    exporters:
      otlphttp/tempo:
        endpoint: http://tempo:4318
    
    service:
      pipelines:
        traces:
          receivers: [otlp]
          processors: [memory_limiter, batch]
          exporters: [otlphttp/tempo]

    Agent-ready traces pipeline (attributes + tail sampling)

    This is where the Collector starts paying for itself: you keep the traces that matter.

    processors:
      attributes/agent:
        actions:
          # Example: enforce a standard service.name if missing
          - key: service.name
            action: upsert
            value: llm-agent
    
      tail_sampling:
        decision_wait: 10s
        num_traces: 50000
        expected_new_traces_per_sec: 200
        policies:
          # Keep all error traces
          - name: errors
            type: status_code
            status_code:
              status_codes: [ERROR]
          # Keep slow runs (e.g., total run > 8s)
          - name: slow
            type: latency
            latency:
              threshold_ms: 8000
          # Otherwise sample successful runs at 5%
          - name: probabilistic-success
            type: probabilistic
            probabilistic:
              sampling_percentage: 5

    Tail sampling patterns for agent runs

    Agent systems are spiky: a single run can generate dozens of spans (planner + multiple tool calls + retries). Tail sampling helps because it decides after it sees how the trace ended.

    • Keep 100% of traces where error=true or span status is ERROR.
    • Keep 100% of traces where a tool returned 401/403/429/500 or timed out.
    • Keep 100% of traces where the run latency exceeds a threshold.
    • Sample the rest (e.g., 1-10%) for baseline performance monitoring.

    Redaction, governance, and safe logging

    LLM systems deal with sensitive inputs (customer text, internal docs, credentials). Your tracing stack must be designed for safety. Practical rules:

    • Never export secrets: API keys, tokens, cookies. Log references (key_id) only.
    • Redact PII: emails, phone numbers, addresses. Avoid raw prompts/tool arguments in production.
    • Separate data classes: store aggregated metrics longer; store raw prompts/traces on short retention.
    • RBAC: restrict who can view tool arguments, retrieved snippets, and prompt templates.
    • Auditability: keep enough metadata to answer “who/what/when” without storing raw payloads.

    Deployment options and scaling

    • Sidecar: best when you want per-service isolation; simpler network policies.
    • DaemonSet (Kubernetes): good default; each node runs a Collector instance.
    • Gateway: centralized Collectors behind a load balancer; good for advanced routing and multi-tenant setups.

    Also enable memory_limiter + batch to avoid the Collector becoming the bottleneck.

    Troubleshooting and validation

    • Verify your app exports OTLP: you should see spans in the backend within seconds.
    • If traces are missing, check network (4317 gRPC / 4318 HTTP) and service discovery.
    • Add a temporary logging exporter in non-prod to confirm the Collector receives data.
    • Ensure context propagation works across tools; otherwise traces will fragment.

    Tools & platforms (official + GitHub links)

    Production checklist

    • Define a stable trace/attribute schema for agent runs (run_id, tool spans, prompt version).
    • Route OTLP to the Collector (don’t hard-code exporters per service).
    • Enable batching + memory limits.
    • Implement tail sampling for errors/slow runs and downsample success.
    • Add redaction rules + RBAC + retention controls.
    • Validate end-to-end trace continuity across tool services.

    FAQ

    Do I need the Collector if I already use an APM like Datadog/New Relic?

    Often yes. The Collector lets you enforce sampling/redaction and route telemetry cleanly. You can still export to your APM-it becomes one destination rather than the only architecture.

    Should I store prompts and tool arguments in traces?

    In production, avoid raw payloads by default. Store summaries/hashes and only enable detailed logging for short-lived debugging with strict access control.

    Related reads on aivineet

    OpenTelemetry Collector for LLM agents is especially useful for agent systems where you need to debug tool calls and control telemetry cost with tail sampling.

  • Lightweight Distributed Tracing for Agent Workflows (Quick Setup + Visibility) | Zipkin

    Lightweight Distributed Tracing for Agent Workflows (Quick Setup + Visibility) | Zipkin

    Zipkin for LLM agents: Zipkin is the “get tracing working today” option. It’s lightweight, approachable, and perfect when you want quick visibility into service latency and failures without adopting a full observability suite.

    Zipkin for LLM agents

    For LLM agents, Zipkin can be a great starting point: it helps you visualize the sequence of tool calls, measure step-by-step latency, and detect broken context propagation. This guide covers how to use Zipkin effectively for agent workflows, and when you should graduate to Jaeger or Tempo.

    TL;DR

    • Zipkin is a lightweight tracing backend for visualizing end-to-end latency.
    • Model 1 agent request as 1 trace; model tool calls as spans.
    • Add run_id + tool.name attributes so traces are searchable.
    • Start with Zipkin for small systems; move to Tempo/Jaeger when volume/features demand it.

    Table of Contents

    What Zipkin is good for

    • Small to medium systems where you want quick trace visibility.
    • Understanding latency distribution across steps (model call vs tool call).
    • Detecting broken trace propagation across services.

    How to model agent workflows in traces

    Keep it simple and consistent:

    • Trace = one agent run (one user request)
    • Spans = planner, tool calls, retrieval, final compose
    • Attributes = run_id, tool.name, http.status_code, retry.count, llm.model, prompt.version

    Setup overview: OTel → Collector → Zipkin

    A clean approach is to use OpenTelemetry everywhere and export to Zipkin via the Collector:

    receivers:
      otlp:
        protocols:
          grpc:
          http:
    
    processors:
      batch:
    
    exporters:
      zipkin:
        endpoint: http://zipkin:9411/api/v2/spans
    
    service:
      pipelines:
        traces:
          receivers: [otlp]
          processors: [batch]
          exporters: [zipkin]

    Debugging tool calls and retries

    • Slow agent? Find the longest span. If it’s a tool call, inspect status/timeout/retries.
    • Incorrect output? Trace helps you confirm which tools were called and in what order.
    • Fragmented traces? That’s usually missing context propagation across tools.

    When to move to Jaeger or Tempo

    • Move to Jaeger when you want a more full-featured tracing experience and broader ecosystem usage.
    • Move to Tempo when trace volume becomes high and you want object-storage economics.

    Privacy + safe logging

    • Don’t store raw prompts and tool arguments by default.
    • Redact PII and secrets at the Collector layer.
    • Use short retention for raw traces; longer retention for derived metrics.

    Tools & platforms (official + GitHub links)

    Production checklist

    • Add run_id to traces and your app logs.
    • Instrument planner + each tool call as spans.
    • Validate context propagation so traces don’t fragment.
    • Use the Collector for batching and redaction.
    • Revisit backend choice when volume grows (Jaeger/Tempo).

    Related reads on aivineet

    Zipkin for LLM agents helps you debug tool calls, measure per-step latency, and keep distributed context across services.

  • Storing High-Volume Agent Traces Cost-Efficiently (OTel/Jaeger/Zipkin Ingest) | Grafana Tempo

    Storing High-Volume Agent Traces Cost-Efficiently (OTel/Jaeger/Zipkin Ingest) | Grafana Tempo

    Grafana Tempo for LLM agents: Grafana Tempo is built for one job: store a huge amount of tracing data cheaply, with minimal operational complexity. That matters for LLM agents because agent runs can generate a lot of spans: planning, tool calls, retries, RAG steps, and post-processing.

    Grafana Tempo for LLM agents

    In this guide, we’ll explain when Tempo is the right tracing backend for agent systems, how it ingests OTel/Jaeger/Zipkin protocols, and how to design a retention strategy that doesn’t explode your bill.

    TL;DR

    • Tempo is great when you have high trace volume and want object storage economics.
    • Send OTLP to an OpenTelemetry Collector, then export to Tempo (simplest architecture).
    • Store raw traces short-term; derive metrics (spanmetrics) for long-term monitoring.
    • Use Grafana’s trace UI to investigate slow/failed agent runs and drill into tool spans.

    Table of Contents

    When Tempo is the right choice for LLM agents

    • Your agents generate high span volume (multi-step plans, retries, tool chains).
    • You want cheap long-ish storage using object storage (S3/GCS/Azure Blob).
    • You want to explore traces in Grafana alongside metrics/logs.

    If you’re early and want the classic standalone tracing UI experience, Jaeger may feel simpler. Tempo shines once volume grows and cost starts to matter.

    Ingest options: OTLP / Jaeger / Zipkin

    Tempo supports multiple ingestion protocols. For new agent systems, standardize on OTLP because it keeps you aligned with OpenTelemetry across traces/metrics/logs.

    • OTLP: recommended (agent runtime + tools export via OpenTelemetry SDK)
    • Jaeger: useful if you already have Jaeger clients
    • Zipkin: useful if you already have Zipkin instrumentation

    Reference architecture: Agent → Collector → Tempo → Grafana

    Agent runtime + tool services (OTel SDK)
       -> OpenTelemetry Collector (batch + tail sampling + redaction)
          -> Grafana Tempo (object storage)
             -> Grafana (trace exploration + correlations)

    This design keeps app code simple: emit OTLP only. The Collector is where you route and apply policy.

    Cost, retention, and sampling strategy

    Agent tracing can become expensive because each run can produce dozens of spans. A cost-safe approach:

    • Tail sample: keep 100% of error traces + slow traces; downsample successful traces.
    • Short retention for raw traces: e.g., 7-30 days depending on compliance.
    • Long retention for metrics: derive RED metrics (rate, errors, duration) from traces and keep longer.

    Debugging agent runs in Grafana (trace-first workflow)

    • Search by run_id (store it as an attribute on root span).
    • Open the trace timeline and identify the longest span (often a tool call or a retry burst).
    • Inspect attributes: tool status codes, retry counts, model, prompt version, and tenant.

    Turning traces into metrics (SLOs, alerts, dashboards)

    Teams often struggle because “agent quality” is not a single metric. A practical approach is:

    • Define success/failure at the end of the run (span status and/or custom attribute like agent.outcome).
    • Export span metrics (duration, error rate) to Prometheus/Grafana for alerting.
    • Use trace exemplars: alerts should link to sample traces.

    Privacy + governance for trace data

    • Avoid raw prompts/tool payloads by default; store summaries/hashes.
    • Use redaction at the Collector layer.
    • Restrict access to any fields that might contain user content.

    Tools & platforms (official + GitHub links)

    Production checklist

    • Standardize on OTLP from agent + tools.
    • Use the Collector for tail sampling + redaction + batching.
    • Store run_id, tool.name, llm.model, prompt.version for trace search.
    • Define retention: raw traces short, derived metrics long.
    • Make alerts link to example traces for fast debugging.

    Related reads on aivineet

    Grafana Tempo for LLM agents helps you debug tool calls, measure per-step latency, and keep distributed context across services.

  • Debugging LLM Agent Tool Calls with Distributed Traces (Run IDs, Spans, Failures) | Jaeger

    Debugging LLM Agent Tool Calls with Distributed Traces (Run IDs, Spans, Failures) | Jaeger

    Jaeger for LLM agents: Jaeger is one of the easiest ways to see what your LLM agent actually did in production. When an agent fails, the final answer rarely tells you the real story. The story is in the timeline: planning, tool selection, retries, RAG retrieval, and downstream service latency.

    Jaeger for LLM agents

    In this guide, we’ll build a practical Jaeger workflow for debugging tool calls and multi-step agent runs using OpenTelemetry. We’ll focus on what teams need in real systems: searchability (run_id), safe logging, and fast incident triage.

    TL;DR

    • Trace = 1 user request / 1 agent run.
    • Span = each step (plan, tool call, retrieval, final).
    • Add run_id, tool.name, llm.model, prompt.version as span attributes so Jaeger search works.
    • Keep 100% of error traces (tail sampling) and downsample the rest.
    • Don’t store raw prompts/tool args in production by default; store summaries/hashes + strict RBAC.

    Table of Contents

    What Jaeger is (and what it is not)

    Jaeger is an open-source distributed tracing backend. It stores traces (spans), provides a UI to explore timelines, and helps you understand request flows across services.

    Jaeger is not a complete observability platform by itself. Most teams pair it with metrics (Prometheus/Grafana) and logs (ELK/OpenSearch/Loki). For LLM agents, Jaeger is the best “trace-first” entry point because timelines are how agent failures present.

    Why Jaeger is great for agent debugging

    • Request narrative: agents are sequential + branching systems. Traces show the narrative.
    • Root-cause speed: instantly spot if the tool call timed out vs. the model stalled.
    • Cross-service visibility: planner service → tool service → DB → third-party API, all in one view.

    Span model for tool calling and RAG

    Start with a consistent span naming convention. Example:

    trace (run_id=R123)
      span: agent.plan
      span: llm.generate (model=gpt-4.1)
      span: tool.search (tool.name=web_search)
      span: tool.search.result (http.status=200)
      span: rag.retrieve (top_k=10)
      span: final.compose

    Recommended attributes (keep them structured):

    • run_id (critical: makes incident triage fast)
    • tool.name, tool.type, tool.status, http.status_code
    • llm.provider, llm.model, llm.tokens_in, llm.tokens_out
    • prompt.version or prompt.hash
    • rag.top_k, rag.source, rag.hit_count (avoid raw retrieved content)

    The cleanest workflow is: your app logs a run_id for each user request, and Jaeger traces carry the same attribute. Then you can search Jaeger by run_id and open the exact trace in seconds.

    • Log run_id at request start and return it in API responses for support tickets.
    • Add run_id as a span attribute on the root span (and optionally all spans).
    • Use Jaeger search to filter by run_id, error=true, or tool.name.

    Common failure patterns Jaeger reveals

    1) Broken context propagation (fragmented traces)

    If tool calls run as separate services, missing trace propagation breaks the timeline. You’ll see disconnected traces instead of one end-to-end trace. Fix: propagate trace headers (W3C Trace Context) into tool HTTP calls or internal RPC.

    2) “Tool call succeeded” but agent still failed

    This often indicates parsing/validation issues (schema mismatch), prompt regression, or poor retrieval. The trace shows tool latency is fine; failure happens in the LLM generation span or post-processing span.

    3) Slow runs caused by retries

    Retries add up. In Jaeger, you’ll see repeated tool spans. Add attributes like retry.count and retry.reason to make it obvious.

    Setup overview: OTel → Collector → Jaeger

    A simple production-friendly architecture is:

    Agent Runtime (OTel SDK)  ->  OTel Collector  ->  Jaeger (storage + UI)

    Export OTLP from your agent to the Collector, apply tail sampling + redaction there, and export to Jaeger.

    Privacy + redaction guidance

    • Do not store raw prompts/tool arguments by default in production traces.
    • Store summaries, hashes, or classified metadata (e.g., “contains_pii=true”) instead.
    • Keep detailed logging behind feature flags, short retention, and strict RBAC.

    Tools & platforms (official + GitHub links)

    Production checklist

    • Define a span naming convention + attribute schema (run_id, tool attributes, model info).
    • Propagate trace context into tool calls (headers/middleware).
    • Use tail sampling to keep full traces for failures/slow runs.
    • Redact PII/secrets and restrict access to sensitive trace fields.
    • Train the team on a basic incident workflow: “get run_id → find trace → identify slow/error span → fix.”

    FAQ

    Jaeger vs Tempo: which should I use?

    If you want a straightforward tracing backend with a classic trace UI, Jaeger is a strong default. If you expect very high volume and want object-storage economics, Tempo can be a better fit (especially with Grafana).

    Related reads on aivineet

    Jaeger for LLM agents helps you debug tool calls, measure per-step latency, and keep distributed context across services.

  • LLM Agent Tracing & Distributed Context: End-to-End Spans for Tool Calls + RAG | OpenTelemetry (OTel)

    OpenTelemetry (OTel) is the fastest path to production-grade tracing for LLM agents because it gives you a standard way to follow a request across your agent runtime, tools, and downstream services. If your agent uses RAG, tool calling, or multi-step plans, OTel helps you answer the only questions that matter in production: what happened, where did it fail, and why?

    In this guide, we’ll explain how to instrument an LLM agent with end-to-end traces (spans), how to propagate context across tool calls, and how to store + query traces in backends like Jaeger/Tempo. We’ll keep it practical and enterprise-friendly (redaction, auditability, and performance).

    TL;DR

    • Trace everything: prompt version → plan → tool calls → tool outputs → final answer.
    • Use trace context propagation so tool calls remain linked to the parent run.
    • Model “one user request” as a trace, and each agent/tool step as a span.
    • Export via OTLP to an OpenTelemetry Collector, then route to Jaeger/Tempo or your observability stack.
    • Redact PII and never log secrets; keep raw traces on short retention.

    Table of Contents

    What is OpenTelemetry (OTel)?

    OpenTelemetry is an open standard for collecting traces, metrics, and logs. In practice, OTel gives you a consistent way to generate and export trace data across services. For LLM agents, that means you can follow a single user request through:

    • your API gateway / app server
    • agent planner + router
    • tool calling (search, DB, browser, CRM)
    • RAG retrieval and reranking
    • final synthesis and formatting

    Why agents need distributed tracing

    Agent failures rarely show up in the final answer. More often, the issue is upstream: a tool returned a 429, the model chose the wrong tool, or retrieval returned irrelevant context. Therefore, tracing becomes your “black box recorder” for agent runs.

    • Debuggability: see the exact tool call sequence and timing.
    • Reliability: track where latency and errors occur (per tool, per step).
    • Governance: produce audit trails for data access and actions.

    A trace model for LLM agents (runs, spans, events)

    Start with a simple mapping:

    • Trace = 1 user request (1 agent run)
    • Span = a step (plan, tool call, retrieval, final response)
    • Span attributes = structured fields (tool name, status code, prompt version, token counts)
    trace: run_id=R123
      span: plan (prompt_version=v12)
      span: tool.search (q="...")
      span: tool.search.result (status=200, docs=8)
      span: rag.retrieve (top_k=10)
      span: final.compose (schema=AnswerV3)

    Distributed context propagation for tool calls

    The biggest mistake teams make is tracing the agent runtime but losing context once tools run. To keep spans connected, propagate trace context into tool requests. For HTTP tools this is typically done via headers, and for internal tools it can be done via function parameters or middleware.

    • Use trace_id/span_id propagation into each tool call.
    • Ensure tool services also emit spans (or at least structured logs) with the same trace_id.
    • As a result, your trace UI shows one end-to-end timeline instead of disconnected fragments.

    Tracing RAG: retrieval, embeddings, and citations

    RAG pipelines introduce their own failure modes: missing documents, irrelevant retrieval, and hallucinated citations. Instrument spans for:

    • retrieval query + filters (redacted)
    • top_k results and scores (summaries, not raw content)
    • reranker latency
    • citation coverage (how much of the answer is backed by retrieved text)

    Privacy, redaction, and retention

    • Never log secrets (keys/tokens). Store references only.
    • Redact PII from prompts/tool args (emails, phone numbers, addresses).
    • Short retention for raw traces; longer retention for aggregated metrics.
    • RBAC for viewing prompts/tool args and retrieved snippets.

    Tools & platforms (official + GitHub links)

    Production checklist

    • Define run_id and map 1 request = 1 trace.
    • Instrument spans for plan, each tool call, and final synthesis.
    • Propagate trace context into tool calls (headers/middleware).
    • Export OTLP to an OTel Collector and route to your backend.
    • Redact PII + enforce retention and access controls.

    FAQ

    Do I need an OpenTelemetry Collector?

    Not strictly, but it’s the cleanest way to route OTLP data to multiple backends (Jaeger/Tempo, logs, metrics) without rewriting your app instrumentation.

    Related reads on aivineet

  • LLM Agent Observability & Audit Logs: Tracing, Tool Calls, and Compliance (Enterprise Guide)

    Enterprise LLM agents don’t fail like normal software. They fail in ways that look random: a tool call that “usually works” suddenly breaks, a prompt change triggers a new behavior, or the agent confidently returns an answer that contradicts tool output. The fix is not guesswork – it’s observability and audit logs.

    This guide shows how to instrument LLM agents with tracing, structured logs, and audit trails so you can debug failures, prove compliance, and stop regressions. We’ll cover what to log, how to redact sensitive data, and how to build replayable runs for evaluation.

    TL;DR

    • Log the full agent workflow: prompt → plan → tool calls → outputs → final answer.
    • Use trace IDs and structured events so you can replay and debug.
    • Redact PII/secrets, and enforce retention policies for compliance.
    • Track reliability metrics: tool error rate, retries, latency p95, cost per success.
    • Audit trails matter: who triggered actions, which tools ran, and what data was accessed.

    Table of Contents

    Why observability is mandatory for agents

    With agents, failures often happen in intermediate steps: the model chooses the wrong tool, passes a malformed argument, or ignores a key constraint. Therefore, if you only log the final answer, you’re blind to the real cause.

    • Debuggability: you need to see the tool calls and outputs.
    • Safety: you need evidence of what the agent tried to do.
    • Compliance: you need an audit trail for data access and actions.

    What to log (minimum viable trace)

    Start with a structured event model. For example, every run should emit:

    • run_id, user_id (hashed), session_id, trace_id
    • model, temperature, tools enabled
    • prompt version + system/developer messages (as permitted)
    • tool calls (name, args, timestamps)
    • tool results (status, payload summary, latency)
    • final answer + structured output (JSON)

    Example event schema (simplified)

    {
      "run_id": "run_123",
      "trace_id": "trace_abc",
      "prompt_version": "agent_v12",
      "model": "gpt-5.2",
      "events": [
        {"type": "plan", "ts": 1730000000, "summary": "..."},
        {"type": "tool_call", "tool": "search", "args": {"q": "..."}},
        {"type": "tool_result", "tool": "search", "status": 200, "latency_ms": 842},
        {"type": "final", "output": {"answer": "..."}}
      ]
    }

    Tool-call audits (arguments, responses, side effects)

    Tool-call audits are your safety net. They let you answer: what did the agent do, and what changed as a result?

    • Read tools: log what was accessed (dataset/table/doc IDs), not raw sensitive content.
    • Write tools: log side effects (ticket created, email sent, record updated) with idempotency keys.
    • External calls: log domains, endpoints, and allowlist decisions.

    Privacy, redaction, and retention

    • Redact PII (emails, phone numbers, addresses) in logs.
    • Never log secrets (API keys, tokens). Store references only.
    • Retention policy: keep minimal logs longer; purge raw traces quickly.
    • Access control: restrict who can view prompts/tool args.

    Metrics and alerts (what to monitor)

    • Task success rate and failure reasons
    • Tool error rate (by tool, endpoint)
    • Retries per run and retry storms
    • Latency p50/p95 end-to-end + per tool
    • Cost per successful task
    • Safety incidents (policy violations, prompt injection triggers)

    Replayable runs and regression debugging

    One of the biggest wins is “replay”: take a failed run and replay it against a new prompt or model version. This turns production failures into eval cases.

    Tools, libraries, and open-source platforms (what to actually use)

    If you want to implement LLM agent observability quickly, you don’t need to invent a new logging system. Instead, reuse proven tracing/logging stacks and add agent-specific events (prompt version, tool calls, and safety signals).

    Tracing and distributed context

    LLM-specific tracing / eval tooling

    Logs, metrics, and dashboards

    Security / audit / compliance plumbing

    • SIEM integrations (e.g., Splunk / Microsoft Sentinel): ship audit events for investigations.
    • PII redaction: use structured logging + redaction middleware (hash IDs; never log secrets).
    • RBAC: restrict who can view prompts, tool args, and retrieved snippets.

    Moreover, if you’re using agent frameworks (LangChain, LlamaIndex, custom tool routers), treat their built-in callbacks as a starting point – then standardize everything into OTel spans or a single event schema.

    Implementation paths

    • Path A: log JSON events to a database (fast start) – e.g., Postgres + a simple admin UI, or OpenSearch for search.
    • Path B: OpenTelemetry tracing + log pipeline – e.g., OTel Collector + Jaeger/Tempo + Prometheus/Grafana.
    • Path C: governed audit trails + SIEM integration – e.g., immutable audit events + Splunk/Microsoft Sentinel + retention controls.

    Production checklist

    • Define run_id/trace_id and structured event schema.
    • Log tool calls and results with redaction.
    • Add metrics dashboards for success, latency, cost, errors.
    • Set alerts for regressions and safety spikes.
    • Store replayable runs for debugging and eval expansion.

    FAQ

    Should I log chain-of-thought?

    Generally no. Prefer short structured summaries (plan summaries, tool-call reasons) and keep sensitive reasoning out of logs.

    Related reads on aivineet

  • Tool Calling Reliability for LLM Agents: Schemas, Validation, Retries (Production Checklist)

    Tool calling is where most “agent demos” die in production. Models are great at writing plausible text, but tools require correct structure, correct arguments, and correct sequencing under timeouts, partial failures, and messy user inputs. If you want reliable LLM agents, you need a tool-calling reliability layer: schemas, validation, retries, idempotency, and observability.

    This guide is a practical, production-first checklist for making tool-using agents dependable. It focuses on tool schemas, strict validation, safe retries, rate limits, and the debugging instrumentation you need to stop “random” failures from becoming incidents.

    TL;DR

    • Define tight tool schemas (types + constraints) and validate inputs and outputs.
    • Prefer deterministic tools and idempotent actions where possible.
    • Use retries with backoff only for safe failure modes (timeouts, 429s), not logic errors.
    • Add timeouts, budgets, and stop conditions to prevent tool thrashing.
    • Log everything: tool name, args, response, latency, errors (with PII redaction).

    Table of Contents

    Why tool calling fails in production

    Tool calls fail for boring reasons – and boring reasons are the hardest to debug when an LLM is in the loop:

    • Schema drift: the tool expects one shape; the model produces another.
    • Ambiguous arguments: the model guesses missing fields (wrong IDs, wrong dates, wrong currency).
    • Partial failures: retries, timeouts, and 429s create inconsistent state.
    • Non-idempotent actions: “retry” creates duplicates (double charge, duplicate ticket, repeated email).
    • Tool thrashing: the agent loops, calling tools without converging.

    Therefore, reliability comes from engineering the boundary between the model and the tools – not from “better prompting” alone.

    Tool schemas: types, constraints, and guardrails

    A good tool schema is more than a JSON shape. It encodes business rules and constraints so the model has fewer ways to be wrong.

    Design principles

    • Make required fields truly required. No silent defaults.
    • Use enums for modes and categories (avoid free text).
    • Constrain strings with patterns (e.g., ISO dates, UUIDs).
    • Separate “intent” from “execution” (plan first, act second).

    Example: a strict tool schema (illustrative)

    {
      "name": "create_support_ticket",
      "description": "Create a support ticket in the helpdesk.",
      "parameters": {
        "type": "object",
        "additionalProperties": false,
        "required": ["customer_id", "subject", "priority", "body"],
        "properties": {
          "customer_id": {"type": "string", "pattern": "^[0-9]{6,}$"},
          "subject": {"type": "string", "minLength": 8, "maxLength": 120},
          "priority": {"type": "string", "enum": ["low", "medium", "high", "urgent"]},
          "body": {"type": "string", "minLength": 40, "maxLength": 4000},
          "idempotency_key": {"type": "string", "minLength": 12, "maxLength": 80}
        }
      }
    }

    Notice the constraints: no extra fields, strict required fields, patterns, and an explicit idempotency key.

    Validation: input, output, and schema enforcement

    In production, treat the model as an untrusted caller. Validate both directions:

    • Input validation: before the tool runs (types, required fields, bounds).
    • Output validation: after the tool runs (expected response schema).
    • Semantic validation: sanity checks (dates in the future, currency totals add up, IDs exist).

    Example: schema-first execution (pseudo)

    1) Model proposes tool call + arguments
    2) Validator checks JSON schema (reject if invalid)
    3) Business rules validate semantics (reject if unsafe)
    4) Execute tool with timeout + idempotency key
    5) Validate tool response schema
    6) Only then show final answer to user

    Retries: when they help vs when they make it worse

    Retries are useful for transient failures (timeouts, 429 rate limits). However, they are dangerous for logic failures (bad args) and non-idempotent actions.

    • Retry timeouts, connection errors, and 429s with exponential backoff.
    • Do not retry 400s without changing arguments (force the model to correct the call).
    • Cap retries and add a fallback path (ask user for missing info, escalate to human).

    Idempotency: the key to safe actions

    Idempotency means “the same request can be applied multiple times without changing the result.” It is the difference between safe retries and duplicated side effects.

    • For write actions (create ticket, charge card, send email), require an idempotency key.
    • Store and dedupe by that key for a reasonable window.
    • Return the existing result if the key was already processed.

    Budgets, timeouts, and anti-thrashing

    • Timeout every tool call (hard upper bound).
    • Budget tool calls per task (e.g., max 8 calls) and max steps.
    • Stop conditions: detect loops, repeated failures, or repeated identical calls.
    • Ask-for-clarification triggers: missing IDs, ambiguous user intent, insufficient context.

    Observability: traces, audits, and debugging

    When a tool-using agent fails, you need to answer: what did it try, what did the tool return, and why did it choose that path?

    • Log: tool name, args (redacted), response (redacted), latency, retries, error codes.
    • Add trace IDs across model + tools for end-to-end debugging.
    • Store “replayable” runs for regression testing.

    Production checklist

    • Define strict tool schemas (no extra fields).
    • Validate inputs and outputs with schemas.
    • Add semantic checks for high-risk parameters.
    • Enforce timeouts + budgets + stop conditions.
    • Require idempotency keys for side-effect tools.
    • Retry only safe transient failures with backoff.
    • Instrument tracing and tool-call audits (with redaction).

    FAQ

    Is prompting enough to make tool calling reliable?

    No. Prompting helps, but production reliability comes from schemas, validation, idempotency, and observability.

    What should I implement first?

    Start with strict schemas + validation + timeouts. Then add idempotency for write actions, and finally build monitoring and regression evals.

    Related reads on aivineet

  • Agent Evaluation Framework: How to Test LLM Agents (Offline Evals + Production Monitoring)

    If you ship LLM agents in production, you’ll eventually hit the same painful truth: agents don’t fail once-they fail in new, surprising ways every time you change a prompt, tool, model, or knowledge source. That’s why you need an agent evaluation framework: a repeatable way to test LLM agents offline, monitor them in production, and stop regressions before customers do.

    This guide gives you a practical, enterprise-ready evaluation stack: offline evals, golden tasks, scoring rubrics, automated regression checks, and production monitoring (traces, tool-call audits, and safety alerts). If you’re building under reliability/governance constraints, this is the fastest way to move from “it works on my laptop” to “it holds up in the real world.”

    Moreover, an evaluation framework is not a one-time checklist. It is an ongoing loop that improves as your agent ships to more users and encounters more edge cases.

    TL;DR

    • Offline evals catch regressions early (prompt changes, tool changes, model upgrades).
    • Evaluate agents on task success, not just “answer quality”. Track tool-calls, latency, cost, and safety failures.
    • Use golden tasks + adversarial tests (prompt injection, tool misuse, long context failures).
    • In production, add tracing + audits (prompt/tool logs), plus alerts for safety/quality regressions.
    • Build a loop: Collect → Label → Evaluate → Fix → Re-run.

    Table of Contents

    What is an agent evaluation framework?

    An agent evaluation framework is the system you use to measure whether an LLM agent is doing the right thing reliably. It includes:

    • A set of representative tasks (real user requests, not toy prompts)
    • A scoring method (success/failure + quality rubrics)
    • Automated regression tests (run on every change)
    • Production monitoring + audits (to catch long-tail failures)

    Think of it like unit tests + integration tests + observability-except for an agent that plans, calls tools, and works with messy context.

    Why agents need evals (more than chatbots)

    Agents are not “just chat.” Instead, they:

    • call tools (APIs, databases, browsers, CRMs)
    • execute multi-step plans
    • depend on context (RAG, memory, long documents)
    • have real-world blast radius (wrong tool action = real incident)

    Therefore, your evals must cover tool correctness, policy compliance, and workflow success-not only “did it write a nice answer?”

    Metrics that matter: success, reliability, cost, safety

    Core outcome metrics

    • Task success rate (binary or graded)
    • Step success (where it fails: plan, retrieve, tool-call, final synthesis)
    • Groundedness (are claims supported by citations / tool output?)

    Reliability + quality metrics

    • Consistency across runs (variance with temperature, retries)
    • Instruction hierarchy compliance (system > developer > user)
    • Format adherence (valid JSON/schema, required fields present)

    Operational metrics

    • Latency (p50/p95 end-to-end)
    • Cost per successful task (tokens + tool calls)
    • Tool-call budget (how often agents “thrash”)

    Safety metrics

    • Prompt injection susceptibility (tool misuse, exfil attempts)
    • Data leakage (PII in logs/output)
    • Policy violations (disallowed content/actions)

    Offline evals: datasets, golden tasks, and scoring

    The highest ROI practice is building a small eval set that mirrors reality: 50-200 tasks from your product. For example, start with the top workflows and the most expensive failures.

    Step 1: Create “golden tasks”

    Golden tasks are the agent equivalent of regression tests. Each task includes:

    • input prompt + context
    • tool stubs / fixtures (fake but realistic tool responses)
    • expected outcome (pass criteria)

    Step 2: Build a scoring rubric (human + automated)

    Start simple with a 1-5 rubric per dimension. Example:

    Score each run (1-5):
    1) Task success
    2) Tool correctness (right tool, right arguments)
    3) Groundedness (claims match tool output)
    4) Safety/policy compliance
    5) Format adherence (JSON/schema)
    
    Return:
    - scores
    - failure_reason
    - suggested fix

    Step 3: Add adversarial tests

    Enterprises get burned by edge cases. Add tests for:

    • prompt injection inside retrieved docs
    • tool timeouts and partial failures
    • long context truncation
    • conflicting instructions

    Production monitoring: traces, audits, and alerts

    Offline evals won’t catch everything. In production, therefore, add:

    • Tracing: capture the plan, tool calls, and intermediate reasoning outputs (where allowed).
    • Tool-call audits: log tool name + arguments + responses (redact PII).
    • Alerts: spikes in failure rate, cost per task, latency, or policy violations.

    As a result, production becomes a data pipeline: failures turn into new eval cases.

    3 implementation paths (simple → enterprise)

    Path A: Lightweight (solo/early stage)

    • 50 golden tasks in JSONL
    • manual review + rubric scoring
    • run weekly or before releases

    Path B: Team-ready (CI evals)

    • run evals on every PR that changes prompts/tools
    • track p95 latency + cost per success
    • store traces + replay failures

    Path C: Enterprise (governed agents)

    • role-based access to logs and prompts
    • redaction + retention policies
    • approval workflows for high-risk tools
    • audit trails for compliance

    A practical checklist for week 1

    • Pick 3 core workflows and extract 50 tasks from them.
    • Define success criteria + rubrics.
    • Stub tool outputs for deterministic tests.
    • Run baseline on your current agent and record metrics.
    • Add 10 adversarial tests (prompt injection, tool failures).

    FAQ

    How many eval cases do I need?

    Start with 50-200 real tasks. You can get strong signal quickly. Expand based on production failures.

    Should I use LLM-as-a-judge?

    Yes, but don’t rely on it blindly. Use structured rubrics, spot-check with humans, and keep deterministic checks (schema validation, tool correctness) wherever possible.

    Related reads on aivineet