KatInterview

Debugging Multi-Step LLM Agent Tool Execution at Scale

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsobservabilityllm-agents

Last updated

Build an observability system to capture, diagnose, and query failures in LLM agent tool calls across retries and execution phases.

Context

Production LLM agents orchestrate sequences of tool executions—database queries, API calls, sandboxed code runs, web searches—to complete user requests. These tools fail often: the model generates malformed arguments, services time out, rate limits trigger, schemas drift, or downstream dependencies return errors. When an agent retries a failed tool or switches strategies across multiple conversation turns, isolating the root cause without comprehensive telemetry becomes nearly impossible.

Your task is to design an observability platform that captures and organizes telemetry for agent tool execution, enabling engineers to debug failures efficiently while operating at high scale.

Requirements

Core Functionality

Structured trace hierarchy: Organize events in a four-level hierarchy where each agent session contains turns, each turn contains tool calls, and each tool call contains one or more execution attempts. Retries must appear as separate child attempts under the same tool call, preserving the full attempt history.

Lifecycle error classification: Tag each failure with its lifecycle phase:

  • Argument generation: Model output invalid, schema validation rejected the arguments
  • Transport and execution: Network failures, HTTP errors (4xx/5xx), sandbox crashes, timeouts
  • Response handling: Parse errors, output truncation, policy violations detected post-execution

Payload capture with safety controls: Store enough context to debug (input arguments, error details, partial responses) while protecting secrets and preventing storage cost explosion from oversized outputs.

Retry metadata: Record the retry strategy used (max attempts, backoff timing), the attempt sequence number, delays applied, and the terminal outcome (succeeded eventually, gave up after budget exhausted, hit unrecoverable error).

Query capabilities: Engineers should be able to filter traces by error type, tool name, session identifier, or latency threshold to investigate patterns.

Scale and Performance Constraints

  • Handle 50,000 tool executions per second at peak
  • Telemetry overhead must stay under 5ms at P99 for any single tool call
  • The system must never block agent progress, even during telemetry pipeline outages
  • Keep full debug context for 7 days; retain aggregated error metrics for 90 days

What You Should Address

Schema design: Define the structure of a trace span for a tool execution attempt. Show how context flows between levels and how errors are classified.

System architecture: Describe the components from instrumentation in the agent runtime through collection, processing, and storage. Justify technology choices for the pipeline and query layer.

Data safety: Explain your approach to redacting secrets, handling PII, and managing payload size (inline vs. external storage, truncation strategies).

Sampling strategy: Discuss how you balance capturing all failures for debugging against the cost of storing high-volume success telemetry.

Hints

Hint 1

Think about what absolutely must be on the critical path versus what can happen asynchronously in the background

Hint 2

Consider how context propagation standards like OpenTelemetry handle parent-child relationships across service boundaries

Hint 3

Small metadata can be stored at 100% while large payloads need selective sampling based on outcome