← Back to modules

AI Agents in Production — Advanced

Compound error rates, token cost growth, MCP architecture, LangGraph checkpointer trade-offs, Store API memory, interrupt/Command flow, multi-agent patterns (supervisor/swarm/handoff), A2A protocol, planning pattern comparisons, agent evaluation, prompt injection through tools, guardrail layering, trace debugging, deployment security.

Hard40 questions

Sample questions

1

An agent model has 95% per-step accuracy. A 5-step plan succeeds with probability 0.77. If you improve per-step accuracy to 97%, what is the success probability for a 10-step plan?

  • About 85%, because the 97% accuracy compounds less aggressively than 95% and most of the error budget is consumed by the first 5 steps of the plan
  • About 74%, computed as 0.97 raised to the 10th power, demonstrating that even a 2% accuracy improvement significantly extends the viable plan length
  • About 60%, because 10-step plans always have roughly the same success rate regardless of per-step accuracy once the plan exceeds a critical length threshold
  • About 90%, because improving accuracy by 2 percentage points roughly doubles the effective plan length that can be executed at any given success probability target

Why

The success probability for a multi-step agent plan where each step succeeds independently with probability p is p raised to the N power. At 97% accuracy with 10 steps, this is 0.97 to the 10th power, which equals approximately 0.737 or about 74%. Compare this to 95% accuracy at 10 steps: 0.95 to the 10th equals 0.60, or 60%. The 2-percentage-point improvement in per-step accuracy raises the 10-step success rate from 60% to 74%, a 14-percentage-point improvement. This demonstrates that small improvements in per-step reliability have outsized impact on multi-step plans because the improvement compounds at each step. The 85% estimate incorrectly assumes non-uniform error distribution across steps. The 60% estimate uses the old 95% accuracy rate, not the improved 97%. The 90% estimate overstates the improvement. The practical implication is that investing in better tool descriptions, structured outputs, and observation validation to push per-step accuracy from 95% to 97% can nearly double the viable plan length from 5 steps to 10 steps while maintaining acceptable success rates.

2

An agent loop with system prompt S=2000 tokens, query Q=100 tokens, and average round R=400 tokens runs for N=10 iterations. Why is the total input token consumption approximately 43,000 rather than the 25,000 that linear growth would predict?

  • Each iteration duplicates the system prompt in the context, and the duplication overhead compounds quadratically because the model re-tokenizes the full prompt at each step
  • The tool results embedded in each observation grow larger at each step because the model requests more detailed tool outputs as the task progresses toward completion
  • Each iteration sends the full conversation history, so iteration N includes all N-1 prior rounds, making the history term grow as R times N times (N+1) divided by 2
  • The model generates progressively longer outputs at each iteration as it accumulates more context, and the output length growth follows a quadratic curve bounded by the context window

Why

Each iteration of the agent loop sends the full conversation history to the model as input. Iteration 1 sends just the system prompt and query. Iteration 2 sends the system prompt, query, plus the first assistant-observation round. Iteration N sends all N-1 prior rounds. The total input across N iterations is N times S plus N times Q plus R times the sum from 1 to N-1, which equals R times N times (N-1) divided by 2. With the system prompt repeated N times and the query repeated N times, plus the quadratic history term, the formula becomes N times (S plus Q) plus R times N times (N+1) divided by 2. Plugging in S=2000, Q=100, R=400, N=10: 10 times 2100 plus 400 times 10 times 11 divided by 2 equals 21000 plus 22000 equals 43000. The linear estimate of 25000 would assume each iteration adds a fixed amount without the growing history. The system prompt is not re-tokenized; it is the growing conversation history that creates the quadratic term. Output lengths do not systematically grow per iteration. Tool result sizes are typically consistent. This quadratic growth is why prompt caching, history truncation, and cheaper models for routing steps are critical cost optimizations.

3

An MCP server exposes tools through a standardized JSON-RPC interface. What architectural property makes MCP different from framework-specific tool integrations like LangChain tools?

  • MCP inverts the integration: the server exposes capabilities once and any compatible client can discover and use them, rather than requiring per-framework adapter code for each tool
  • MCP tools run inside the LLM's inference process for lower latency, while framework tools run in a separate process and communicate through interprocess serialization
  • MCP provides built-in authentication and rate limiting for every tool automatically, while framework tools require the developer to implement these security controls manually
  • MCP compiles tool definitions into the model's system prompt at startup for faster tool selection, while framework tools are passed as separate function schemas alongside each request

Why

Before MCP, each agent framework implemented its own tool interface: LangChain tools are Python classes with a _run method, OpenAI plugins use an OpenAPI spec, and custom agents use ad-hoc function registries. A tool built for one framework had to be rewritten for another. MCP inverts this by defining a standard JSON-RPC interface that any server can implement and any client can consume. The server is written once; clients are interchangeable. This is the same design principle as REST APIs: define the interface, not the implementation. MCP tools do not run inside the inference process; they run as separate server processes communicating over standard transports. Tool definitions are not compiled into the system prompt; they are discovered at runtime through the protocol's capability negotiation. MCP does not provide built-in auth or rate limiting; those are concerns of the transport and application layers. The practical benefit is tool ecosystem reuse: an MCP server for database access works with Claude Desktop, Cursor, a LangGraph agent, or any custom MCP client without any adapter code.

4

LangGraph provides MemorySaver, SqliteSaver, and PostgresSaver as checkpointer backends. For a production agent handling 1000 concurrent conversations, which should you use and why?

  • MemorySaver, because it writes checkpoints in 0.02ms versus 12ms for PostgresSaver, and the latency difference matters when LLM calls take 500-2000ms per step
  • PostgresSaver, because MemorySaver loses all state on process restart, SqliteSaver cannot handle concurrent writes from multiple processes, and Postgres provides both durability and multi-process access
  • SqliteSaver, because SQLite handles concurrent writes through WAL mode and provides persistence without the operational overhead of running a separate database server
  • Any backend works equally well because the checkpointer is only used for crash recovery and the choice does not affect normal operation, latency, or concurrency handling, which is the standard recommendation for production agent deployments at scale

Why

For production agents handling 1000 concurrent conversations, PostgresSaver is the correct choice for three reasons. First, durability: MemorySaver stores checkpoints in a Python dictionary that is lost when the process restarts, meaning all active conversations lose their state on any restart or deployment. Second, multi-process access: SQLite uses file-level locking that does not support concurrent writes from multiple application processes, which is required when running multiple API server instances behind a load balancer. Postgres handles concurrent writes through its MVCC transaction system. Third, operational maturity: Postgres provides built-in replication, backups, and connection pooling. The 12ms write latency for PostgresSaver versus 0.02ms for MemorySaver is negligible when LLM calls in the agent loop take 500-2000ms per step; the checkpointer latency is less than 1% of total step time. The checkpoint backend absolutely affects normal operation because it determines whether conversations can be resumed after process restarts and whether multiple server instances can serve the same conversation. Co-locating the database with the agent service minimizes the network round-trip that dominates Postgres write latency.

5

LangGraph's Store API provides long-term memory through a key-value store with optional semantic search. When accumulated memories exceed 500 facts at 20 tokens each, why does memory retrieval become necessary instead of injecting all facts into the system prompt?

  • The model's tokenizer cannot process more than 500 individual fact entries in a single prompt because of internal buffer limits on the number of distinct semantic units per message
  • Long fact lists in the system prompt cause the model to hallucinate connections between unrelated facts, producing confabulated responses that combine memories inappropriately
  • Injecting 500 facts at 20 tokens each adds 10,000 tokens to every prompt, costing $0.025 per call on GPT-4o and degrading model attention on the actual query as the prompt grows
  • The Store API only supports storing up to 500 entries per namespace, so any additional facts must be retrieved on demand from an external vector database to stay within the store's capacity

Why

Injecting all accumulated long-term memories into the system prompt creates two problems that scale with memory count. First, cost: 500 facts at 20 tokens each adds 10,000 tokens to every prompt. At GPT-4o's $2.50 per million input tokens, this adds $0.025 per call. For an agent making 5 calls per task across 10,000 daily tasks, that is $1,250 per day just for memory tokens. Second, attention degradation: as the prompt grows longer, the model's effective attention on the user's actual query and task instructions decreases, leading to less relevant and less accurate responses. Retrieval solves both problems by embedding past interactions and searching for only the 5-10 most relevant memories at query time, keeping the injected context small and highly relevant. The tokenizer does not have a buffer limit on semantic units; it processes the full prompt. The Store API does not have a 500-entry capacity limit. While attention degradation is real, it manifests as reduced relevance and accuracy, not specifically as confabulation between unrelated facts. The hybrid approach is standard: inject the 5-10 most critical persistent facts directly and retrieve situationally relevant memories on demand.

Free account

Take the full module

These are the first few of 40 questions. A free account opens the rest as a scored drill.

  • Every question in this module
  • Instant feedback and supporting reading
  • Your score and progress, saved

Free · your email is used for progress only.