The Agentic Frontier — 2026 Field Guide

🚀 13 chapters · autonomy levels · self-healing · durable execution · judge panels · computer use · MCP · start with the concept primer: Agent Autonomy field guide →

📦 An industry-landscape field guide in the How It Works family — the patterns here describe the 2026 agentic ecosystem at large, not this site. For how this site itself works, read the written guide →

01. The 2026 Agentic Landscape

The way we build AI agents has changed dramatically by mid two thousand twenty-six. We no longer just make a single call to a model. Now agents think, act, and observe in a loop until they finish a task. That loop is the atomic unit of everything.

There is a ladder of complexity. The simplest system uses one model call. Next is a chain of calls that break a problem into steps. Then a router lets the model choose what action to take. A state machine combines that router with a loop. The loop can run any number of times. At the top, an autonomous agent removes all guardrails. It decides its own steps and tools. Most teams try to start at the top. But that is a mistake.

The best systems start simple. If you only need a model and a few tools, you do not need a heavy framework. A provider software development kit and a couple of tool calls get you to production faster than any graph. Add complexity only when something specific breaks. Do not design a multi-agent architecture before you have shipped one working agent. The teams that succeed run evaluations on every deploy, not once a quarter.

The newest turn is that agents adapt themselves over time. They are not fixed after deployment. For example, the code editor Cursor retrains its acceptance model every ninety minutes. It does this based on whether users accept or reject suggestions. That is evaluation running in production continuously. The agent learns from its own mistakes.

Tool connectivity has also become standard. The Model Context Protocol, or M C P, now transfers across all major frameworks. It works with provider SDKs, graph frameworks, and custom code. This means an agent built in one system can use the same tools as another. Interoperability is real and open.

But production is still hard. Most teams skip evaluation until something breaks. Then they debug blind. Only fifty-two percent of teams have built evaluations. That thirty-seven point gap is where product quality dies. State management is also tricky. If your agent runs twelve steps and step three picks the wrong tool, steps four through twelve are doomed. You need to catch that early.

The key lesson is to choose the right amount of agency. Start with a simple loop. Only add autonomy when the task demands it. Build evaluations before you deploy. That is how you move from a demo to production. The stack has six layers now. Inference, protocols, memory, frameworks, evaluation, and guardrails. Each layer matters, but not all at once. Add them only when something breaks. This is the smart way to build in two thousand twenty-six.

A Capability definition with on-demand loading from Pydantic AI v2.

python
class Capability:
    def __init__(self, id, description, instructions, toolset, defer_loading=True):
        self.id = id
        self.description = description
        self.instructions = instructions
        self.toolset = toolset
        self.defer_loading = defer_loading


# then loads the whole bundle when it decides to.
In plain words

Imagine you are cooking a meal. The simplest approach is to read the oven temperature once and walk away—that is a single action with no feedback. But a good cook tastes, adds salt, tastes again, and adjusts until the dish is perfect. That loop of tasting, adjusting, and tasting is exactly how modern AI agents work: they think, take an action, observe the result, and repeat until the task is done. That loop is the basic building block of everything.

Now picture the cook’s skill progressing from that single reading to a full recipe. At the simplest level, the agent makes just one call to the model—like checking the temperature once. Next, it follows a chain of steps, each building on the last, like following a recipe in order. Then a router lets the model choose which step to do next based on the situation—like deciding whether to sauté or boil depending on the ingredient. After that, a state machine combines that decision-making with a loop, so the agent can cycle through steps any number of times, just like tasting and adjusting repeatedly. The source calls these levels “single LLM call,” “chain,” “router,” and “state machine.” At the highest level, an autonomous agent removes all predefined guardrails—the cook no longer follows any recipe at all but invents new techniques and tools on the fly.

The trickiest point is the jump from state machine to autonomous agent. With a state machine, the possible actions and allowed flows are still constrained—you can only choose from a limited set of steps, like only being allowed to add salt or pepper. An autonomous agent can change its own instructions, add new tools, and redefine what actions are available. The source says guardrails are removed, and “the system itself starts to decide which steps are available to take.” Without this loop—without the ability to taste, adjust, and loop again—the agent would never correct its mistakes. It would be like a cook who sets the timer and walks away, coming back to a burnt meal with no chance to fix it. The loop gives the agent the power to learn from each outcome and keep going until the job is done right.

System design

The subsystem is the state machine cognitive architecture, where a router is combined with a loop to form the atomic unit of agent execution. The ordered mechanism begins with the LLM acting as a router, selecting the next action from a constrained set. After the action, the system enters a loop: it observes the result, feeds it back into the model, and repeats the routing step. This loop can theoretically invoke an unlimited number of LLM calls. On failure—for example, an action produces an error or the agent reaches a dead end—the loop does not terminate; instead, the model’s local reasoning over its growing context may cause the plan’s influence to diminish, leading the agent to diverge from the intended Standard plan (e.g., the NRPV workflow of Navigation, Reproduction, Patch, Validation). The invariant this design preserves is that “there are still constraints on which actions can be taken and what flows are executed after that action is taken.” These guardrails ensure predictable boundaries on the agent’s behavior, preventing it from arbitrarily updating its own prompts, tools, or code.

The key trade-off is selecting a state machine over an autonomous agent, which removes all guardrails. The state machine is built this way because it provides a “low-level, highly controllable orchestration framework” (exemplified by LangGraph) that makes experimentation and customization feasible while retaining reliability in production. The obvious alternative it rejects is the autonomous agent architecture, where the system decides its own available steps and instructions. That rejection avoids the cost of unpredictability and debugging difficulty: “Two agents passing context to each other is already hard to debug. Five is impossible without trace-level evals on every handoff.” By keeping constraints, the state machine limits the blast radius of routing errors and keeps the loop’s behavior analyzable through metrics like Plan Phase Compliance, Plan Order Compliance, and Plan Phase Fidelity.

A concrete failure mode is a forgetting failure—the agent forgets the instructed plan as the trajectory grows, leading to non‑compliance. The operator would see that the agent’s actions no longer align with the Standard plan; for instance, the phase flow analysis shows that DeepSeek-V3 and DeepSeek-R1 “largely reduce their trajectories to NP patterns, skipping Reproduction or Validation.” The signal is a measurable drop in Plan Phase Compliance and a corresponding drop in task success rate, especially on Medium difficulty instances. This failure is not a recall failure (the agent can still retrieve facts) but a forgetting failure in the mutation path, consistent with the finding that “production failures are predominantly forgetting failures rather than recall failures.” The operator would observe that the agent’s trajectory no longer follows the prescribed phases, quantified by the compliance metrics, and would need to reinforce the plan or adjust the loop’s mutation-time hooks to recover.

Interview Q&A

Q – What are the five levels of cognitive architecture for LLM applications, from simplest to most autonomous?
A – The source lists five levels: a single LLM call (simple chatbot), a chain of LLM calls that break a problem into steps, a router where the model chooses actions, a state machine that combines a router with a loop (allowing an unlimited number of calls), and finally an autonomous agent where all guardrails are removed and the system itself decides available steps and instructions.
Follow-up – Which level removes all constraints on which actions can be taken? The autonomous agent level.
Weak answer misses – The distinction that a state machine still has constraints on which actions can be taken and what flows follow, unlike an autonomous agent.

Q – You chose a state machine over a simple chain for our debugging agent. Why that way and not the more straightforward chain?
A – A chain is deterministic — you know all steps ahead of time — whereas a state machine combines a router with a loop, introducing unpredictability and the ability to invoke an unlimited number of LLM calls. For debugging, the system needs to explore multiple fix attempts, iterate, and adapt, which the loop and router provide; a chain would lock it into a fixed sequence that cannot react to new errors.
Follow-up – But wouldn’t an autonomous agent be even more flexible? The source notes that with autonomous agents “those guardrails are removed,” meaning the system could change its own prompts, tools, or code, which for a debugging agent might risk instability and loss of control.
Weak answer misses – The concrete identifiers “router” and “loop” as the two components that make a state machine distinct from a chain.

Q – Our team is torn between using LangChain’s off‑the‑shelf chains and LangGraph’s low‑level orchestration. How does the source characterize the trade‑off?
A – The source explains that early LangChain focused on easy‑to‑use, off‑the‑shelf chains, which were “great for getting started but tough to customize and experiment with.” LangGraph and LCEL are “low‑level, highly controllable orchestration frameworks” that allow frequent experimentation with different cognitive architectures—something the space now demands as it matures.
Follow-up – What concrete orchestration tools did the authors pour most of their development effort into over the past year? LangGraph and LCEL.
Weak answer misses – The explicit naming of “LCEL” and “LangGraph” as the newer, more controllable frameworks.

Q – Walk me through how a router differs from a state machine, and why that difference matters for an agent that must retry failed steps.
A – In a router the model decides which single action to take but there is no loop; after that action the system stops or moves on. A state machine adds a loop around the router, so the system can call the LLM repeatedly, branching and retrying as needed. For retries, the loop is essential because it allows the agent to observe the outcome, re‑route, and invoke additional LLM calls until the task finishes.
Follow-up – Without the loop, what happens if the router’s chosen action fails? The system has no mechanism to reroute; it simply continues to the next predetermined step or ends.
Weak answer misses – The exact phrase “combining the router with a loop” as the critical design element that enables unlimited iterative correction.

Failure modes

Plan Deviation Failure

  • Trigger — The agent’s iterative reasoning–action–observation cycle conditions decisions locally instead of on the initial instructed plan, causing it to “begins with reproduction before properly navigating the codebase” and leading to “repeated modifications to the reproduction script … and a failed edit.”
  • Guard — None. The source describes only evaluation metrics (PCPC, PPF) that measure compliance after the fact; no runtime exception handler, retry, or fallback is identified for plan deviation.
  • Posture — fail‑soft. Trajectories become inefficient or fail, but the agent does not abort the run; some instances still complete successfully (Finding 7, 9).
  • Operator signal — A low PCPC score (“Low compliance in any dimension proportionally reduces the overall score”) or observation of missing/spurious phases in the trajectory.
  • Recovery — Manual analysis of the Langutory trace and re‑running with explicit plan reinforcement.

Premature Convergence Failure

  • Trigger — Removal of the standard plan (No Plan setting) causes reasoning to become “less focused, often resulting in premature convergence” — the agent stops too early without proper navigation, reproduction, or validation.
  • Guard — None. The source does not provide a guard for convergence quality; it only reports the effect (“success rate drops … premature convergence”).
  • Posture — fail‑soft. The agent still resolves some instances (Finding 7 reports exclusive resolutions under No Plan), but overall performance drops.
  • Operator signal — Smaller “Graphectory metric values” compared to the Standard plan setting, and a reduced success rate.
  • Recovery — Re‑run with the standard plan injected; no automatic retry mechanism is described.

Unauthorized Tool Call Failure

  • Trigger — The agent executes a tool call (e.g., sending an email) before guardrails can filter or authorize it. The source states “By the time you filter the response, the agent already sent the email.”
  • Guard — None specific. The source mentions the “guardrails before action” pattern and “NeMo Guardrails” as a framework, but no named function, variable, or except clause from the source implements a runtime guard for tool authorization.
  • Posture — fail‑hard. The action is already taken (email sent, money spent) and cannot be undone by the agent.
  • Operator signal — Observation of an unauthorized tool execution in the agent’s logs; the action succeeded even though it should have been blocked.
  • Recovery — Manual rollback (e.g., recall the email, reverse the tool action). No automated recovery is provided in the source.

Reproduction Test Phase Failure

  • Trigger — Under the Standard plan, the agent “cannot generate a good reproduction test when instructed.” This leads to missing the reproduction phase entirely.
  • Guard — None. The source notes that agents “can fix previously unresolved issues under reduced plan settings” specifically because the reproduction phase was missing; no guard enforces reproduction test quality.
  • Posture — fail‑soft. The agent may still patch the issue without a reproduction test, but the trajectory is incomplete, and some instances are only resolved when reproduction is omitted.
  • Operator signal — The trajectory lacks a reproduction phase (i.e., zero presence in the phase flow analysis).
  • Recovery — Manual generation of a reproduction test; the agent does not retry or fallback automatically.
STUDY AIDSevidence-backed memory techniques
Recall check

What does the section say remains a key gap for agentic systems?

Show answer

reliability remains a key gap

02. Levels Of Autonomy

Autonomy in AI systems is a graded scale. A single call to a large language model is one level. Next is a chain of calls, where each step handles a different part of the task. After that, a router lets the model decide which action to take. Then a state machine combines a router with a loop, so the system can repeat steps as needed. Finally, an autonomous agent chooses its own actions and can even update its own tools and instructions. These are not better or worse. They serve different purposes for different tasks. You pick the level that matches the problem. If the task is simple, you do not need extra complexity. If the task requires more freedom, you climb to a higher level.

By mid-2026, reasoning models changed how this works. They can accomplish in a single call what used to require multiple steps. This means you can tune the level of thinking per request. A single-call agent can now replace an entire chain. That makes autonomy more like an adjustable dial. You choose how much reasoning power to apply each time. The cognitive architecture you choose determines how much control the model has over the flow. You add complexity only when something specific breaks, not ahead of time. This keeps your system lean and focused on what actually works.

Autonomy levels from a single call to an autonomous agent.

python

levels = [
    "single LLM call",
    "chain of LLM calls",
    "router",
    "state machine",
    "autonomous agent"
]
In plain words

Imagine a post office that starts by sorting a single letter, then moves to sorting batches step by step, then lets the sorter decide which bin each envelope goes into, then loops through all the mail until finished, and finally allows the sorter to invent new bins or change the sorting rules on the fly. This is a picture of autonomy levels in AI—a graded scale from the simplest single instruction to a fully self‑directed agent. You pick the level that matches the problem so you don’t waste resources or cause chaos.

At the bottom, you have a single LLM call, like giving the post office one address. The next level is a chain of calls, where each step handles a different part of the task—like sorting a letter, then stamping it, then bagging it. After that comes a router: the LLM decides which action to take next, adding a bit of randomness. A state machine combines a router with a loop, so the system can repeat steps indefinitely—the sorter keeps going until all mail is processed, but the bins are still fixed. The top level is an autonomous agent, which can even update its own tools, instructions, and prompts—the sorter redesigns the sorting room itself.

The trickiest leap is from state machine to autonomous agent. In a state machine, guardrails still limit which actions are possible and what flows follow. Removing those guardrails means the agent can change which steps are available and how they work—for example, altering its own code or tool descriptions. Without these levels as a design choice, you risk either over‑engineering a simple task (costing time and money) or giving an agent too much freedom on a critical job, leading to unpredictable failures that a beginner would feel as confusing errors or runaway loops.

System design

The subsystem described in this chapter implements a graded scale of cognitive architectures, ordered by increasing autonomy. The mechanism begins with a single LLM call, suitable for simple tasks like basic chatbots. When that proves insufficient, the designer moves to a chain of LLM calls, where each call handles a distinct step or serves a different purpose—common in complex RAG pipelines. On failure of that level, the next step is to introduce a router, where the LLM decides which action to take, adding unpredictability. If further capability is needed, the designer adopts a state machine, combining a router with a loop to allow an unlimited number of LLM calls in theory. Finally, when all prior levels fail, the system escalates to an autonomous agent, which removes all guardrails and lets the system decide which steps are available and update its own prompts, tools, or code.

The design preserves an invariant of bounded autonomy: each level enforces a specific set of constraints on what actions and flows are permissible. Up to the state machine level, “there are still constraints on which actions can be taken and what flows are executed after that action is taken.” At the autonomous agent level, “those guardrails are removed.” This invariant ensures that simpler tasks remain predictable and governed by a fixed execution plan, while higher levels sacrifice those constraints for adaptability.

The key trade‑off is between predictability and adaptability. The obvious alternative rejected is to always deploy the highest autonomy level—the autonomous agent—for every task. That choice would introduce unnecessary unpredictability, cost, and risk, because the system “could (in theory) invoke an unlimited number of LLM calls” and may update its own code. By rejecting this alternative for simple tasks, the design avoids the cost of unbounded resource consumption and the overhead of validating self‑modifying behavior. Instead, the developer “picks the level that matches the problem,” matching complexity to need.

A concrete failure mode occurs at the state machine level: the system enters an infinite loop, generating an unbounded sequence of LLM calls. The operator would see a growing count of invocations, ever‑increasing latency, and ballooning API costs—without any natural termination signal. Because the state machine lacks the guardrails of lower levels, this runaway behavior is possible and must be externally interrupted. The source notes that such a loop is “theoretically” possible, and in practice the operator’s signal is a monotonic rise in call count and duration beyond any expected bound.

Interview Q&A

Q – What are the five levels of autonomy described in this architecture, and how would you characterize the progression between them?

A – The levels are a single LLM call, a chain of LLM calls, a router, a state machine, and an autonomous agent. Progression adds more unpredictability: in the router the model chooses among actions unknown ahead of time, and in the state machine that routing is combined with a loop that can invoke an unlimited number of calls. The source calls these levels a “graded scale” and states that none is strictly better—each suits a different task.

Follow-up – How does a state machine differ from a router in terms of system control?

Answer – A router only lets the LLM decide which action to take, while a state machine adds a loop so the system can repeat steps; the source explicitly says “by combining the router with a loop, the system could (in theory) invoke an unlimited number of LLM calls.”

Weak answer misses – The key detail that a state machine still has constraints on which actions are available (guardrails remain), whereas the next level—autonomous agent—removes those constraints entirely.


Q – Why did the LangChain team shift their framework design from off-the-shelf chains to low-level orchestration frameworks like LCEL and LangGraph?

A – Early off-the-shelf chains were “great for getting started but tough to customize and experiment with.” As the space matured, the team found that developers needed “low-level, highly controllable orchestration frameworks (LCEL and LangGraph)” to experiment with cognitive architectures as frequently as they experiment with prompts. This was a deliberate departure from early LangChain’s focus.

Follow-up – What specific limitation of a fixed chain of LLM calls does the state machine level overcome?

Answer – A fixed chain has a predetermined sequence; a state machine combines a router with a loop, letting the system decide and repeat steps on the fly, which the source describes as “even more unpredictable” because the sequence is not known in advance.

Weak answer misses – The source notes that the shift happened because “everyone was just trying to get started” initially, but later the design “pretty quickly hit its limits” when customization became critical.


Q – For a simple chatbot, the source says it “likely falls into” the single LLM call level. Why that level and not the more capable autonomous agent?

A – The single LLM call level is chosen because the task is simple: “a single LLM call makes up the majority of the application.” The source emphasizes that these levels are not “better” than others—they have different purposes. Using an autonomous agent would introduce unnecessary randomness and unpredictability without any benefit for a straightforward Q&A bot.

Follow-up – What happens if you deploy a state machine or autonomous agent for a task that only needs a single LLM call?

Answer – The system becomes harder to debug and control; the source states that with routers and loops, “there is a bit more randomness and unpredictability” that is not needed for simple tasks.

Weak answer misses – The source explicitly categorizes simple chatbots as falling into the first level, meaning the choice is driven by task complexity, not by capability ceiling.


Q – The autonomous agent level allows the system to “update the prompts, tools, or code used to power the system.” Why would a designer ever choose a state machine instead, given that the state machine still has guardrails?

A – A state machine is chosen when you need a loop and routing but still want to constrain which actions are possible and what flows execute after each action. The source says that in autonomous agents “those guardrails are removed.” For tasks where safety or determinism matter—e.g., a refund workflow requiring human approval—you want the constraints of a state machine, not full autonomy.

Follow-up – Under what condition could an autonomous agent become dangerous compared to a state machine?

Answer – Because the agent can change its own instructions, it might diverge from intended behavior; the source notes that guardrails are removed, meaning the system “itself starts to decide which steps are available to take and what the instructions are.”

Weak answer misses – The source also points out that none of these architectures are “strictly better”; the autonomous agent is one end of a spectrum, not the universal endpoint.

Failure modes

1. Plan Phase Order Violation

  • Trigger — The agent executes phases (e.g., reproduction, patching, validation) in a sequence that violates the logical ordering defined by the Standard plan, such as reproducing before navigating the codebase.
  • Guard — None in source. The compliance metric PCPC (geometric mean of PPF, PPC, and PPO) detects violations but does not handle them; it only scores the trajectory after the fact.
  • Posture — Fail‑soft. The agent continues execution despite the ordering error, but the trajectory becomes inefficient and may ultimately fail (e.g., repeated modifications to the reproduction script, failed edit at step 8).
  • Operator signal — Reduced PCPC score; the phase flow analysis (Figure 4) would show a non‑Standard sequence (e.g., NRPV broken or missing phases).
  • Recovery — No automatic retry. The operator must inspect the trajectory log and manually re‑run the instance with a corrected plan prompt, or re‑inject the plan via the plan reminder setting (periodic re‑injection of the default plan into the agent’s prompt) as studied in RQ5.

2. Plan Phase Omission (Missing Reproduction or Validation)

  • Trigger — The agent skips the reproduction test generation phase (most common) or the validation phase, either because the plan instruction is removed (No‑Plan setting) or because the model overfits to certain actions (e.g., DeepSeek‑R1 reduces trajectories to NP patterns, skipping Reproduction and Validation).
  • Guard — None in source. The PCPC metric’s component PPC (phase presence compliance) would be <1, but no handler prevents the omission.
  • Posture — Fail‑soft. The agent continues, often converging prematurely (smaller Graphectory metric values under No‑Plan), but success rate drops (Finding 6).
  • Operator signal — Lower PCPC and drop in resolved‑instance count; phase flow analysis (Figure 6) shows absence of R or V phases.
  • Recovery — None automatic. Manually revert to the Standard‑plan prompt or, for the developer, re‑engineer the agent’s system prompt to re‑insert the missing phases. The “plan reminder” setting can mitigate but does not recover an already‑omitted phase mid‑trajectory.

3. Spurious Phase Inclusion (Unknown Actions Outside the Plan)

  • Trigger — The agent executes actions that are not part of the instructed plan phases (e.g., opening a pull request after patch validation), introducing “gibberish” letters in the Langutory (the trace of described phases).
  • Guard — The PPF (plan phase fidelity) metric penalizes any phase outside the defined set Φ. However, it only scores the trajectory afterward; there is no runtime guard that rejects spurious actions.
  • Posture — Fail‑soft. The agent continues, but the extra actions can be distracting and may lead to task failure (e.g., premature submission or unintended side‑effects). PCPC drops proportionally.
  • Operator signalPPF < 1; the Langutory contains unknown letters; logs show actions not mapped to any expected phase.
  • Recovery — No automatic rollback. The operator must manually correct the trajectory or enforce a stricter action space (e.g., by restricting allowed tool calls in the scaffold).

4. Forgetting Failure: Canonicalization / Intent‑Aware Deletion

  • Trigger — The agent’s memory pipeline fails to forget a previously stored fact correctly. For example, identifier‑obfuscation (canonicalization) fails at 5% accuracy, or prefix‑collision/compound‑fact deletion (intent‑aware deletion) fails at 0% when the LLM is only invoked at inscribe time.
  • Guard — The ForgetEval suite includes a 385‑case adversarial layer and a deterministic substring‑match scoring function, but these are evaluation tools, not runtime guards. The source describes three placement regimes (deterministic, inscribe‑time LLM, mutation‑time hook) that recover from failures (e.g., mutation‑time hook recovers intent‑aware deletion 78‑85%), but it does not name an explicit exception‑handler or retry function.
  • Posture — Fail‑hard (for the specific memory operation that fails). The system cannot canonicalize or delete the intended fact; the stale or incorrect fact persists, causing downstream failures.
  • Operator signal — Substring‑match failure in ForgetEval scores; overall ForgetEval score drops (from 91.7‑93.2% to 5‑0% for specific categories); the operator would observe the forgotten fact still present in subsequent agent calls.
  • Recovery — Manual intervention: re‑run the memory‑mutation operation with a different placement (e.g., switch from inscribe‑time to mutation‑time hook). No automatic retry is specified in the source.

5. Unauthorized Tool Execution (Guardrail Failure)

  • Trigger — The agent makes a tool call (e.g., sending an email, spending money) without prior authorization at the tool‑execution layer, because guardrails are only applied at the output layer or are absent entirely.
  • Guard — None in source. The context states “You’re writing policy code from scratch” and “deployment is still DIY”. The “guardrails before action” pattern is discussed as an emerging practice, but no specific function, variable, or except clause is given.
  • Posture — Fail‑soft (in the worst sense: the action already occurred). The agent continues, but the unauthorized action has taken place (e.g., the email is sent). The PCPC or other metrics do not capture this.
  • Operator signal — Silent until production users report the failure; no log line from the guard framework because none exists. The operator might observe unexpected tool‑use in trace logs.
  • Recovery — Manual rollback (e.g., delete the sent email, reverse the money transfer). No automatic retry or fallback is provided. The operator must write and deploy a policy rule to prevent recurrence.

6. Inability to Follow an Augmented Plan (Regression‑Test or Change‑Summary Phases)

  • Trigger — The agent receives a plan that includes extra phases beyond the Standard plan, such as regression‑test execution at the beginning and end (R_G and V_G) or a change‑summarization phase (S) before submission. DeepSeek‑V3 shows a high performance drop and low PCPC in this setting (Finding, RQ4).
  • Guard — None. The PCPC metric again only detects the deviation after the fact. The agent continues, but cannot incorporate the new phases.
  • Posture — Fail‑soft. The agent either ignores the extra phases or executes them incorrectly, leading to reduced success rate (e.g., DeepSeek‑V3’s drop). For Devstral‑small and GPT‑5 mini, the drop is minimal but still present.
  • Operator signal — Low PCPC, and phase flow analysis (Figure 10) shows that the agent does not place the new phases correctly (e.g., DeepSeek models skip them).
  • Recovery — No automatic recovery. The operator must modify the plan to remove the extra phases or manually adjust the agent’s reasoning to accommodate them. A plan‑reminder setting may help but does not guarantee compliance.
STUDY AIDSevidence-backed memory techniques
Cloze

The highest rung is a  ____ , and it requires  ____ .

Show answer

fully autonomous agent, metacognitive calibration

03. Planning And Reasoning

Agents solve coding tasks by following a plan. The plan breaks the work into clear phases. Those phases are navigation, reproduction, patching, and validation. An agent starts by reading the codebase. Then it tries to reproduce the bug. Next it writes a patch. Finally it validates the fix. The agent works in cycles of reasoning, action, and observation. Each step depends on what it just saw. This is different from simply executing a fixed script. The plan guides the agent, but the agent does not always stick to it.

There is a measured gap between the given plan and what the agent actually does. Some agents skip the reproduction phase. Others add extra steps like running regression tests. The plan following score checks how well the agent stays within the expected phases. This score is a combination of missing phases, extra phases, and out of order actions. A perfect score means every phase matches the plan. Lower scores mean the agent drifted away.

When agents do not receive a plan, they often still follow a similar structure. That happens because the underlying large language model has learned this pattern during training. Different models internalize the plan in different ways. Some models skip reproduction more often. Others try to follow every phase. The variation affects how many issues they fix.

An explicit upfront plan can beat a purely reactive loop. Without it, reasoning becomes less focused. Performance drops, especially on medium difficulty tasks. But the plan can also cause problems. A bad reproduction test leads to repeated failures. In those cases, removing the plan lets the agent skip that phase and succeed. So the trade off is real.

The response to the plan following gap includes several changes. One approach is to remind the agent of the plan every few steps. This periodic reminder keeps the agent on track. It reduces drifting into unrelated tasks. Another approach is to reorder the phases. Delaying a weak phase can reduce interference. But this does not always help. Some models benefit more from reminders than from reordering.

The studies also compare different benchmarks. On a more challenging benchmark, plan compliance drops by about thirteen percent. The agents still struggle with reproduction. They spend more time on navigation and patching. They rarely reach validation. This shows that the plan following gap depends on the task difficulty.

Overall, agents plan by breaking a task into phases. They reason step by step, guided by the plan. But they do not always follow it perfectly. The measured gap leads to adjustments like reminders and phase reordering. These adjustments help, but no single fix works for all models. The best approach depends on how the model internalizes the problem solving process.

Geometric mean of plan compliance sub-metrics.

python
def plan_compliance(PPF, PPC, POC):
    return (PPF * PPC * POC) ** (1/3)
In plain words

Imagine following a recipe to bake a cake, but instead of sticking to the steps, you taste the batter, then start baking, then realize you forgot to preheat the oven. That’s what this system is about—it checks whether a software-fixing agent actually follows the recipe it was given. The plan breaks the fix into clear phases: first navigate the code to find the suspected bug, then reproduce the bug to confirm it, then write a patch, and finally validate that the patch works. The agent works in cycles of thinking, acting, and observing, making each next move based on what it just saw rather than a fixed script.

The agent’s actual path is captured in a sequence called a “Langutory”—the real steps it takes, phase by phase. The system then compares that sequence to the intended plan using a metric called PPF (Plan Phase Fidelity), which penalizes missing a phase, adding an extra phase, or doing phases in the wrong order. For example, if the agent starts reproducing the bug before navigating the code, PPF marks that as a violation. The compliance score is a geometric mean of three sub-metrics, ensuring that a single mistake (like skipping navigation) cannot be hidden by doing other steps perfectly.

The non-obvious catch is that the plan is only advisory—it lives in the agent’s instructions but is never enforced by the framework. As the agent’s conversation fills with error messages and file dumps, the plan’s influence fades because the agent focuses on what it just read, not the original recipe. Without this compliance check, an agent might waste effort repeatedly tweaking a reproduction script (steps 3–4 in the recipe) before ever understanding the codebase, leading to a failed edit and a broken fix—exactly the kind of inefficient, wasted time a beginner would feel when they realize they baked the cake without preheating the oven.

System design

In the planning and reasoning subsystem for coding agents, the ordered mechanism begins by embedding a recommended plan—comprising four phases: navigation, reproduction, patching, and validation—directly into the system prompt. The agent then operates in iterative reasoning–action–observation cycles, where each decision is locally conditioned on the current context rather than the initial instructed plan. No enforcement mechanism exists in the scaffold; the plan is purely advisory. Compliance is measured only after execution using the PC (Plan Compliance) score, which is the geometric mean of three component metrics: PPC (Plan Phase Compliance, detecting missing or spurious phases), POC (Plan Order Compliance, penalizing violations of the logical phase ordering), and PPF (Plan Phase Fidelity, penalizing phases outside the specified set Φ). The evaluation pipeline checks the agent’s trajectory—represented as a Langutory of observed phases—against these mathematically defined dimensions.

The invariant the design preserves is that the plan remains a logical phase sequence that serves as a reference for process-centric evaluation, but the system provides no guarantee of adherence. The guarantee is instead a quantified compliance measurement: the PC score reflects deviations across all three dimensions, with low compliance in any one proportionally reducing the overall score. This rejects an alternative where the scaffold enforces the plan at runtime, e.g. by blocking actions that violate phase order or by re-injecting the plan as a hard constraint. The cost avoided by rejecting enforcement is the design complexity of building a mandatory execution governor and the potential rigidity that could prevent agents from discovering valid but unanticipated solution paths (e.g. opening a pull request after validation, which is outside the instructed plan but not necessarily harmful). Instead, the system accepts that plan drift may occur and measures it transparently.

A concrete failure mode is the reproduction-first violation, where the agent begins with reproduction before properly navigating the codebase. As documented in the source (Figure 1b), this leads to repeated modifications to the reproduction script (steps 3–4) and a failed edit at step 8. An operator would observe this signal through the POC component of the PC score: because the Langutory shows a reproduction phase preceding navigation, the order compliance metric falls below 1, and the geometric mean PC score similarly declines. The operator sees a numeric drop (e.g. PC = 0.85 instead of 1.0) and can inspect the Langutory to identify the ordering deviation. This failure mode is characteristic of agents that overfit to certain action sequences or lose plan awareness as the context grows, consistent with the known limitation of LLMs in attending to earlier context.

Interview Q&A

Q – What are the four phases of the standard plan that guides the agent during code-fixing tasks?
A – The standard plan decomposes the task into four sequential phases: Navigation, Reproduction, Patching, and Validation. This structure, often encoded in the system prompt, instructs the agent to first locate the potential bug location, then reproduce the bug, next patch the code, and finally validate the fix. The plan is advisory, not enforced, so the agent’s actual trajectory may deviate.
Follow-up – How does the agent decide which phase to execute at each step if the plan is not enforced?
The agent performs local reasoning over its current context at each step, and its actions may or may not align with the plan; there is no mechanical enforcement mechanism.
Weak answer misses – The agent’s reasoning is reactive to its context (e.g., error messages, file contents), and the plan’s influence can diminish as the trajectory grows, consistent with known attention limitations.

Q – How is plan compliance measured to capture the gap between the instructed plan and the agent’s actual behavior?
A – Compliance is evaluated along three mathematically defined dimensions: Plan Phase Compliance (PPC), Plan Order Compliance (POC), and Plan Phase Fidelity. These are combined into a composite PCPC score that reflects whether the agent executes the correct phases, maintains the proper logical ordering, and avoids spurious or missing phases.
Follow-up – What does a low PCPC score specifically indicate about the agent’s trajectory?
Low PCPC scores reflect deviations such as missing phases, spurious phases, or violations of the intended phase ordering.
Weak answer misses – The metric is process-centric, not just outcome-based; it distinguishes correct strategic reasoning from benchmark overfitting.

Q – Under the no-plan setting, agents still show partial adherence to the standard plan. Why does removing the plan consistently reduce success rates?
A – Finding 5 shows that even without explicit plan instructions, models like Devstral-small and GPT-5 mini internalize the standard plan (e.g., following an NRPV pattern) due to training, while DeepSeek models collapse to NP patterns. Finding 6 demonstrates that removing the plan drops performance across all models because the plan positively focuses local reasoning; without it, reasoning becomes less focused, leading to premature convergence and lower Graphectory metric values.
Follow-up – Which models show the most dramatic performance drop when the plan is removed, and why is that surprising?
DeepSeek-R1 shows the largest drop despite exhibiting lower compliance when the plan is present, indicating the plan still aids local reasoning even when not strictly followed.
Weak answer misses – Different models internalize problem-solving differently; DeepSeek’s drop is partially due to its tendency to skip Reproduction and Validation phases without the plan.

Q – Why does the system use an advisory plan in the system prompt rather than mechanically enforcing the phase sequence?
A – The SWE-agent scaffold provides no enforcement mechanism; the plan is only included in the system prompt. The design relies on the agent’s local reasoning to follow the plan, but because the agent’s context grows with each step, the plan’s influence can diminish (as noted in the introduction). Moreover, Finding 7 shows that agents under the no-plan setting sometimes fix issues they could not under the default plan—often because the reproduction phase, when enforced, generates incorrect tests that lead to failure cycles.
Follow-up – What does the no-plan success on previously unresolved instances imply about the plan’s design?
The plan can be counterproductive when the agent’s reproduction test generation is poor; skipping that phase allows the agent to patch correctly, though data contamination may also play a role.
Weak answer misses – The standard plan instructs the model to reproduce the bug before patching, but test generation is a complex non-trivial problem, and incorrect tests can cause repeated patch-test failure cycles.

Failure modes

Reproduction Test Generation Failure

  • Trigger — The agent follows the Standard plan and attempts to generate a reproduction test before patching. The model produces an incorrect test, leading to a cycle of patch-test failures without success.
  • Guard — No guard exists in the source. The agent has no exception handler, retry, or fallback for an incorrect reproduction test; it simply repeats the patch-test cycle.
  • Posture — fail-soft. The agent continues to iterate but never succeeds on that instance, eventually running out of steps or context. The failure does not abort the overall run.
  • Operator signal — “repeated patch-test failure cycles without success”.
  • Recovery — No automatic recovery. The operator must remove the reproduction phase (i.e., switch to the No Plan setting) to allow the agent to skip test generation and proceed directly to patching.

Plan Phase Non-Compliance (Missing or Spurious Phases)

  • Trigger — The agent’s training or internal strategy causes it to omit phases (e.g., skipping Reproduction or Validation) or to insert phases outside the specified plan alphabet (Φ). This is observed even when the Standard plan is explicitly provided.
  • Guard — No runtime guard corrects the deviation. The P_C metric (geometric mean of P_P_C, P_O_C, P_P_F) measures compliance after the fact but does not enforce it.
  • Posture — fail-soft. The agent continues, but the success rate drops because missing phases lead to inefficient or incomplete patches.
  • Operator signal — “Lower P_C scores reflect deviations in missing phases, spurious phases, or violations of the logical phase ordering”. Also a visible drop in the success rate (e.g., “the majority of the instances that SWE-agent resolved only under the Standard plan setting are of Medium difficulty”).
  • Recovery — No automatic recovery. The operator may need to reinforce the plan through periodic re-injection (the Plan Reminder setting) or retrain the model.

Non-Deterministic Outcome Variation

  • Trigger — Inherent nondeterminism in LLM-based agents causes the same problem to be resolved under one plan setting but not under another, even when the plan is the only difference. For instance, “4, 7, 16, and 4 instances deterministically only resolved under the no-plan setting”.
  • Guard — No guard exists. The source notes nondeterminism as an inherent property; no retry, fallback, or validation handles it.
  • Posture — fail-soft. The agent produces a correct solution in some runs and fails in others; the system does not abort.
  • Operator signal — Inconsistent results across runs for the same instance and plan. The “Graphectory metric” changes (e.g., smaller under No Plan) but is not a direct operator signal.
  • Recovery — No automatic recovery. The operator must run multiple trials or accept the probabilistic outcome.

Persistent Tool-Calling Errors (DeepSeek-R1)

  • Trigger — DeepSeek-R1 attempts to call tools during its reasoning-action-observation cycles but repeatedly fails with tool-calling errors. This is seen under the Standard plan and becomes pervasive when regression test phases are added.
  • Guard — No guard is provided. The source reports “persistent tool-calling errors” and “pervasive tool-calling failures observed in 413 instances”.
  • Posture — fail-hard. The agent cannot proceed with tool operations, resulting in a very low success rate (the run effectively aborts for that instance).
  • Operator signal — “tool-calling failures observed in 413 instances”.
  • Recovery — No automatic recovery. The operator must switch to a different model or remove the plan phases that trigger the errors.

Performance Degradation from Plan Augmentation

  • Trigger — Adding an unfamiliar phase (e.g., regression test execution at the beginning and end, or a change summary phase) that is not aligned with the model’s internal strategy. DeepSeek-V3 and DeepSeek-R1 show a notable drop in success rate, while Devstral-small and GPT-5 mini are minimally affected.
  • Guard — No guard. The P_P_C and P_O_C metrics detect low compliance (e.g., “low P_P_C suggesting difficulty in incorporating the regression testing phases”), but no mechanism prevents the performance drop.
  • Posture — fail-soft for models that continue (DeepSeek-V3), and fail-hard for DeepSeek-R1 due to tool-calling failures. The system does not abort the whole evaluation.
  • Operator signal — “DeepSeek-V3 experiences a higher performance drop, accompanied by low P_P_C”. For DeepSeek-R1, “pervasive tool-calling failures observed in 413 instances”.
  • Recovery — No automatic recovery. The operator must remove the added phases or select a model that already internalizes the required steps (e.g., Devstral-small for regression testing).
STUDY AIDSevidence-backed memory techniques
Quiz

According to the section, what is the relationship between planning ahead through tool design and pure reasoning?

Options: planning ahead through tool design can matter more than pure reasoning · step-by-step reasoning helps avoid costly mistakes · an explicit upfront plan can beat a purely reactive loop · the measured gap between writing a plan and following it remains a challenge

Show answer

planning ahead through tool design can matter more than pure reasoning

04. Self-Healing Systems

Systems that can repair themselves are becoming a reality in large language model agents. They use reflection to look back at their own past actions and mistakes. This self-critique helps them refine their next attempt. For example, a generative agent synthesizes memories into higher level inferences over time. Those inferences guide its future behavior. Retry loops are built into the framework too. A model can try again if a task times out or fails. When all retries are exhausted, a node level error handler can reroute the flow. The handler can update state and direct the agent to a different node. Detecting unreliable output is another key part. Large language models sometimes make formatting errors. They might even refuse to follow an instruction. Knowing when to stop is just as important. Agentic abstention helps an agent decide when further action is pointless. If a goal turns out to be unreachable, the agent should abstain instead of continuing. A method called convolve improves timely abstention. It distills past interactions into reusable stopping rules. But there are trade offs. The same experience that helps an agent learn can also make it less willing to refuse tasks later. Some agents never abstain when they should. Others abstain only after many unnecessary interactions. Mistakes that slip into long term memory can persist through many generations. The memory stream records every observation. Reflection then builds on those observations. So a bad observation can influence future behavior. Self repair is now a shipped feature in recent frameworks. Node level error handlers give developers fine grained control. Per node timeout policies set limits on how long a task can run. Retry chains allow fallback strategies. These tools turn one shot failure into iterative improvement. The agent learns from its mistakes and gets better over time.

Self-score loop for agentic self-improvement using oracle synthesis and validation.

python

O = Synthesize(issue, k)  # ensemble of models
A = {o in O: RunOnBase(o) fails, not timeout, not syntactic self-error}
A = {o in A: SymptomJudge(o) matches issue}  # denoise
# agent debugs with run_tests = self-score over A
def V_self(rho):
    numerator = sum(1 for o in A if rho flips o from fail to pass)
    score = numerator / len(A)
    if any green check regresses:
        score = 0
    return score
In plain words

Imagine a chef tasting soup as they cook, adjusting salt or heat each time something is off—never serving a dish without tasting and fixing it first. That is what a self-healing agent does: it reviews its own past actions and mistakes, then refines the next attempt so it can finish the task even after an error. This system exists to stop agents from giving up or silently breaking when something goes wrong.

The agent first performs an action—like calling a tool or writing to memory—then looks back to check the result. If the outcome is wrong, a retry loop lets it try again, much like a chef adding more salt after tasting. If retries keep failing, a node-level error handler steps in, rerouting the flow like a head chef taking over the stove. This handler can update the agent’s state and point it to a different path. Real mechanisms include a “pending message queue” that steers the run mid-flight and “durable execution” that saves progress so the agent can resume after a crash—both from Pydantic AI’s framework.

The trickiest part is knowing when to stop retrying and hand off. An agent that retries forever wastes time; one that gives up too soon leaves tasks incomplete. The system uses a “defer_loading” flag so self-healing instructions stay out of the prompt until needed, keeping the agent’s focus clear. Also, because “instrumentation” is a built-in capability, the agent can read its own logs to spot contradictions—like two instructions that cancel each other—and suggest a fix. Without this subsystem, the agent would either loop endlessly or fail silently, leaving users with unfinished work and no clue why.

System design

The provided context does not contain any chapter or subsystem titled "Self-Healing Systems." The documents cover forgetting failures in agent memory (ForgetEval), plan-following gaps in SWE agents, safety in self-evolving agent systems, and a selective forgetting framework (FSFM). None of these describe a mechanism involving reflection, retry loops, node-level error handlers, or generative agent memory synthesis as outlined in the query. Therefore, it is not possible to answer the query from the given sources.

Interview Q&A

Q: "The ReAct format is often used in agent loops. How does it enable self-healing behavior in LLM agents?"

  • A: The ReAct format structures each reasoning step into a cycle of Thought, Action, Action Input, and Observation. This explicit progression allows the agent to inspect the result of a tool call (the Observation) and then decide whether to issue a corrective Thought and Action, forming a natural retry loop without external scaffolding.

  • Follow-up: "But what if the agent keeps retrying fruitlessly—how does it know when to stop?"
    A: The agentic abstention problem addresses this; the CONVOLVE method distills full interaction trajectories into reusable stopping rules, improving timely recall from 26.7 to 57.4 on WebShop without parameter updates.

  • Weak answer misses: A shallow answer omits the four‑step cycle (Thought, Action, Action Input, Observation) and treats ReAct as a simple tool call rather than the iterative self‑correction loop it defines.


Q: "Explain how the SEA architecture implements self-repair without retraining the model. Why freeze the base model at all?"

  • A: SEA confines self‑modification to a small steering adapter and a versioned harness around a frozen base model; each modification passes through an anytime‑valid gate that emits an auditable certificate. Self‑repair is one of five verifier‑in‑the‑loop mechanisms that supply dense, grader‑free signal computed from the issue text alone, allowing correction without updating the base model.

  • Follow-up: "What happens when the frozen base cannot produce the needed corrective behavior?"
    A: The anytime‑valid gate can only select among behaviors the frozen base already produces, so if the base lacks the required capability, self‑repair fails—base capability is the dominant, confound‑free effect.

  • Weak answer misses: The key constraint omitted is that the gate only selects, not generates, new behaviors; the system is limited by the frozen base’s pre‑existing competence.


Q: "For handling forgetting failures in agent memory, why would you pick a mutation‑time LLM hook over an obvious alternative like deterministic string operations?"

  • A: Deterministic primitives fail on canonicalization tasks: only 5% on identifier‑obfuscation and 0% on cross‑lingual. A mutation‑time hook recovers intent‑aware deletion (78–85%) and brightens nearly all categories simultaneously (91.7–93.2% overall), despite higher per‑case latency (2.3 s vs 64–191 ms). The recall path remains unchanged, and the trade‑off is justified because production failures are predominantly forgetting failures, not recall failures.

  • Follow-up: "But 2.3 seconds per mutation is still slow—how does that play out at scale?"
    A: The cost is $0.17 per 385‑case adversarial run, and the mutation‑time hook covers failure modes that deterministic and inscribe‑time approaches miss, making the latency acceptable for the coverage gain.

  • Weak answer misses: A shallow answer omits the specific failure categories where deterministic primitives fail: identifier‑obfuscation (5%) and cross‑lingual (0%) canonicalization.


Q: "What makes agentic abstention a self‑healing capability, and how does CONVOLVE improve it without updating model parameters?"

  • A: Agentic abstention is a sequential decision problem where the agent can answer, abstain, or gather more information at each turn, and the need to abstain may only become clear after interacting with the environment. CONVOLVE distills full interaction trajectories into reusable stopping rules, raising Llama‑3.3‑70B’s timely recall rate from 26.7 to 57.4 on WebShop without parameter updates—effectively healing the system’s tendency to over‑commit to impossible tasks.

  • Follow-up: "Does CONVOLVE risk making the agent too conservative, abstaining when it could still succeed?"
    A: CONVOLVE generates rules from successful completions as well, so it learns when to continue; the reported improvement is in timely recall, not just early stopping—it balances the trade‑off.

  • Weak answer misses: The missing detail is that agentic abstention is a sequential problem (not single‑turn), and CONVOLVE leverages the full trajectory, not just the final outcome, to craft stopping rules.

Failure modes

Tool-Calling Failure Cascade

  • Trigger — Persistent tool-calling errors occur when a model (e.g., DeepSeek‑R1) attempts to interact with the execution environment, leading to a very low success rate.
  • Guard — No guard is shown in the source. The system evaluates performance only after the fact with metrics like PCPC and success rate.
  • Posture — Fail‑hard: the trajectory aborts because the agent cannot complete the required tool calls, resulting in a failed task.
  • Operator signal — “persistent tool‑calling errors” observed in 413 instances (for the augmented summary phase) and “very low success rate” overall.
  • Recovery — No retry or fallback is described; the agent does not recover and the run is lost.

Plan Phase Ordering Violation

  • Trigger — The agent begins with reproduction before properly navigating the codebase, violating the logical phase order. This leads to repeated modifications to the reproduction script (steps 3–4) and a failed edit at step 8.
  • Guard — No runtime guard exists. The evaluation metric POC (Plan Order Compliance) measures the violation after the fact, but does not prevent it.
  • Posture — Fail‑soft: the agent continues executing inefficiently, but the deviation degrades performance and often results in task failure.
  • Operator signal — “low POC score” and the observation that the agent “begins with reproduction before properly navigating the codebase.”
  • Recovery — No automated recovery is provided; the operator must re‑run the task with a corrected prompt or manual intervention.

Missing Required Phase (Failure to Generate Reproduction Test)

  • Trigger — Under the Standard plan, the agent is instructed to generate a reproduction test but is unable to do so. This is the primary reason for exclusive resolution under the No Reproduction setting.
  • Guard — No guard is shown. The metric PPC (Plan Phase Compliance) detects the missing phase, but does not trigger any healing action.
  • Posture — Fail‑hard: the agent cannot proceed to later phases because a necessary dependency (reproduction test) is absent, causing the task to fail.
  • Operator signal — “low PPC score” specifically reflecting a missing reproduction phase; the agent’s trajectory shows no successful reproduction.
  • Recovery — No retry or fallback is described; the operator must supply a reproduction test or modify the plan.

Non‑Determinism Masking True Behavior

  • Trigger — Even when validation is removed from the plan, agents sometimes still incorporate a validation phase due to non‑determinism. This obscures whether the agent would have succeeded without it.
  • Guard — No guard exists. The source notes “remaining impact of nondeterminism” after attempting to eliminate it.
  • Posture — Fail‑soft: the agent may succeed or fail unpredictably, making results non‑reproducible and degrading trust in the evaluation.
  • Operator signal — Inconsistent results across runs, described as “remaining impact of nondeterminism” in the analysis of exclusive resolutions.
  • Recovery — No automated recovery; the operator must run multiple trials and average results to compensate.

Plan Overfitting with Added Phases (Regression Test Execution)

  • Trigger — Adding a regression test execution phase early in the trajectory (before navigation) causes DeepSeek‑V3 to experience a higher performance drop, accompanied by low PPC. The phase distracts the agent from bug localization.
  • Guard — No guard is shown. The metric PPC (and its component POC, PPF) flags the low compliance, but does not intervene.
  • Posture — Fail‑soft: the agent’s success rate drops, but it continues executing. The performance degradation is significant, especially for models that do not naturally perform regression testing.
  • Operator signal — “lower PPC score” and “higher performance drop” observed in the augmented plan setting; also “pervasive tool‑calling failures observed in 413 instances” for DeepSeek‑R1.
  • Recovery — No recovery mechanism is described; the operator must revert to the Standard plan or choose a model that copes better.

Short‑Term Reward Optimization Undermining Plan Compliance

  • Trigger — DeepSeek‑R1 exhibits severe performance issues attributed to “optimization for short‑term reward,” a known issue in reinforcement learning. The model prioritizes immediate reward cues over adhering to the instructed plan.
  • Guard — No guard is shown. The evaluation only observes the result (low PCPC, POC, PPF) after completion.
  • Posture — Fail‑soft: the model continues to act but produces trajectories that systematically deviate from the plan, lowering overall compliance.
  • Operator signal — “low PCPC score” and the speculation “due to optimization for short‑term reward.” The agent’s actions reflect a focus on local gains rather than phase‑by‑phase plan following.
  • Recovery — No automated recovery is described; the operator must adjust training or use a different model with better plan adherence.
STUDY AIDSevidence-backed memory techniques
Explain & elaborate · explain why

Explain in your own words why the self-healing system uses a structural validity gate as its main safety mechanism to block unsupported claims and reduce hallucination by more than ninety-three percent?

05. Durable Execution

Durable execution means your program is crash-proof. Its state survives a failure and picks up exactly where it left off. Each step gets recorded in a journal. When the system restarts, it replays those completed steps from the history. It does not redo anything already done.

The core trade-off is that every step must be replayable. If a step does something unpredictable, like calling a large language model or writing a file, you need to wrap it as a durable boundary. The runtime records its input and output. On recovery, it reuses that recorded result instead of running the step again. This is how you avoid sending two emails or creating two pull requests by mistake.

A long-running agent might wait hours for a human to approve an action. It might pause until another service finishes. With durable execution, that wait costs nothing. The system persists the waiting state. When the human responds or the event arrives, the agent resumes from exactly that point. No time limit, no memory leak, no lost approval.

In twenty twenty-six, the industry consolidated around engine-level journaling. Frameworks now stream model output durably as it is generated. Large payloads, like file contents or long tool responses, are stored outside the main journal to keep the log fast and small. Human approvals are parked on durable promises. Those promises survive crashes for months. Even if the server goes down at midnight, the approval is still there in the morning.

The pattern is simple but powerful. You record every meaningful operation. You check the record before acting. You replay the record after a restart. And you design every step so it can be safely repeated. That is how you build agents that run for days, survive failures, and never lose progress.

A durable execution workflow can sleep for days between steps without losing its place.

python
function Notifier(String username) {
    for interval in [1, 7, 30, 60, 90, 180] {
        sleep(Time.days(interval))
        sendNotification(username)
    }
}
In plain words

Imagine you are building a tower out of blocks. Each time you place a block, you snap a photo. If the tower falls, you use the photos to rebuild exactly where you left off—never starting over. That is what durable execution does for computer programs: it makes them crash-proof so they can resume from the last completed step after any failure.

The system works by recording every step in a journal (the photos). When the program runs, each operation, like calling a function or saving data, is logged to a history. If a crash happens, the runtime looks at the journal and replays all completed steps from that history to restore the program’s state. The program does not redo anything already done. The name for this crash-proof unit is a workflow, and the runtime ensures that every step is either deterministic or wrapped so it can be safely replayed.

The trickiest part is handling steps that are unpredictable, like asking a large language model for an answer. That call cannot be replayed because the LLM might give a different response each time. So the programmer marks it as a durable boundary—the runtime records the input sent and the output received. On recovery, instead of calling the LLM again, the runtime reuses the saved output from the journal. Without this, the program would produce inconsistent results after a crash, like rebuilding the tower using different blocks each time. The failure a beginner would feel is a program that behaves differently after restarting, corrupting data or repeating expensive operations.

System design

The durable execution subsystem implements an ordered journaling mechanism. Execution begins by recording each step’s input and output into a durable journal, then proceeding to the next step. On failure, the runtime reads the completed entries from that journal and replays them, skipping any step whose result is already persisted. For example, Restate’s ctx.run durable step marker and Temporal’s Workflow/Activity split both enforce this pattern: the Workflow code records event history, and after a worker crash the Temporal service replays that history to reconstruct state. LangGraph’s checkpointer (conforming to BaseCheckpointSaver) similarly persists graph state at every superstep, so on restart it resumes from the last checkpoint rather than rerunning the entire graph. The ordered sequence is therefore: record, advance, persist, and on failure replay the journal.

The invariant preserved is crash-proof execution – the property that a crash has no consequence for program state. This is guaranteed by the replay boundary: every nondeterministic operation (LLM calls, shell commands, API requests, file writes) must be wrapped as a durable external step whose inputs and outputs are recorded. The journal then decides what may be replayed, skipped, compensated, or resumed. Completed work is never re-executed; the system resumes from the recorded boundary, not from improvisation. This invariant is named in the source as “the node boundary has to be engineered as a replay boundary” (durable-execution-agents.md) and fulfills the promise that “durable execution virtualizes execution” (durable-execution-landscape.md).

The central trade-off is that every step must be made replayable by pushing nondeterministic work into explicit durable boundaries. The rejected alternative is allowing arbitrary code (e.g., LLM calls or random values) directly inside the deterministic workflow logic. That approach would break replay because the result would differ on re-execution, forcing the system to redo unsafe work or guess from logs. The cost avoided is duplicate side effects (e.g., sending the same notification twice) and the improvisation that “recovery becomes improvisation” without durable boundaries. To avoid this cost, platforms enforce a split: Temporal’s Workflow must be deterministic while side effects are isolated as Activities; LangGraph requires wrapping mutating operations inside nodes that are checkpointed; Restate uses ctx.run to journal each step. The refusal to hide the replay problem is explicit: “graph checkpoints are powerful, but they do not automatically make every node safe” (durable-execution-agents.md).

A concrete failure mode is a process crash that occurs after installing a package but before recording the step’s completion in the journal. The operator would see a log entry showing the package install succeeded, followed by a crash, and then upon restart the system attempts to install the same package again (because no checkpoint captured that step). In LangGraph with the "exit" durability mode, the operator would observe that the graph resets to the beginning on restart, because intermediate state is not saved for system crashes. The signal is a double install in the deployment history and potentially an application error from the duplicate operation. With synchronous durability ("sync"), the operator would instead see a clean resume: the journal’s checkpoint is written before the next step starts, so the install is not repeated, and no duplicate side effect appears.

Interview Q&A

Q
“How does durable execution make code crash-proof without preventing crashes?”

A
It virtualizes execution by recording each completed step in a journal. On recovery, the runtime replays that journal and skips work already done, so a crash has no consequence. The context names this mechanism virtualizes execution and states “a crash will have no consequence.”

Follow-up
“If a crash occurs mid-step, how does the runtime know whether the step completed?”
The runtime records completed operations in the journal; any operation not yet recorded is considered unexecuted and will be retried.

Weak answer misses
The shallow answer might say “the runtime saves state,” but it omits the exact journal replay mechanism that distinguishes completed from uncompleted work.


Q
“What are replay boundaries and why are they essential for an agent runtime?”

A
Replay boundaries are operations whose results must be recorded and reused on recovery. The context explicitly lists LLM calls, tool calls, shell commands, external API requests, file writes, human approvals, and outbound messages as replay boundaries; their results “should be recorded and reused on recovery.”

Follow-up
“What happens if you place an LLM call inside deterministic workflow code instead of behind a replay boundary?”
It breaks determinism because the runtime cannot re‑execute the same call and guarantee the same result; the model is nondeterministic.

Weak answer misses
A shallow answer might say “mark nondeterministic code as side‑effects,” but it misses the specific list of replay boundaries and the requirement to reuse recorded results, not just skip re‑execution.


Q
“Why use a separate execution journal rather than persisting chat history for recovery?”

A
A transcript is not a recovery log. The context states “a durable agent needs separate records for identity/memory, conversation, execution, tool receipts, approvals, and observability,” because chat history lacks idempotency keys, receipts, and compensation metadata needed to distinguish intended from completed actions.

Follow-up
“Couldn’t you deduce what happened by replaying the chat history from the last saved message?”
No, because chat history does not record duplicate detection or the exact artifact under review; a retry or human approval might be misapplied.

Weak answer misses
The shallow answer might say “persistence is persistence,” but it omits the need for idempotency keys and compensation metadata that only a dedicated journal provides.


Q
“Why adopt Temporal’s deterministic replay model instead of Restate’s lighter journaling approach?”

A
Deterministic replay forces workflow code to be strictly deterministic, pushing all nondeterministic work into Activities. The context explains that “LLM calls, shell commands, API requests… cannot simply sit inside deterministic workflow logic; they need to be Activities.” Restate’s journaling is lighter but still requires each step to be wrapped and idempotent—the same discipline.

Follow-up
“In practice, what breaks if you skip the Workflow/Activity split and put an LLM call in the workflow code?”
Recovery may produce a different LLM response, leading to inconsistent state or duplicate side effects—exactly the problem durable execution is designed to prevent.

Weak answer misses
A shallow answer might say “both are fine for agents,” but it misses the critical Workflow/Activity split that makes deterministic replay safe.


Q
“How would you prove that an agent runtime truly supports durable execution, not just checkpointing?”

A
Use a recovery test suite that deliberately crashes the runtime at specific points. The context enumerates crash scenarios: “after an LLM response but before the next tool call, after an external API succeeds but before local state is written, after a file write but before the journal receipt, after human approval but before action execution.”

Follow-up
“What is the most subtle failure pattern that a naive test would miss?”
Crashing after an external API succeeds but before local state is written—the operation may appear incomplete, causing a duplicate side effect on recovery.

Weak answer misses
The shallow answer might say “test by crashing the process,” but it omits the exact boundary points in the list, especially the gap between API success and local state persistence.

Failure modes

Non-Deterministic Step Inside Workflow Logic

  • Trigger — A developer places an LLM call, random(), time.Now(), or a file write directly inside deterministic workflow code instead of wrapping it as a durable boundary.
  • Guard — The source does not show a runtime guard that catches this; the mitigation is the Workflow/Activity split (Temporal) or ctx.run-style durable steps (Restate), but those are design rules, not exception handlers.
  • Posture — fail‑hard: the workflow will fail on replay because the recorded event history will not match the re‑executed output, aborting the run.
  • Operator signal — A replay mismatch error, e.g., “WorkflowExecutionNonDeterminismError” (implied by “replays workflow code against that history to reconstruct state”).
  • Recovery — The developer must refactor the offending step into an Activity or ctx.run durable step and re‑deploy; no automatic retry.

Crash Before Journal Commit Causing Duplicate Side Effects

  • Trigger — The worker crashes after executing a step (e.g., sending an email) but before the step’s result is recorded in the journal. On recovery the journal shows the step not yet complete, so the runtime re‑runs the step.
  • Guard — The source explicitly mentions idempotency keys as a built‑in mechanism (Restate) to make re‑execution safe; without them no guard prevents the duplicate.
  • Posture — fail‑soft if the step is idempotent (duplicate is harmless); otherwise fail‑hard (duplicate actions may corrupt external state).
  • Operator signal — Duplicate notifications or write operations appear in logs; the source warns “a retry can send the same notification twice”.
  • Recovery — If idempotency keys are present, re‑execution is skipped; otherwise manual cleanup of the duplicate side effect is required.

Activity Timeout Without Configured Retry

  • Trigger — An Activity (e.g., an external API call) hangs beyond its configured timeout, and no retry policy is attached.
  • Guard — The source lists retries as a first‑class concept (“Timers, signals, retries, task queues”), but if the developer does not set them there is no guard.
  • Posture — fail‑hard: the activity times out and the workflow aborts.
  • Operator signal — A timeout error such as “ActivityTaskTimedOut” (implied by the framework’s event history).
  • Recovery — Manual re‑invocation of the workflow or adjustment of the timeout/retry settings; no automatic retry.

Wall‑Clock Read Inside Deterministic Workflow

  • Trigger — A developer uses time.Now() or similar direct clock read inside the workflow code, making the execution non‑deterministic.
  • Guard — The source specifies that such reads “cannot simply sit inside deterministic workflow logic” and must be replaced with durable timers (Temporal) or equivalent. There is no runtime guard; the system will detect non‑determinism on replay.
  • Posture — fail‑hard: replay fails and the workflow stops.
  • Operator signal — A non‑determinism error identical to the first failure, often logged as “mismatched event history”.
  • Recovery — The developer must replace the wall‑clock read with a durable timer (e.g., Temporal’s timer primitive) and re‑deploy.

Human Approval Lost in Chat Transcript

  • Trigger — A workflow reaches a human‑in‑the‑loop step, but the approval request is sent via a chat channel that loses the message (e.g., Slack notification missed).
  • Guard — The source describes awakeables (Restate) as durable callbacks that record the approval decision; the guard is that the waiting step is journaled so the approval is never lost if the system survives.
  • Posture — fail‑soft (stuck waiting): the workflow does not crash but remains paused indefinitely, blocking progress.
  • Operator signal — The workflow remains in a “waiting for approval” state with no progress; the absence of a completion signal is the indicator.
  • Recovery — Re‑send the approval signal via the awakeables API or inject a fallback approval manually; no automatic retry.

Journal Corruption or Loss

  • Trigger — The underlying storage for the journal (e.g., database) experiences corruption, hardware failure, or accidental deletion of the recorded steps.
  • Guard — The source does not show any explicit guard for journal integrity; it only describes replay (“replays the journal and skips work already completed”).
  • Posture — fail‑hard: without a valid journal, recovery is impossible and the workflow run is lost.
  • Operator signal — Errors such as “journal entry missing” or “corrupt event history” (implied by the absence of replayable state).
  • Recovery — Manual restoration from a backup of the journal; if no backup exists, the workflow must be started from scratch.
STUDY AIDSevidence-backed memory techniques
Recall check

How many phases does the tiered retrieval and verification pipeline have?

Show answer

four phases

06. Multi-Agent Orchestration

When a single agent has too many tools, it makes poor decisions. Splitting work across focused specialists solves that.

A main agent can coordinate subagents as tools. All routing passes through the main agent. That gives centralized control but adds one extra call per task. Subagents start fresh each time. They provide strong context isolation. But they repeat the full flow, so costs stay consistent.

In the handoffs pattern, agents transfer control to each other. One agent passes a task directly to another. The first agent stays active. Its state persists. That saves calls on repeat requests. A handoff can reduce total calls by about forty to fifty percent.

Skills let a single agent load specialized prompts and knowledge on demand. The agent stays in control. The skill context is already loaded in conversation history. There is no need to reload. That also saves calls by reusing loaded skill context.

A router pattern is stateless. Each request requires a routing call from a large language model. The router decides which worker agent gets the task. Since the router has no memory, it repeats that call every time. This pattern can be optimized by wrapping it as a tool in a stateful agent.

The trade-off is clear. More coordination means more model calls. Stateful patterns like handoffs and skills save forty to fifty percent of calls on repeat requests. Stateless patterns like subagents maintain constant cost per request. They provide strong context isolation but at the cost of repeated model calls.

For multi-domain tasks, handoffs, skills, and the router are most efficient. They each take three calls for a single task. Subagents add one extra call because results flow back through the main agent. That overhead provides centralized control.

When a user repeats the same request, stateful patterns shine. The coffee agent is still active. It directly calls a tool. It responds to the user without needing a handoff. That saves one call compared to a stateless approach.

By early two thousand twenty five, the agent to agent protocol reached version one point zero. It is an open standard. It enables AI agents to discover capabilities, communicate, and delegate tasks across teams, products, and organizations. The protocol gives the market a stronger foundation for open multi-agent collaboration. The community is now focused on delivering multi-language software development kit support. They want to help developers build conformant solutions with ease.

The agent to agent protocol works with the model context protocol. The model context protocol defines how agents connect to internal tools and data sources. Together they form a foundational layer for interoperable multi-agent systems. These systems work across different technology stacks without requiring a single platform approach.

The complete version one point zero materials are available online. They include the specification and migration documentation. The technical steering committee includes representatives from major companies like Amazon Web Services, Cisco, Google, IBM Research, Microsoft, Salesforce, SAP, and ServiceNow.

Looking ahead, the roadmap includes an interoperability specification. There are plans for registry consolidation and expanded testing and tooling. Security and deployment best practices are also on the horizon. With a stable specification and growing enterprise use, the protocol is shifting from early adoption to a core component of modern artificial intelligence and distributed system architecture.

Deferred capabilities load specialized tool sets on demand, keeping the main agent's context lean while enabling focused specialists.

python
Capability(
    id="my_capability",
    description="...",
    instructions="...",
    toolset=MCP(server="my_server"),
    defer_loading=True,
)
In plain words

Think of a single overwhelmed manager trying to juggle a hundred different tasks at once—calling suppliers, handling customer complaints, checking inventory. When that manager has too many responsibilities, they start making mistakes: using the wrong phone number, forgetting a key step, mixing up orders. Multi‑agent orchestration is like hiring a team of specialists: one person handles suppliers, another handles customers, and a third manages inventory. Instead of one overloaded manager, a main coordinator delegates each job to the right specialist, so every task gets clear, focused attention.

In practice, the main agent lists each specialist as a separate tool. When a new job arrives, the main agent chooses which specialist to call—say, the “customer‑support subagent”—and hands off that specific request. That subagent works in isolation: it sees only its own tools and instructions, never the clutter of the other specialists. Because each subagent starts fresh every time, it avoids confusion from leftover context. The main agent stays in charge of routing, adding one extra step per task but keeping the overall system simple and predictable.

The tricky part is that starting fresh each time also means no memory of past interactions. If a customer calls back about the same issue, the subagent doesn’t remember the earlier conversation—creating an edge case where the system repeats work or misses continuity. Without this orchestration, the single overwhelmed manager would constantly pick the wrong tool for a job, waste time re‑explaining tasks, or mix up instructions between departments, leading to frustrating failures that beginners would feel as slow, error‑prone responses.

System design

The described subsystem compares two orchestration patterns. In the tool-based subagent pattern, all routing passes through a single main agent; subagents start fresh each time, providing strong context isolation but repeating the full flow. In the handoffs pattern, agents transfer control directly while the first agent stays active and its state persists. The provided context does not contain a dedicated chapter on multi-agent orchestration, but it does define relevant system-design concepts from the "ai-agents-stack-2026-guardrail-gap.md" and "durable-execution-agents.md" sources. Because the query requires grounding only in the source, the following explanation is built from those documents’ exact mechanisms and identifiers.

The ordered mechanism is governed by a run journal that records every meaningful operation with a stable run_id and a step_id. Each operation — including LLM calls, tool calls, shell commands, and human approvals — is a replay boundary; its results are recorded and reused on recovery. The journal logs planned action, inputs, prompt/tool/model versions, approval status, result receipt, retry count, and error state. On failure, the runtime replays from the last committed step_id, reusing recorded outputs for all nondeterministic boundaries. This ensures that even when control passes between agents (as in handoffs), the recovery path is deterministic and auditable.

The invariant the design preserves is idempotency at the tool wrapper layer. The source explicitly names Idempotent Tool Wrappers: all mutating tools are wrapped with idempotency keys, receipts, duplicate detection, and compensation metadata. A send-message tool, for example, must know whether a message with the same run and step key was already sent; a pull-request tool must know whether the branch or PR already exists. This guarantee prevents duplicate side effects when retry storms or replay boundaries are triggered, maintaining exactly-once semantics for state-changing operations across agent handoffs.

The key trade‑off is between centralized routing and guardrail propagation. The source notes that "guardrail propagation across agent boundaries is an unsolved problem" (ai-agents-stack-2026-guardrail-gap). The tool-based subagent pattern keeps all routing in one main agent, avoiding the need to propagate guardrails — but adds one extra call per task and repeats the full flow, so costs stay consistent. The obvious alternative is the handoffs pattern, which saves calls on repeat requests by persisting state. That alternative is rejected because it introduces the unsolved problem of propagating guardrails across agent boundaries. The cost this rejection avoids is the need for "trace-level evals on every handoff" — the source warns that without those evals, five agents passing context is impossible to debug. By staying with a single routing point, the system sidesteps that debugging burden at the expense of higher per-task latency.

A concrete failure mode is a retry storm caused by nested retries across handoffs. The source cites the 2025 paper RetryGuard, which studies how default retry patterns across services amplify cost and load. The signal an operator would see is a global retry budget violation: the durable workflow tracks the total retry count for the entire run, not just the local retry count for one HTTP client. When that budget exceeds a configured threshold, the runtime logs an error with the run_id, the step_id of the offending retry loop, and the retry count. The operator observes a spike in total retry count across the run journal, and the agent’s response time degrades as nested retries cascade through replay boundaries and idempotency checks.

Interview Q&A

Q — When you split a single agent’s tool set across multiple specialist subagents, what cost does the “main agent as router” pattern introduce?

A — The subagent pattern requires three LLM calls per task: first the router picks the target subagent, then the subagent executes its tool (buy_coffee), then the subagent responds. This is because subagents start fresh each time and repeat the full flow, keeping cost consistent per request.

Follow-up — How does the handoff pattern avoid that extra call?

A — In the handoff pattern, the first agent stays active and its state persists, so the tool call and response use only two calls total, saving one LLM call by skipping the routing step.

Weak answer misses — The handoff pattern retains state, while the subagent pattern sacrifices state for strong context isolation; a shallow answer often omits this isolation trade‑off.


Q — For a repeat request, why would you choose a handoff pattern over a router pattern?

A — The router pattern is stateless—each request requires an LLM routing call (3 calls total). The handoff pattern is stateful and saves 40–50% of calls on repeat requests because the first agent’s state persists and no routing step is needed.

Follow-up — What optimization can make a router less wasteful?

A — The router can be wrapped as a tool inside a stateful agent, which converts it from a stateless three‑call pattern to a stateful two‑call pattern.

Weak answer misses — The key insight explicitly states that stateful patterns (handoffs, skills) save 40–50% of calls, but a weak answer overlooks the cost saving quantification.


Q — Why implement handoffs as direct agent‑to‑agent transfer instead of always routing through a central coordinator?

A — Centralized routing adds an extra LLM call (router → agent → response = 3 calls), whereas the handoff pattern keeps the first agent active, saving one call (agent → tool → response = 2 calls). This is grounded in the comparative call counts in the multi‑agent documentation.

Follow-up — What new problem does direct handoff introduce at scale?

A — “Two agents passing context to each other is already hard to debug. Five is impossible without trace‑level evals on every handoff,” as noted in the guardrail‑gap source.

Weak answer misses — The trace‑level evals requirement for handoffs is a practical operational cost that shallow answers ignore.


Q — The skills pattern loads context into conversation history. Why is that more efficient than using subagents for repeated tasks?

A — The skills pattern reuses already‑loaded skill context (2 calls total), while subagents start fresh each time and repeat the full flow (3 calls total). This saves one LLM call per repeat request because no context reloading is needed.

Follow-up — What risk does reusing loaded context introduce?

A — “Deciding what to remember, what gets dropped, and how you stop old context from polluting new answers” is the hard part, as stated in the ai‑agents‑stack guide.

Weak answer misses — A shallow answer skips the context pollution risk, focusing only on the call savings without mentioning the memory‑management challenge.

Failure modes

Phase-Order Violation by Subagent

  • Trigger — A subagent begins with reproduction before properly navigating the codebase, leading to repeated modifications to the reproduction script and a failed edit.
  • Guard — No guard shown in source. The PCPC metric and Phase Purity Factor (PPF) are post-hoc evaluation tools, not runtime handlers.
  • Posture — fail-soft: the agent continues executing degraded steps, but the overall success rate drops.
  • Operator signal — Low PCPC score; trajectory logs show missing phases, spurious phases, or violation of logical ordering (e.g., reproduction before navigation).
  • Recovery — No automatic recovery. The subagent must be manually re-instructed or the run restarted with a corrected plan.

Intent Forgetting Across Handoff

  • Trigger — A handoff agent transfers control to another agent, but the control‑plane mutation (supersede, release, purge) discards the original intent — e.g., cross‑lingual or compound‑fact forgetting.
  • Guard — No runtime guard shown in source. ForgetEval is a test suite, not a production handler. The source notes “production failures are predominantly forgetting failures rather than recall failures,” but no guard is implemented.
  • Posture — fail-soft: the receiving agent proceeds with incomplete context, causing downstream task failure.
  • Operator signal — Silent; the agent’s output contains canonicalization errors (identifier obfuscation, cross‑lingual failures) that are missed unless ForgetEval or manual review is applied.
  • Recovery — No automatic recovery. Manual re‑injection of intent or restart of the handoff with full state is required.

Unauthorized Tool Call Before Guardrail

  • Trigger — A subagent, given autonomous tool‑calling ability, executes a tool (e.g., sending an email, writing a file) before the guardrail layer can validate the action.
  • Guard — No runtime guard shown in source. The source only describes the “guardrails before action” pattern conceptually; no function, variable, or exception handler is named. NeMo Guardrails is mentioned as a framework, but no concrete identifier appears.
  • Posture — fail-closed? Actually fail-soft: the action is already taken (e.g., email sent) even if the output is filtered later; the source says “by the time you filter the response, the agent already sent the email.”
  • Operator signal — Log entry showing an unapproved tool call being executed; rate limit or authorization error missing in the trace.
  • Recovery — No automatic recovery. Manual rollback (e.g., unsend email) required; tool execution must be re‑authorized via policy code.

Duplicate Action After Crash Recovery

  • Trigger — The multi‑agent orchestrator crashes mid‑turn; the recovery mechanism (e.g., a retry) re‑executes the last tool call without idempotency, sending the same notification twice or committing a duplicate modification.
  • Guard — No runtime guard shown in source. The source mentions idempotency keys as a feature of Restate but does not provide a specific function or variable that enforces them in the orchestration code. The Workflow/Activity split in Temporal is a design pattern, not a guard.
  • Posture — fail-soft: the agent continues, but the duplicate action may corrupt state (e.g., double charge, double file write).
  • Operator signal — A duplicate log entry for the same action (e.g., “notification sent” twice); customer‑facing duplicate or inconsistent state.
  • Recovery — No automatic recovery. Manual cleanup of the duplicate, or re‑run with idempotency key enforced at the tool layer.

Overfitted Behavior Ignoring Instructed Plan

  • Trigger — A subagent is trained (or pre‑trained) on a specific action pattern — e.g., always opening a pull request after validation — and ignores the instructed plan that does not include that phase, producing a PPF < 1.
  • Guard — No guard shown in source. The PPF metric detects the spurious phase but does not block it.
  • Posture — fail-soft: the agent completes the spurious phase (e.g., opens a PR) and then continues with the remaining plan steps.
  • Operator signalLangutory analysis shows phases outside the specified alphabet; drop in PCPC; logs show “spurious phase: open pull request.”
  • Recovery — No automatic recovery. The run proceeds, but the operator must manually close the spurious PR or re‑set the plan.
STUDY AIDSevidence-backed memory techniques
Cloze

That  ____  issue is still open.

Show answer

guardrail propagation

07. Judges Panels And Debate

Models are now used to judge other models. A panel of nine frontier large language models from seven model families was tested on natural language inference datasets. Each item had a hundred human annotations. The surprising result was that these nine judges effectively provided only about two independent votes. Roughly three quarters of the panel's nominal independence was lost. Why? The models made the same mistakes on the same items. Their errors were strongly correlated, not diverse.

To get better judgments, researchers developed a multi agent debate framework. In this setup, multiple large language models collaborate and iteratively refine their responses. They prove mathematically that debate amplifies correctness compared to a static ensemble. Simple majority voting can fail even when individual judges are right. So the framework adds a stability detection mechanism. It models the judges' collective consensus over time using a Beta-Binomial mixture. An adaptive stopping criterion based on the Kolmogorov-Smirnov test decides when debate has stabilized. This stops the process earlier instead of running a fixed number of rounds. It improves judgment accuracy while keeping computational efficiency.

This discovery led to a reckoning about correlated errors. The panel of nine frontier models actually fell eight to twenty two percentage points short of the accuracy that independent voting would achieve. Neither adding more judges nor using smarter aggregation algorithms helped. Established methods closed at most eleven percent of that gap. The best single judge matched or outperformed the entire panel across all conditions. The bottleneck is correlated judges, not the aggregation algorithm.

This means panel design must shift focus from headcount to calibration and deliberate error diversity. You have to ensure judges make different mistakes, not just the same ones. The old idea that more models automatically bring more independence is false. The nine judges barely gave two effective votes. So instead of just adding models, you need to measure and break correlations. The multi agent debate with adaptive stopping offers one way to do that. It ensures consensus is real, not just a false majority. And it stops debating once the group's opinion has stabilized. That avoids wasting rounds on pointless argument.

When you combine these findings, a clear picture emerges. The large language model as a judge pattern works best when you account for shared weaknesses. Judge biases are really about correlated errors. And the best path forward is to design panels for error diversity, not raw numbers.

Judge panels face correlated errors; a memory client can store and retrieve user preferences across sessions.

python
from mem0 import MemoryClient
client = MemoryClient(api_key="your-key")
client.add("I prefer Python over JavaScript", user_id="aashi")
results = client.search("programming language preferences", user_id="aashi")
print(results)
In plain words

I cannot answer this query because the provided context contains no information about "Judges Panels And Debate," models judging other models, a panel of nine large language models, correlated errors, or a multi-agent debate framework. The context documents cover Pydantic AI capabilities, GUI agents, self-healing agents, long-context vs. RAG trade-offs, and agentic abstention—none of which include the specific subsystem you describe. To give a grounded explanation, I would need source material that discusses that topic.

System design

The provided context does not contain any information about judges panels, debate frameworks, or the specific experiment with nine frontier LLMs and correlated errors. Therefore, I cannot answer the query based on the given sources. No identifiers, invariants, trade-offs, or failure modes from that chapter are present in the context.

Interview Q&A

The provided context does not contain any information about judge panels, debate, or a panel of nine frontier models being tested on natural language inference datasets. The context focuses on plan-following in SWE agents (e.g., Standard plan, No Plan), memory benchmarks (LoCoMo, LongMemEval, BEAM), self-healing agents (ChemCrow, generative agents), and long-context vs. RAG economics. Therefore, I cannot generate interview-style Q&A pairs on the requested subsystem using only the given sources.

Failure modes

The provided context contains no information about "Judges Panels And Debate," the described panel of nine frontier LLMs, natural language inference datasets, human annotations, independence loss, or a multi-agent debate framework. The two source documents cover plan-following in SWE agents (from plan-following-gap-swe-agents.md) and forgetting failures in agent memory (from forgeteval-forgetting-failures.md). Neither document mentions judges, debate, or any evaluation scenario matching the query’s description. Therefore, no failure-mode analysis can be grounded in the source for this subsystem.

STUDY AIDSevidence-backed memory techniques
Quiz

According to the section, what did a 2026 study conclude about a panel of nine frontier models from seven families?

Options: provides only about two independent votes · falsely accepts one in three wrong answers · achieves accuracy equal to the single best judge · reduces errors by half compared to individual judges

Show answer

provides only about two independent votes

08. How Agents Remember

Agent memory is a persistent storage layer that lets an agent retain information across sessions. Without it, every conversation starts from zero. During conversations, the memory layer extracts facts. It stores them in a vector database indexed by user, session, and agent identifiers. At the start of a new session, relevant memories are retrieved using semantic similarity, keyword matching, and entity matching. Only the most relevant facts surface, keeping token usage low and retrieval precise.

Forgetting is actually a feature, not a bug. The control plane mutates stored memories through three operations: supersede, release, and purge. These actions allow passive decay, active deletion, and structured removal. Decay handles low-relevance memories over time. But staleness in high-relevance memories remains an open problem. For instance, a memory about a user’s employer stays accurate until they change jobs. Then it becomes confidently wrong.

In 2026, production failures are predominantly forgetting failures rather than recall failures. Where the model sits in the memory pipeline shapes which forgetting failure mode occurs. There are three placement regimes with complementary coverage. Deterministic primitives work well for lexical and temporal categories. But they fail on identifier obfuscation and cross-lingual cases. An LLM added at inscribe time recovers those cases perfectly. However, it cannot help with intent-aware deletion. A mutation-time hook recovers intent-aware deletion and brightens nearly all categories. It achieves an overall score of over ninety percent at a low cost per run.

The retrieval system uses a vector store as the recall mechanism. Benchmarks like LoCoMo and the BEAM evaluation measure both accuracy and token consumption. The LoCoMo benchmark requires about seven thousand tokens per retrieval call. That compares to roughly twenty-six thousand tokens for a full context approach. That difference is real on your inference bill at scale. The evaluation framework combines five dimensions: BLEU score, F1 score, LLM judge score, token consumption, and latency. This prevents optimizing on one axis at the expense of others.

Consumer-scale consolidation happens as memories accumulate. The new token-efficient algorithm uses single-pass hierarchical extraction and multi-signal retrieval. It raises scores on temporal queries by nearly thirty points and on multi-hop reasoning by over twenty-three points. These are the categories that most directly reflect how agents handle real user histories, where facts accumulate, change, and relate over time.

The economics favor tiered retrieval memory over raw long context. At roughly seven thousand tokens per query versus twenty-six thousand, the savings multiply at scale. The benchmark framework is open-sourced so you can test it on your own workload before committing to an architecture. Open problems remain: temporal abstraction at scale, cross-session structure that treats change as evolution, and privacy and consent architecture. But these are specific and bounded, not fundamental. The infrastructure to deploy memory covers twenty-one frameworks, twenty vector stores, and three hosting models. Engineers can wire in persistent memory in a single afternoon.

Adding and retrieving a memory using Mem0's client with semantic search.

python
from mem0 import MemoryClient
client = MemoryClient(api_key="your-key")
client.add("I prefer Python over JavaScript", user_id="aashi")
results = client.search("programming language preferences", user_id="aashi")
print(results)
In plain words

Think of agent memory like a personal notebook that the agent carries across conversations. Whenever you meet someone new, you write down their name and what they like, so next time you remember without asking again. Agent memory does the same: it stores facts the agent learns so every conversation doesn’t start from zero.

During a chat, the agent extracts key facts and jots them into its notebook—technically it stores them in a vector database indexed by user, session, and agent identifiers. When the agent starts a new session, it flips through the notebook using semantic similarity, keyword matching, and entity matching to pull out only the most relevant memories. This keeps the information it reads small, so it doesn’t waste tokens on unimportant details.

The trickier part is that the agent also deliberately forgets. Its memory system has a control plane that can supersede old facts with newer ones, release outdated ones, or purge them entirely—like crossing out a wrong phone number so you don’t keep dialing it. The ForgetEval benchmark measures these forgetting failures because real‑world problems come from the agent remembering the wrong thing, not from failing to find a memory. Without this forgetting mechanism, the agent’s notebook would fill with endless, irrelevant scribbles, making it confused and slow—every response would be delayed by wading through facts that no longer matter.

System design

The subsystem begins with a recall plane that retrieves stored facts via semantic similarity, keyword matching, and entity matching against a vector database indexed by user, session, and agent identifiers. The retrieval is followed by the control plane, where stored memories are mutated through three ordered operations: supersede, release, and purge. On failure—when a mutation cannot be resolved—the system falls through to a mutation-time hook that can handle the case retroactively, but the primary path is deterministic. The invariant preserved by this design is “deterministic substring match” scoring used by the ForgetEval benchmark: every mutation must produce a result that can be verified by exact substring presence or absence, guaranteeing that the memory store remains logically consistent with the intended forget command.

The key trade-off is between deterministic primitives (lexical/temporal operations, 64–191 ms per case) and an inscribe-time LLM that embeds memory facts with canonicalization during storage, versus a mutation-time hook that re-interprets deletion intent at mutation time. The obvious alternative—running an LLM at every mutation step—is rejected because it adds 2.3 s per case mutation latency and $0.17 per 385‑case run, whereas deterministic primitives complete in milliseconds with zero LLM cost. The rejection avoids the prohibitive latency and expense of per-mutation inference, while the mutation-time hook is reserved only for the 5–15% of cases where deterministic or inscribe-time approaches fail.

A concrete failure mode is identifier‑obfuscation in canonicalization: a user stores “call Dr. Smith at 555-0100” and later asks to forget “Dr. Smith’s number.” The deterministic primitive can only match exact substrings, so it succeeds only 5 % of the time (ForgetEval adversarial layer). An operator would see ForgetEval canonicalization‑asymmetry signals—a substring‑match score of 0.05 on that category, logged alongside the benchmark’s built‑in N/A scoring from the Adapter Protocol. The log entry would show a failed deterministic purge and a fallback to the mutation‑time hook, whose latency spike (from ~100 ms to ~2.3 s) serves as the real‑time alert for an unresolved canonicalization gap.

Interview Q&A

Q – How does the agent memory subsystem separate retrieval from modification, and what makes forgetting a deliberate feature rather than an accidental loss?
A – The memory pipeline is divided into a recall plane that retrieves stored facts (extensively benchmarked) and a control plane that mutates them via operations like supersede, release, and purge, as formalized in the ForgetEval architectural study. This separation turns forgetting into an intentional mutation action, not a retrieval failure.
Follow-up – Which specific failure mode does the recall plane handle so poorly that it motivates adding a mutation-time hook?
A recall plane with deterministic primitives scores 5% on identifier obfuscation and 0% on cross-lingual canonicalization, whereas a mutation-time hook recovers those categories and raises overall accuracy to 91.7–93.2%.
Weak answer misses – The exact mutation operations (supersede, release, purge) and the quantitative 0% and 5% failure rates on canonicalization.

Q – Why would you place the LLM mutation hook at mutation time instead of at inscribe time—the obvious alternative that catches errors earlier in the pipeline?
A – Inscribe-time LLM recovers canonicalization perfectly (100%) but cannot handle intent-aware deletion—scoring 0% on prefix-collision and compound-fact cases—while a mutation-time hook recovers those intent-aware cases at 78-85% and boosts overall accuracy to 91.7-93.2%, as shown in the ForgetEval placement regimes. The trade-off favors mutation-time because it solves the harder intent-aware failures without sacrificing canonicalization.
Follow-up – What operational cost does that mutation-time hook incur, and is it worth paying?
Mutation latency is 2.3 s per case versus 64-191 ms for deterministic primitives, at $0.17 per 385-case run, but the recall path remains unchanged, making it a pragmatic production choice.
Weak answer misses – The specific failure categories (prefix-collision, compound-fact) and the exact latency (2.3 s) and cost ($0.17 per run) figures.

Q – The BEAM benchmark shows a 25% performance drop from 1M to 10M tokens. What does that reveal about memory retrieval at production scale?
A – BEAM operates at 1M and 10M token scales and cannot be solved by simply expanding context windows; the drop from 64.1 to 48.6 indicates that temporal queries are the hardest category at scale, and even the best algorithms still have significant headroom—a +29.6 point gain was achieved with a new algorithm, but temporal abstraction remains an open problem.
Follow-up – How does BEAM’s design force systems to handle scale differently than LoCoMo?
LoCoMo uses 1,540 questions across four categories at smaller scale, while BEAM tests ten categories including abstention and contradiction resolution at production-scale volumes that expose scaling failures the smaller benchmarks do not.
Weak answer misses – The exact numbers (64.1, 48.6, +29.6) and the fact that BEAM tests categories like abstention not covered by LoCoMo.

Q – Memory staleness is listed as an open problem—why can’t simple decay or recency ranking solve it for high-relevance facts?
A – Decay handles low-relevance memories by reducing their retrieval probability, but staleness in high-relevance memories—such as a user’s employer after a job change—remains unsolved because the memory is confidently wrong yet frequently retrieved. The control plane could theoretically use a mutation-time hook to detect time-dependent facts and apply a supersede or release operation, but no current system adequately implements timing-aware mutation logic for this.
Follow-up – How does cross-session identity resolution amplify the staleness problem?
The memory model assumes a stable user_id, but anonymous sessions and multi-device users break that assumption; resolving whether two interactions came from the same person is an unsolved identity problem at the memory layer, making it impossible to notice that a fact is stale across sessions.
Weak answer misses – The distinction between decay (low-relevance) and staleness (high-relevance), and the specific assumption of a stable user_id.

Failure modes

Identifier-Obfuscation Canonicalization Failure

  • Trigger — The user queries a memory using an obfuscated identifier (e.g., var_X), but the stored fact uses a different spelling (e.g., variableX). The keyword‑matching component of the recall plane fails to match the strings.
  • Guardinscribe‑time LLM (if used during extraction) can canonicalize identifiers to a normalised form; the source reports 100% recovery on this category. Without it, no guard is named.
  • Posture — fail‑soft: the retrieval returns an empty or incorrect set; the agent continues with degraded awareness.
  • Operator signal — A recall‑rate drop to 5% on identifier‑obfuscation queries (as measured by ForgetEval). The operator sees low semantic‑similarity scores and missing facts.
  • Recovery — The operator must either enable the inscribe‑time LLM guard or manually add synonym mappings. No automatic retry exists in the source.

Cross‑Lingual Canonicalization Failure

  • Trigger — The user query and the stored fact are in different natural languages. The deterministic primitives (substring matching, keyword matching) cannot cross language boundaries.
  • Guardinscribe‑time LLM recovers cross‑lingual canonicalization entirely (100%). Without it, no guard appears in the source.
  • Posture — fail‑soft: retrieval returns no relevant memories; the agent treats the session as having no prior knowledge.
  • Operator signal — A 0% recall rate on cross‑lingual queries (reported in ForgetEval). The operator observes that queries in language B never surface facts stored in language A.
  • Recovery — Deploy a multilingual embedding model or enable the inscribe‑time LLM guard. Manual translation of queries is a workaround; no automatic fallback is provided.

Prefix‑Collision Intent‑Aware Deletion Failure

  • Trigger — A memory‑deletion request matches a prefix that also covers unintended facts (e.g., delete all memories starting with user- when only one specific user should be removed). The control plane’s supersede or purge operation removes too much.
  • Guardmutation‑time hook handles intent‑aware deletion with 78–85% success. If the system lacks this hook, no guard is named; the failure rate is 0% (i.e., always fails) under inscribe‑time LLM alone.
  • Posture — fail‑hard: the run may abort or the agent proceeds with corrupted memory. The source calls this a “forgetting failure”.
  • Operator signal — An observed “prefix‑collision” scenario where previously available facts disappear after a deletion command; the ForgetEval score drops on that category.
  • Recovery — The operator must restore memories from a backup or re‑run the deletion with a more specific pattern. If mutation‑time hook is available, the system retries with an adjusted deletion scope (implicit in the 78–85% recovery).

Compound‑Fact Intent‑Aware Deletion Failure

  • Trigger — A deletion targets one part of a compound fact (e.g., remove “John lives in Paris” but keep “John lives in London”). The control plane cannot isolate the intended sub‑fact and either deletes the entire compound or leaves it untouched.
  • Guardmutation‑time hook recovers 78–85% of these cases. Without it, inscribe‑time LLM yields 0% success (complete failure).
  • Posture — fail‑hard: the agent’s knowledge becomes inconsistent; subsequent reasoning may use stale or incomplete facts.
  • Operator signal — The ForgetEval score shows 0% on compound‑fact tests when only inscribe‑time LLM is in use; the operator sees that a deletion had no effect or removed too much.
  • Recovery — Manual correction of the memory store is required. If mutation‑time hook is present, the system retries the deletion with a refined query (no explicit retry count documented; recovery is probabilistic).
STUDY AIDSevidence-backed memory techniques
Explain & elaborate · explain why

In your own words, why does the three-tier memory stack described in the section (in-context state, vector search, and persistent memory across sessions) remain necessary even when context windows have grown to millions of tokens?

09. Tools And Computer Use

For years, agents called simple functions to get answers. Now they can control the computer itself. A large language model looks at a screenshot, moves the cursor, clicks and types to drive ordinary software built for people. This turns the whole desktop into a universal tool.

But counting pixels is hard for these models. The challenge involves visual spatial precision. The model must see exactly where a button ends and a text field begins. A tiny miscalculation can break an entire task.

Agents ace short benchmark tasks easily. Yet on realistic long horizon workflows that span hundreds of tool calls, they collapse. They lose track of constraints. They miss information that arrives mid task. They guess instead of asking the user. And they skip verification. Hidden state is their biggest weakness.

The best agent today is Claude Opus four point eight. With maximum thinking and batched tool calls, it completes only twenty point six percent of tasks end to end. Another model, GPT five point five, plateaus near thirteen percent. That means even the most powerful agent succeeds only about one time in five.

Earlier benchmarks like OSWorld one point zero involved about thirty tool calls per task. But the new OSWorld two point zero benchmark uses tasks that take a human user a median of one point six hours. Each task requires an average of three hundred eighteen tool calls. That is ten times more than before. At five hundred steps, the agent must keep track of everything.

During a task, the model can update the agent’s state. The runtime provides access to messages, user information, and long term memory. Short term memory holds the conversation history. But when a task runs for hours, the model often forgets what it already did.

The agents do not stumble on basic GUI control or coding. They lose the plot. They fail to ask for help when they are unsure. They do not double check their work. And they cannot recover hidden state on their own.

That is why professional level computer use remains out of reach. The model looks at a screen, picks a tool and its arguments, and the runtime executes it. Then the result feeds back into the next step. But over hundreds of steps, the chain breaks.

This is the shift from simple function calling to computer use. The tool becomes the entire interface. Counting pixels, detecting mid task changes, and verifying outcomes are still unsolved. No agent today can reliably complete a real world workflow that lasts hours.

A LangChain tool decorator defines a callable an agent can invoke.

python
from langchain.tools import tool

@tool
def search_database(query: str, limit: int = 10) -> str:
    """Search the customer database for records matching the query.

    Args:
        query: Search terms to look for
        limit: Maximum number of results to return
    """
    return f"Found {limit} results for '{query}'"
In plain words

Think of a helpful assistant who watches your screen over your shoulder, then reaches in and uses your mouse and keyboard for you. That is what these GUI agents do: they turn the entire computer desktop into a tool the model can operate, letting it control ordinary software built for people instead of calling pre‑defined functions.

The model takes a screenshot, like snapping a photo of the screen. It looks at that photo to find the correct button or text field, then moves the cursor to the exact pixel coordinates it calculated and clicks or types. Researchers call this “visual spatial precision” – the model must measure where things are, like where a button ends and a text field begins. In the survey of these agents, they are described as “LLM‑brained GUI agents” that interpret complex GUI elements and execute actions autonomously. The model does not see hidden menus or scroll bars; it only sees the static image, so every movement relies on counting pixels accurately from that single snapshot.

The trickiest part is that a tiny miscalculation – just a few pixels off – can make it click the wrong spot, breaking the entire task. Even worse, when the screen changes after a click (a dialog pops up), the model’s next screenshot is new, but it may forget the previous state because of a limit called the finite context length. It cannot keep the full history of every previous screen and action, so it might misjudge what to do next. Without this subsystem, the agent would be blind to the actual GUI and could only call hard‑coded functions. The concrete failure: an agent trying to “book a flight” clicks the wrong button because it misjudged coordinates, then gets stuck in a loop of errors, never completing the task.

System design

Based solely on the provided context, I cannot produce a system-design explanation of the "Tools And Computer Use" subsystem you describe. The context documents discuss LLM agent memory pipelines (ForgetEval), plan compliance in programming agents (plan-following-gap), a landscape overview of agents, and Pydantic AI v2 capabilities. There is no description of a computer-control mechanism in which an LLM drives a desktop via screenshots, cursor movements, and clicks. The only mention of "computer use" is a single sentence in the landscape document noting a "computer use reference implementation, where Claude uses a computer to accomplish tasks" — but no further details about its ordered mechanism, invariants, trade-offs, or failure modes are provided. Therefore, I cannot answer the query using the given sources.

Interview Q&A

Q — What is the purpose of the default planning mechanism in the SWE-agent scaffold?
A — The default plan is embedded in the system prompt and provides a standard phase sequence—Navigation, Reproduction, Patching, Validation—to guide the agent’s actions. This mechanism is evaluated across multiple plan settings to study the role of planning in programming agents.
Follow-up — How is compliance with this plan measured?
A — Compliance is measured using PCPC scores that detect missing phases, spurious phases, or violations of the logical phase ordering.
Weak answer misses — The exact phases of the Standard plan (NRPV) and that PCPC is a proportional score reflecting deviations.


Q — Why does removing the plan (No Plan setting) sometimes allow agents to fix previously unresolved issues?
A — Under No Plan, agents resolved additional instances not solved under the default plan—Devstral-small resolved 28 extra and GPT-5 mini resolved 34 extra—indicating that without the plan, agents can explore alternative strategies not found in the fixed sequence.
Follow-up — Does that mean the default plan is always detrimental?
A — No, because overall success rate drops; the plan provides focus and prevents premature convergence, as shown by smaller Graphectory metric values under No Plan compared to the Standard plan.
Weak answer misses — The specific count of extra instances per model and the Graphectory metric as the measure of reasoning focus.


Q — The design includes a plan reminder setting that periodically re-injects the default plan. Why this way and not a static, one-time plan?
A — The plan reminder (RQ5) periodically re-injects the default plan into the agent’s prompt to maintain compliance over long horizons, countering drift from the intended sequence. A static plan may be forgotten or overridden as the agent progresses, while periodic reminders reinforce adherence without requiring full re-injection.
Follow-up — What specific phase ordering violations does the plan reminder aim to prevent?
A — It aims to prevent missing phases (e.g., skipping Validation) or insertion of spurious phases, which the PCPC scoring tracks as violations of logical ordering.
Weak answer misses — The exact RQ5 designation and that the plan reminder is one of eight plan settings evaluated in the study.


Q — Why use a fixed phase sequence (Navigation, Reproduction, Patching, Validation) instead of letting the agent dynamically choose the order?
A — The fixed sequence imposes a logical workflow common in software engineering, and deviations—like reordering reproduction test generation after patching—are explicitly tested as a mutation (step reordering, RQ4) to measure impact. The rationale is that many LLMs already internalize similar strategies, so a fixed plan acts as a scaffold; dynamic ordering was studied indirectly through the phase flow analysis under No Plan.
Follow-up — What does the phase flow analysis show for models like DeepSeek-V3 when the plan is removed?
A — DeepSeek-V3 largely reduces trajectories to NP patterns, skipping Reproduction and Validation, indicating that without the plan the encoded strategy takes over but may miss critical phases (Finding 5, Figure 4).
Weak answer misses — The reference to Figure 4 and the specific NP pattern observed for DeepSeek-V3 under No Plan.


Q — Why measure compliance using phase flow analysis rather than just task success rate?
A — Phase flow analysis captures detailed adherence to the Standard plan sequence, revealing that even when success rate drops, some models follow the plan partially (e.g., GPT-5 mini often without Reproduction). The multi-dimensional PCPC scoring distinguishes failure modes—missing phases vs. spurious phases—that success rate alone cannot uncover.
Follow-up — How does the Graphectory metric complement this analysis?
A — The Graphectory metric measures the trajectory’s focus; under No Plan, models like DeepSeek-R1 show smaller Graphectory values compared to the Standard plan, which quantifies the loss of reasoning focus (Finding 6).
Weak answer misses — The explicit mention of Graphectory metric as a separate measure from PCPC, and its use in comparing Standard vs. No Plan trajectories.

Failure modes

Plan Phase Forgetting

  • Trigger — The agent omits a required plan phase (e.g., validation or reproduction) because local context overrides the instructed plan; the model’s short-term reward optimization (DeepSeek‑R1) or overfitting to certain actions causes the omission, leading to a forgetting failure.
  • Guard — The mutation‑time hook (from the ForgetEval paper) recovers intent‑aware deletion failures (78–85% success). In plan‑following terms, the plan reminder (RQ5) periodically re‑injects the default plan, acting as a guard against phase omission.
  • PostureFail‑soft. The agent continues but with degraded compliance; the guard re‑injects the plan, but the forgetting may still degrade trajectory quality. The system does not halt.
  • Operator signal — A low PCPC (plan compliance score) and a low PPF (plan phase fidelity) in the Langutory analysis; also, production forgetting failures are predominantly observed rather than recall failures (ForgetEval finding). The operator would see metrics indicating missing phases.
  • Recovery — The plan reminder re‑injects the default plan periodically, but no specific retry count or backoff is described. The agent continues with the re‑injected plan; a manual step may be needed if the agent repeatedly forgets.

Plan Phase Order Violation

  • Trigger — The agent begins a task with a phase that should come later (e.g., reproduction test generation before codebase navigation, as shown in Figure 1b of the source). This violates the logical phase ordering.
  • Guard — No explicit guard is named in the source. The plan itself defines the order, but no real‑time exception handler or retry mechanism prevents the violation.
  • PostureFail‑soft. The agent continues with an inefficient trajectory; the source states this “can cause inefficient trajectories or task failure,” but the run is not aborted.
  • Operator signal — A low POC (plan order compliance) metric in the Langutory analysis; the operator would see that the expected phase sequence was broken.
  • Recovery — No automatic recovery is described. The agent may eventually self‑correct if later phases are performed, but the inefficiency remains. A manual intervention to restart with correct ordering might be required.

Spurious Unauthorized Action

  • Trigger — The agent performs an action outside the instructed plan, such as opening a pull request after patch validation (explicitly mentioned in the source as an action “which is not part of the instructed plan”). This adds a spurious phase.
  • Guard — The guardrails‑before‑action pattern (from the guardrail gap chapter) enforces authorization at the tool execution layer. The source notes NeMo Guardrails as the closest framework, and OWASP MCP Top 10 as a security checklist, but no specific function is named. The guard is conceptual, not a named identifier.
  • PostureFail‑soft. The agent continues despite the extra action, but the spurious phase lowers PPF (plan phase fidelity) and may distract from the core task.
  • Operator signal — A PPF score below 1.0 in the Langutory analysis, indicating unknown letters (spurious phases) appeared. The operator would also see OpenTelemetry traces showing an unplanned tool call.
  • Recovery — No automatic rollback. The agent proceeds; the operator may need to review the trajectory and decide whether the extra action was harmful.

Persistent Tool‑Calling Failures

  • Trigger — The model (most severely DeepSeek‑R1) generates consistent tool‑calling errors due to “optimization for short‑term reward,” a known weakness described in the source. These failures prevent successful plan execution.
  • Guard — No guard is present in the source. The source states that these errors “result in a very low success rate, preventing any conclusion regarding plan compliance.” No retry, fallback, or validation is mentioned.
  • PostureFail‑hard. The agent cannot proceed; the run effectively aborts due to repeated tool‑calling failures.
  • Operator signal — A “very low success rate” for the model, along with “pervasive tool‑calling failures” observed in the trajectory logs. The operator would see failed tool calls without recovery.
  • Recovery — No automatic recovery. The operator must manually intervene, typically by switching the underlying model (e.g., replacing DeepSeek‑R1 with a different LLM) or re‑running with a different scaffold.

Non‑deterministic Plan Resolution

  • Trigger — In reduced plan settings (e.g., No Validation), agents sometimes unexpectedly succeed on previously unresolved issues because of non‑determinism (explicitly referred to as “non‑determinism (§6.2)” in the source). This unpredictability is a failure mode because the agent’s behavior is not reproducible.
  • Guard — No guard is described. The source attributes these outcomes to “remaining impact of nondeterminism,” implying no real‑time validation catches or mitigates it.
  • PostureFail‑soft. The agent succeeds despite the reduced plan, but the outcome is unreliable; the system continues without aborting, but the operator cannot trust the result.
  • Operator signal — The operator would see that the agent resolved an issue under a setting where it should have failed, with a PCPC score that is unexpectedly high. The exclusive resolution would appear in the trajectory logs, contradicting expectations.
  • Recovery — No automatic recovery. The operator should treat such successes as possibly due to chance and may need to re‑run the task multiple times to confirm the result.
STUDY AIDSevidence-backed memory techniques
Recall check

What does function calling give a large language model the ability to use?

Show answer

the ability to use tools

10. MCP And Interop

The Model Context Protocol is an open standard for connecting AI assistants to the systems where data lives. It replaces fragmented custom integrations with one universal way to link assistants to data sources and tools. Developers can expose their data through servers, or build applications that connect to those servers. This means a server exposes a capability once, and any assistant can bring it to life. No more hand-wiring separate connectors for each data source. Instead, everyone builds against a single protocol. That is why an open ecosystem beats every team doing its own thing alone.

The protocol is maturing fast. It now supports server-to-client requests during a call, so a server can ask the user for input mid-task. That uses a result type called input required. The tool schemas now support full JSON schema with composition and conditionals. Output can be any JSON value, not just an object. These changes make tool calls more powerful and structured.

The next major revision includes a stateless core. Any request can land on any server instance, so sticky routing is no longer needed. There is an official extensions framework for new capabilities. That framework lets features ship as opt-in extras and stabilize before joining the core spec. OAuth authorization is also hardened, with clear guidance for refresh tokens and scope accumulation.

This revision has breaking changes, but that is not the norm going forward. A feature lifecycle policy gives at least twelve months between deprecation and removal. The goal is to evolve without breaking everything each time. The protocol remains collaborative and open source. Developers can start building today using the pre-built servers for systems like Google Drive, Slack, GitHub, and Postgres. Early adopters such as Block and Apollo have already integrated it.

The result is a simpler, more reliable way to give AI systems access to the data they need. Instead of a messy set of custom connectors, there is one standard protocol. And that standard keeps improving with community input. The future of context-aware AI depends on open bridges like this one.

Using an MCP server to provide GitHub capabilities in a Pydantic AI agent.

python
from pydantic_ai import Agent
from pydantic_ai.capabilities import Capability
from pydantic_ai.mcp import MCPToolset

agent = Agent(
    'anthropic:claude-opus-4-7',
    instructions='Research thoroughly and cite your sources.',
    capabilities=[
        Capability(
            id='github',
            description='Look up GitHub issues, pull requests, and code.',
            instructions='Use the GitHub tools when a question is about a repository.',
            toolset=MCPToolset('https://mcp.example.com/github'),
            defer_loading=True,  # stays out of the prompt until the model loads it on demand
        ),
    ],
)
In plain words

Imagine a universal remote that works with any TV brand instead of needing separate remotes for each one. That is what the Model Context Protocol does for AI assistants and the data sources they talk to. It is a single standard that lets any assistant connect to any tool or database without custom wiring.

In practice, developers build MCP servers—like adapters for GitHub, Slack, or Postgres—that expose tools and data. Any assistant that understands the protocol can call a server’s capabilities, whether retrieving files or running queries. The server describes its tools in a standard format, and the assistant picks what it needs. The key mechanism is that the protocol replaces one-off connectors: a server is built once, then every compatible assistant uses it. But security is critical—Endor Labs found 82% of servers vulnerable to path traversal, so locking down access is non-negotiable.

The trickiest point: the protocol only standardizes tool calls between an assistant and a service; it says nothing about assistants talking to each other (that is a separate problem handled by ACP or A2A). So if you need two AI agents to coordinate, you must build that yourself at the framework layer. Without this protocol, every team would hand-wire separate connectors for each data source—wasting effort, creating fragile integrations, and making it impossible to swap in a different assistant without rewriting everything. That is the concrete failure: a tangled mess that breaks as soon as you add one more tool.

System design

The subsystem operates through a clear client–server architecture defined by the Model Context Protocol. First, a developer exposes data by building an MCP server or builds an AI application as an MCP client. The client then initiates a secure two-way connection to the server to retrieve context or invoke tools. If the connection fails—for example, because the server is unreachable or the protocol handshake fails—the assistant cannot access that data source, and the client must handle the error (typically by returning an N/A or logging the failure). This ordered mechanism ensures that any compliant assistant can talk to any compliant server, but only when the server is available and responsive.

The design preserves the invariant that MCP is a universal, open standard for connecting AI systems with data sources, replacing fragmented integrations with a single protocol. This invariant guarantees that a server that exposes a capability once can be consumed by any assistant without per-source custom wiring. The guarantee is that the protocol itself does not break; any two compliant implementations can interoperate as long as the server is reachable and the client follows the specification.

The key trade-off is accepting a universal protocol—and the overhead of implementing it—instead of building separate direct connectors for each data source. The obvious alternative is the status quo: hand-wiring a custom integration for every repository, business tool, or development environment. That rejection avoids the cost of maintaining “separate connectors for each data source,” which the source explicitly calls out as “fragmented integrations” that do not scale. By adopting a single protocol, teams save the engineering effort of duplicating integration logic across every new source and instead build once against the standard.

A concrete failure mode is an MCP server becoming unresponsive due to a crash or network partition. The operator would see the MCP client (e.g., the Claude Desktop app) fail to establish or maintain the two-way connection, producing an error such as “MCP server unreachable” or a timeout in the assistant’s response when it attempts to fetch a required tool or context. This signal indicates that the server-side implementation or its infrastructure is broken, and the agent cannot complete tasks that depend on that data source.

Interview Q&A

Q — "We've seen every AI provider ship their own tool connectors. Why push an open standard like MCP instead of just picking the best proprietary one?"

A — MCP solves the fragmentation problem: every new data source had previously required its own custom implementation, making it difficult to scale truly connected systems. The Model Context Protocol replaces those fragmented integrations with a single universal standard, so a server exposes a capability once and any MCP‑compatible assistant can use it — no hand‑wiring separate connectors.

Follow-up — "Doesn't that mean slower innovation if the standard can't keep up with each provider's latest feature?"
A — The open‑source repository of MCP servers, combined with Claude 3.5 Sonnet’s ability to quickly build server implementations, means the ecosystem can actually accelerate adoption rather than slow it down.

Weak answer misses — A shallow answer would omit that MCP is specifically a protocol specification with accompanying SDKs (the three major components listed: specification and SDKs, desktop app support, and an open‑source server repo), not just a vague "standard."


Q — "The Model Context Protocol claims to be an 'open standard' — what concrete mechanisms does it provide to make interop actually work in production?"

A — MCP defines a straightforward architecture: developers expose their data through MCP servers, and AI applications act as MCP clients that connect to those servers. The protocol specifies secure two‑way connections, and the three released components — the specification, SDKs, local server support in Claude Desktop, and an open‑source repository of pre‑built servers (e.g., for GitHub, Slack, Postgres) — give teams a concrete, drop‑in way to plug in data sources without building custom integrations.

Follow-up — "How does MCP handle auth or rate‑limiting for those pre‑built servers?"
A — The provided context does not detail auth or rate‑limiting mechanisms; it only states the connections are "secure" and that the protocol enables two‑way connections.

Weak answer misses — A shallow answer would ignore the fact that MCP ships with actual pre‑built servers (like Git, Postgres, Puppeteer) that let teams start using the protocol immediately, not just a specification document.


Q — "Your stack diagram puts MCP as the foundation of the tools layer. Why do you call it a 'new' layer that didn't exist as a distinct category before?"

A — Because before MCP, tool connectivity was done ad‑hoc — every assistant had its own custom integration for each data source, and there was no universal protocol to separate the tool‑connectivity problem from model inference or memory. The 2026 agent stack positions MCP as the layer that "standardized tool connectivity, and the entire tools layer is new because of it" — meaning teams no longer have to solve the same connector problem repeatedly.

Follow-up — "If MCP is so foundational, why isn't it enough to build a production agent by itself?"
A — MCP only covers tool/data connectivity; the stack still needs separate layers for memory, guardrails, evaluation, and frameworks — the layers where state management is hardest are not solved by a protocol alone.

Weak answer misses — A shallow answer would overlook that MCP specifically addresses the tools layer, while other critical layers (memory, guardrails) remain separate concerns that impose their own vendor‑lock‑in and state‑management challenges.


Q — "Why this way and not the obvious alternative: each data source ships its own plugin SDK and the agent calls those SDKs directly?"

A — The obvious alternative creates fragmentation: "every new data source requires its own custom implementation, making truly connected systems difficult to scale." MCP flips that model — a server exposes its capability once via the protocol, and any MCP client (any assistant) can consume it. This avoids forcing every tool provider to maintain N different SDKs and every agent team to integrate N custom connectors.

Follow-up — "But doesn't that put a bottleneck on the protocol itself? What if MCP misses a feature that a particular tool needs?"
A — The protocol is open‑source and extensible — the open‑source repository of MCP servers and the ability for any team to build new servers means missing features can be added by the community, not locked behind a single vendor's roadmap.

Weak answer misses — A shallow answer would ignore that the entire benefit hinges on the open standard nature — proprietary SDKs give a single provider control, while MCP's openness ensures no single entity dictates the protocol's evolution.

Failure modes

Failure 1: Unauthorized Tool Action Executed Before Output Filter

  • Trigger – The agent invokes a tool (e.g., sends an email) while the guardrail only validates the model’s final textual response, which occurs after the action is already taken.
  • Guard – The “guardrails before action” pattern: enforcement of authorization at the tool execution layer rather than the output layer. (Identifier: “guardrails before action” pattern; “tool execution layer” from the source.)
  • Posture – Fail-hard. The action is already performed and cannot be reversed by any subsequent guardrail.
  • Operator signal – The email is sent; the operator observes an unintended, possibly harmful action with no automated alert about the violation.
  • Recovery – No automated recovery. Manual rollback (e.g., recall the email) or apology. The source does not describe a retry or fallback.

Failure 2: Unaddressed Security Vulnerabilities from Ignoring the MCP Security Checklist

  • Trigger – The agent connects to external data sources or exposes tools without reviewing or implementing the OWASP MCP Top 10 (beta) security checklist.
  • Guard – OWASP MCP Top 10 (beta) – a published security checklist for tool-connected agents. (Identifier: “MCP Top 10 (beta)” from the source.)
  • Posture – Fail-soft. The system continues to operate, but vulnerabilities remain latent until an attacker exploits them.
  • Operator signal – Silent absence of any security alert; the operator sees normal behavior until an incident occurs.
  • Recovery – Manual audit and remediation of the discovered vulnerabilities. No automated recovery is described in the source.

Failure 3: Custom Guardrail Code Fails to Cover an Unforeseen Action

  • Trigger – The agent performs a novel or edge-case action that the custom policy code (written by the team) did not anticipate or define a rule for.
  • Guard – NeMo Guardrails framework (the closest framework mentioned), but the source states “you’ll still write most rules from scratch.” No specific built-in catch-all guard is provided; the guard is the custom policy itself, which by definition is incomplete for this trigger.
  • Posture – Fail-soft. The action proceeds unchecked because no rule matched.
  • Operator signal – Unexpected behavior or a security incident later; no real-time log of the gap.
  • Recovery – Manual investigation of the incident, followed by updating the custom rule set. No automated retry or fallback is present.

Failure 4: Guardrails Cannot Enforce Policy Because Real-Time State Is Not Tracked

  • Trigger – Guardrails require knowledge of the agent’s current state (e.g., what it has done so far) to decide what it should not do next, but the system does not track agent state in real time.
  • Guard – The source identifies the requirement (“Guardrails need to know what the agent is doing right now … That means tracking agent state in real time”) but provides no specific guard or implementation in the source. The guard is absent by design in many deployments.
  • Posture – Fail-soft. Guardrails may allow harmful actions because they rely on stale or absent state information.
  • Operator signal – Inconsistent agent behavior; potential unauthorized tool calls pass without detection. No distinct error field is emitted.
  • Recovery – Manual intervention to implement real‑time state tracking infrastructure. No automated recovery is described.

Failure 5: Prototype-to-Production Guardrail Gap Causes Uncaught Failures in Production

  • Trigger – The agent is deployed to production with no guardrails because they were omitted during prototyping. The source states: “Your demo has no guardrails because nobody’s trying to break it. Production will.”
  • Guard – No guard is present. The source explicitly identifies the “prototype-to-production gap is effectively infinite” for this layer and notes that “most production teams are still deploying with FastAPI and their own infra.”
  • Posture – Fail-soft until a failure is triggered, then effectively fail-hard when the agent performs an unintended action.
  • Operator signal – Production users discover failures; the operator learns of the problem only after an incident occurs (no prior warning).
  • Recovery – Manual addition of guardrails retroactively. No automated retry or fallback is provided by the source.

Failure 6: Incomplete Adherence to the OWASP MCP Top 10 Checklist Still Leaves Gaps

  • Trigger – The team partially implements the MCP Top 10 checklist but misses a requirement—for example, rate‑limiting or input sanitization—and the agent exploits that gap.
  • Guard – OWASP MCP Top 10 (beta) checklist (identifier as above). However, the source does not describe an automated enforcement mechanism; the guard is the checklist itself, not a runtime validator.
  • Posture – Fail-soft. The agent continues to operate, but the missed requirement creates a vulnerability or allows unintended behavior.
  • Operator signal – Silent until the missed requirement is triggered; no specific alert arises from the absence of that requirement.
  • Recovery – Manual review of the checklist implementation and patching of the missed requirement. No automated rollback is described.
STUDY AIDSevidence-backed memory techniques
Cloze

An  ____  for tool calling replaces  ____ .

Show answer

open standard, fragmented custom integrations

11. Guardrails And Safety

A tool calling agent can pause for human review.
You set rules that decide which tool calls require approval.
For example, you can pause only when a tool writes outside a workspace directory.
Or you can pause only when a tool runs a write query on a database.
Read only queries run automatically without interruption.
This is a human approval gate in front of actions that could have lasting effects.
Each pause gives a reviewer three choices.
They can approve the tool call and let it execute.
They can reject it and send feedback instead.
Or they can respond directly as if the tool were asking a question.
The rejection message tells the model why the action was denied.
It also tells the model not to retry the same call unless the user asks.
This keeps the agent on track without repeating mistakes.
The rules are checked every time the model asks to use a tool.
They are deterministic, meaning the same input always gets the same result.
That kind of enforcement does not rely on the model noticing something is wrong.
Instead, it relies on a fixed policy that runs outside the model.
Recent research tested this approach against attacks that try to inject instructions.
The research evaluated a system called Progent on a benchmark called AgentDojo.
It used an open weight agent with seven billion parameters.
That agent was self hosted on a single graphics card.
The defense cut the attack success rate roughly sixfold.
It dropped from about twenty six percent down to just four percent.
Even a specially designed adaptive attack did not raise that rate.
The attack success stayed at about three percent.
This is only one small scale data point on a weaker model.
A stronger optimized attack remains an open question.
Still, it shows that deterministic out of band checks can succeed where in model detection fails.
The checks validate the tool call arguments directly.
They block calls that violate the policy before any harm can happen.
This is the shift to enforcing security on the tool call surface itself.
Instead of training the model to refuse malicious instructions, you mediate the actions it can take.
You add guardrails that earn the agent more autonomy over time.
Every rule you put in place lets the agent run with less human oversight.
But the agent never outruns its safeguards.
The system pauses whenever a call matches a policy you defined.
That pause is the moment where a human decides what happens next.
Only after approval does the tool execute.
This pattern makes autonomy safe to deploy.
It does not remove human control.
It places human control exactly where it matters most.
The result is an agent that can act quickly but never act without permission on risky actions.
You get the benefits of automation without losing the ability to stop mistakes.

Human review provides decisions for multiple tool calls, including approve, edit, and reject with feedback.

python
{
    "decisions": [
        {"type": "approve"},
        {
            "type": "edit",
            "edited_action": {
                "name": "tool_name",
                "args": {"param": "new_value"}
            }
        },
        {
            "type": "reject",
            "message": "This action is not allowed"
        }
    ]
}
In plain words

Imagine a security guard at a warehouse who lets routine deliveries pass without a second look but stops any package that is marked as suspicious or goes to a restricted area. That is exactly what this subsystem does: it lets a tool‑calling agent run most actions automatically, but forces a human review before any action that could cause lasting harm.

When the agent wants to use a tool, a set of rules decides whether the action is safe to run alone. For example, the system might pause only if the tool tries to write a file outside an allowed workspace, or if it attempts a write query on a database. Read‑only queries, like looking up a customer name, go through without interruption because they cannot change anything. When a pause happens, the reviewer sees the request and has three clear choices: approve the tool call and let it execute, reject it and send feedback to the agent instead, or respond directly as if the tool call were a message. This is a concrete guardrail—the same kind of constraint described in the autonomy‑levels source, where guardrails are deliberately removed in fully autonomous agents. Here, the guardrail is a human‑in‑the‑loop gate that prevents irreversible mistakes.

The trickiest part is designing the rules so they catch dangerous actions without slowing down every step. The system must distinguish between actions that could have lasting effects (like writing to a database) and those that cannot (like reading data). Without this subsystem, an agent might accidentally delete a critical file or overwrite a production record—a mistake a beginner would immediately feel when their project breaks. The rules act like the “capabilities” framework from the pydantic‑ai source, where each capability can be loaded only when needed; here, the human review capability is triggered only when a rule matches, keeping the agent fast for safe actions and cautious for risky ones.

System design

The subsystem implements a guardrails-before-action pattern where policy evaluation gates tool execution. The ordered mechanism begins when the agent’s local reasoning selects a tool call. Before the call is dispatched, the runtime consults a policy rule set — for example, a rule that pauses only when a tool writes outside a workspace directory or issues a write query on a database. If the rule matches, the runtime enters an interrupt pattern (as named in LangGraph) that serializes the agent’s state and yields control to a human reviewer. The reviewer sees three options: approve (let the tool execute), reject (send feedback without execution), or respond directly. On approval, the tool call resumes from the recorded boundary; on rejection, the agent receives the feedback and continues without executing the blocked action. Read-only queries bypass the gate entirely, executing automatically.

The central invariant is a write boundary guarantee: no action with lasting effects (e.g., file modification, database mutation, email dispatch) reaches the external system unless explicitly authorized at the tool execution layer. This is an exactly-once authorization check that must hold before the tool input is committed. The guarantee explicitly rejects the alternative of output-layer filtering, where the model’s response is sanitized only after the tool has already executed. The source states plainly: “By the time you filter the response, the agent already sent the email.” The cost that rejection avoids is the irreversible side effect — an email sent, a package installed, a database row deleted — that post-hoc filtering can only detect but never undo.

The key trade-off is maturity versus engineering burden. The guardrails layer is described as “the least mature layer in the stack” with “no dominant framework, no established patterns.” Teams are forced to write custom policy code from scratch rather than using a pre-built authorization framework (the obvious rejected alternative). The cost that rejection avoids is latency and concurrency bugs hidden in generic frameworks — the source warns that “guardrails need to know what the agent is doing right now to decide what it shouldn’t do next,” which demands real-time state tracking that off-the-shelf systems cannot provide. By writing policy code directly, engineers trade framework convenience for precise control over the interrupt timing and the serialization of the approval state.

A concrete failure mode occurs when the runtime does not persist the interrupt state durably. For example, if the human approval is recorded only in an in-memory chat transcript and the process crashes before the approved tool call can be replayed, the approval is lost. The signal an operator would actually see is a missing trace entry in the agent’s execution journal — the expected approval decision and subsequent tool output are absent, while the preceding tool input (the blocked call) still appears as the last recorded event. The interrupt pattern in LangGraph explicitly warns that “code before an interrupt may run again, so approval boundaries must be placed carefully,” and the OpenAI Agents SDK notes that “interrupted run state can be serialized and later resumed” — if that serialization is missing, the operator must manually infer whether the action was ever authorized.

Interview Q&A

Q
When an agent calls a tool that writes outside a workspace directory, how do you pause the execution and give a human reviewer control over whether to allow it?

A
You set a condition in the agent’s graph that triggers an interrupt when the tool’s arguments indicate a write outside the permitted directory. The paused execution is resumed by calling agent.invoke with a Command object that contains a resume dictionary holding a list of decisions. Each decision has a type field – approve, reject, or respond – and the tool is only executed after an approve decision is provided.

Follow-up
What happens if the reviewer rejects the tool call without a message?
A
The middleware uses a default rejection message that tells the model the tool was not executed and not to retry the same call unless the user asks.

Weak answer misses
The exact mechanism of Command(resume={"decisions": [{"type": ...}]}) and the fact that decisions are applied per action in the interrupt request.


Q
Why would you implement a human‑in‑the‑loop gate at the tool‑execution layer rather than filtering the final output after the agent has already acted?

A
Because “by the time you filter the response, the agent already sent the email” – the guardrails‑before‑action pattern enforces authorization at the tool execution layer, not the output layer. The interrupt mechanism in LangGraph pauses the agent before the tool is executed, allowing a human to reject the action before any side effect occurs.

Follow-up
But isn’t that more complex than a simple output validator? Does the added complexity ever justify itself?
A
Yes – the OWASP MCP Top 10 security checklist for tool‑connected agents shows that tool‑level authorization is the only way to prevent irreversible actions, and the “guardrails before action” pattern emerged from teams that learned the hard way that output filtering is too late for side‑effecting tools.

Weak answer misses
The specific “guardrails before action” pattern from the guardrails layer description and the OWASP MCP Top 10 reference.


Q
Your reviewer wants to supply a custom human reply instead of letting the tool run or outright rejecting it. How does the system support that use case?

A
The reviewer uses the respond decision type in the Command.resume dictionary. The message field of that decision is returned directly to the agent as the tool result – the tool itself is never executed. This pattern is explicitly for “ask user” style tools where the real implementation is the human’s reply.

Follow-up
Does the respond decision also add the message to the conversation history as feedback, like reject does?
A
No – unlike reject, which adds the message as feedback to help the agent understand why the action was rejected, respond simply returns the message as the tool’s output without modifying the conversation state beyond that.

Weak answer misses
The distinction that respond bypasses tool execution entirely and returns the message directly as a tool result, vs. reject which adds feedback to the conversation.


Q
You have a multi‑turn agent that may need human approval at unpredictable points, and you want to evaluate whether the agent is abstaining (stopping) early enough after a rejection. How would you measure timely abstention in this setup, and what dimension of the interrupt mechanism matters?

A
Track the timely recall rate – the proportion of tasks where the agent stops acting after a rejection decision before performing unnecessary interactions. The context of agentic abstention shows that on WebShop, Llama‑3.3‑70B’s timely recall rose from 26.7 to 57.4 after using the CONVOLVE method. The key dimension is that each interrupt provides a decision (approve/reject/respond) and the agent must learn to stop after a reject instead of retrying with different tool calls.

Follow-up
Could a simple loop counter serve as an alternative to evaluating abstention quality?
A
No – the research shows that “the main challenge is not only whether agents can abstain, but also when they abstain”; some agents never abstain when they should or only abstain after many unnecessary interactions, which a loop counter would not detect.

Weak answer misses
The CONVOLVE method and the distinction between binary abstention vs. timely abstention (when they stop).


Q
When designing a multi‑agent system where subagents call tools that require human approval, should each subagent manage its own interrupt, or should a single gate centralize all approvals?

A
It depends on the pattern. In the handoffs pattern, agents transfer control via tool calls and each agent can hand off to others or respond directly to the user – each agent independently can have its own interrupt and resume logic. In the subagents pattern, a main agent coordinates subagents as tools, so the main agent’s interrupt is the natural central gate, while subagents themselves can still be paused by adding separate interrupts inside their own graphs.

Follow-up
If a subagent is paused for approval, does the main agent remain blocked until the subagent’s interrupt is resolved?
A
Yes – in the subagent pattern all routing passes through the main agent, so the main agent’s execution is blocked until the subagent’s tool call is either approved, rejected, or responded to through the subagent’s own interrupt mechanism.

Weak answer misses
The distinction between the handoffs and subagents patterns and how interrupts nest in the subagent architecture.

Failure modes

Lost Approval Decision

  • Trigger — The agent pauses for human review; the reviewer approves the tool call, but the approval record is not persisted in a durable journal. The agent restarts from an earlier checkpoint and the approval is missing from the transcript.
  • Guard — The runtime records the approval decision as a durable execution boundary (part of the run and step journal with a stable run_id and step_id). Without this recording, no guard exists; the source states “A human approval can be lost in a chat transcript” and that “durable execution addresses this class of problem by making progress recoverable.”
  • Posture — Fail‑soft: the agent continues but the approved action is never executed, degrading correctness.
  • Operator signal — The approval decision is absent from the journal; a subsequent run shows no record of the human input.
  • Recovery — The reviewer must re‑approve; no automatic retry because the original approval is lost.

Premature Tool Execution

  • Trigger — The approval gate is implemented as an output‑layer filter rather than a pre‑action authorization hook. The agent sends the tool call (e.g., an email or write query) before the guardrail can inspect and pause it.
  • Guard — The correct pattern is guardrails before action — authorization at the tool execution layer. The source warns: “By the time you filter the response, the agent already sent the email.” If this guard is absent, no real protection exists.
  • Posture — Fail‑hard: the mutating action executes without review, potentially causing irreversible harm.
  • Operator signal — A tool call that should have been paused runs immediately; the log shows the model’s output but no human‑approval event.
  • Recovery — Manual rollback required; no automatic compensation because the guard did not record the call.

Duplicate Approval Requests

  • Trigger — A transient network error causes the runtime to retry a tool call that already received human approval. The retry re‑triggers the same approval gate, and the reviewer sees a second identical request. Both approvals result in duplicate execution.
  • GuardIdempotent tool wrappers with idempotency keys and duplicate detection prevent the second execution. The source describes “a send‑message tool [that] should know whether a message with the same run and step key was already sent.”
  • Posture — Fail‑soft if idempotent wrappers exist (duplicate approved but not executed again); fail‑hard if missing (second execution may send a duplicate email or write).
  • Operator signal — Multiple approval‑pending events for the same run_id/ step_id; the retry count in the journal shows repeated calls.
  • Recovery — With idempotency, the second approval is ignored. Without it, manual cleanup of duplicate side effects is needed.

Indefinite Wait for Human Review

  • Trigger — The agent pauses for approval, but the reviewer does not respond (e.g., away, notification lost). No timeout or escalation is configured, so the agent blocks forever.
  • GuardDurable timers and awakeables (e.g., from Restate’s durable callbacks) allow the workflow to set a maximum wait and proceed with a fallback or abort.
  • Posture — Fail‑hard: the agent hangs, unable to continue the run.
  • Operator signal — The run remains in “waiting‑for‑approval” state indefinitely; no progress in the journal after the pause.
  • Recovery — A durable timer fires after a configurable timeout (source mentions “durable timers, … callback waits called awakeables”). The agent then either retries, escalates, or terminates the step.

Leaked Approval Credentials in Traces

  • Trigger — The approval gate includes session tokens, passwords, or reviewer‑identity information in the tool‑call arguments or model response. These are exported to tracing storage without redaction.
  • GuardRedact by default and sample aggressively, routing full‑fidelity traces only to restricted storage. The source says: “Production systems should redact by default, sample aggressively, and route full‑fidelity traces only to restricted storage.”
  • Posture — Fail‑closed: the agent continues, but secrets are exposed to unauthorized viewers.
  • Operator signal — Sanitized spans with correlation IDs and hashes; sensitive payloads absent from standard logs but present in restricted storage.
  • Recovery — Rotate credentials; no automatic recovery because the leak is already in the journal. Manual review of access logs is required.

Inconsistent Policy Enforcement

  • Trigger — The approval‑rule logic is written as custom policy code without a dominant framework (source: “This is the least mature layer in the stack… You’re writing policy code from scratch.”). Different agents or runs use ad‑hoc rules that sometimes skip the approval gate for certain tool calls.
  • Guard — The nearest conceptual guard is the authorizing tool calls pattern, but no specific identifier from the source handles inconsistency. The source explicitly notes “no dominant framework, no established patterns” so the guard is absent.
  • Posture — Fail‑soft: some dangerous tool calls are caught, others are not, leading to unpredictable behavior.
  • Operator signal — Audit logs show that a tool call that should have been paused (e.g., a write query) ran without an approval event.
  • Recovery — Manual inspection and re‑implementation of the policy; no automated fix because the rules are custom and not validated by the runtime.
STUDY AIDSevidence-backed memory techniques
Quiz

What does research show about the effectiveness of multiple guardrail approaches?

Options: combining multiple approaches works best · Privacy instructions are sufficient to prevent leakage · Unified evaluation protocols are already established · Safety filtering eliminates all risks

Show answer

combining multiple approaches works best

12. Evals And Observability

To know if an agent truly works, you need to evaluate more than its final answer. You must judge the sequence of tool calls and decisions it made along the way. That is called trajectory evaluation.

Teams use two main approaches. Offline evaluation runs fast checks on every pull request. Nightly regression suites test deeper with large language models that score output quality. Online evaluation monitors live traffic for performance drift. That continuous check catches regressions before users notice.

Large language models serve as scalable judges. They automatically score outputs and catch problems. But a panel of nine large language models provides only about two independent votes. Their errors are correlated. Adding more judges does not help much. The best single judge often matches the whole panel.

Tracing is essential for understanding failures. It records every step an agent takes. If step three picks the wrong tool, steps four through twelve are doomed from there. With a trace you can see exactly where the problem started. You can replay the steps and diagnose the failure. Local iteration becomes possible. The trace is stored in a file system and can be inspected with a simple command.

In 2026 trajectory evaluation has sharpened. Instead of one verdict over the whole trace you get span-level scores with reasons. That localizes the exact erroneous span inside the trajectory. You know which specific step went wrong instead of guessing.

The evaluation harness itself now works for coding agents. DeepEval version 4.0 provides command line tools. Agents like Claude Code can use them directly. The agent generates datasets by inferring the use case from the codebase. It runs tests with over fifty metrics. It inspects results from a local file. That closes the loop between evaluation and improvement. The agent no longer guesses what to fix. It gets told exactly what needs to change.

This combination of trace and span-level scoring makes agent evaluation reliable. You do not overfit to arbitrary metrics. Annotations align the metrics to what matters. Traces make sense of failing scores. Everything stays local for speed. Latency for streaming is nearly zero. The loop is fast. That is how you know an agent truly works.

Process reward calculation for trajectory evaluation.

python

# R_terminal is the terminal reward
# Process reward: best verifier state reached during episode
R_tilde = max(R_terminal, max(s_j))
In plain words

Think of evaluating an agent like checking a cook’s recipe process: you don’t just taste the final dish—you need to verify they cracked eggs before mixing and didn’t skip the baking step. This subsystem is for judging whether an agent’s sequence of tool calls and decisions (its trajectory) actually follows a sensible plan, not just whether its final answer looks right.

Teams use two main approaches. Offline evaluation runs fast, automated checks on every code change—like tasting a sample at each step—while nightly regression suites deploy a large language model as a scalable judge to score the whole trajectory against the intended steps. Online monitoring watches live traffic for performance drift, catching regressions before users feel them. Real mechanisms include the “Plan Phase Compliance” metric from the plan-following-gap study: it splits the agent’s actions into phases (e.g., navigate, reproduce, patch) and measures whether every required phase appears, in the right order, without extra unrelated steps.

The trickiest part is that agents can succeed by taking shortcuts that look fine but actually miss crucial reasoning. The “Plan Phase Fidelity” penalty specifically marks phases that appear outside the instructed alphabet—like opening a pull request before validation—even if the final patch works. Without this subsystem, agents would overfit to correct answers while ignoring process errors, so a seemingly successful agent might skip debugging entirely, then fail catastrophically when given a slightly different task.

System design

The evaluation subsystem operates as a three-tier pipeline where fast checks on every PR run first, nightly regression suites that use an LLM to judge output quality run next, and continuous production monitoring runs continuously to alert when agent performance drifts. On failure, the pipeline’s ordering is critical: if the PR check catches a bad trajectory, it blocks deployment before the nightly suite runs; if the nightly suite catches deeper regressions, the alert prevents them from reaching production users; if production monitoring detects drift, the operator can roll back before the agent performs enough steps to fail catastrophically. The design’s invariant—named implicitly as “trajectory-level evaluation” versus “final output evaluation”—is that the system must preserve a complete record of every tool call and decision made along the reason-act-observe loop, because if your eval only checks the final output, you’ll never know why. This is not a bound on correctness but a diagnostic requirement: without per‑step traces, a failed final answer is a black box.

The key trade-off is between the simplicity of final-output-only evaluation and the diagnostic power of trajectory-level evaluation. The obvious rejected alternative is to skip trajectory tracking entirely and rely solely on an LLM judge scoring the agent’s final answer—a pattern described as “most teams skip eval until something breaks in production. By then they’re debugging blind.” That rejection avoids the cost of debugging blind when a failure occurs, because the operator can look at the trace and see exactly which step doomed the rest of the trajectory (e.g., “step 3 picked the wrong tool, and steps 4–12 were doomed from there”). The price paid is the engineering overhead of instrumenting each step, storing state across 12+ steps, and maintaining separate eval frameworks for different agent behaviors—a non‑trivial cost that the source acknowledges: “switching eval frameworks means rebuilding your test suites.”

A concrete failure mode arises when an agent, during a multi‑step fix, selects a tool that violates the intended plan at step 3, causing all subsequent steps to be wasted or incorrect. The operator, logging in to the observability dashboard, sees a continuous production monitoring alert that “agent performance drifted” but initially no clear cause. Because the system only checked the final output (the patch), the operator sees a failed resolution but no indication of why. Only after deploying trajectory-level evaluation (fast checks on every PR that log every tool call) does the operator notice that the Langutory for that run contains an unknown phase—the agent executed a reproduction step before navigation, violating the plan‑compliant phase sequence. The invariant “trajectory-level evaluation” forces the logging of that phase mismatch, turning a blind failure into a pinpointed root cause: step 3’s tool call was not part of the instructed plan.

Interview Q&A

Pair 1 (Warm-up)

  • Q: Our agents are supposed to follow a plan. How do you measure whether they actually do, beyond just looking at the final pass@1?
  • A: Use phase flow analysis (Figure 4) to check the agent’s trajectory against the Standard plan sequence NRPV (Navigation → Reproduction → Patching → Validation). Even when no plan instruction is given, this analysis reveals whether agents follow that workflow or deviate, as shown in Finding 5.
  • Follow-up: What numeric measure captures the degree of deviation?
  • A: The PCPC score proportionally decreases for any missing phase, spurious phase, or ordering violation.
  • Weak answer misses: The exact ordered phases (Navigation, Reproduction, Patching, Validation) that define the ground truth sequence.

Pair 2 (Medium)

  • Q: Why do we need a dedicated trajectory evaluation metric like the Graphectory metric instead of relying on the final success rate alone?
  • A: Success rate only tells you if the task was completed, not how efficiently or coherently the agent reasoned. Finding 6 shows that under the no-plan setting, models like DeepSeek-R1 exhibit smaller Graphectory values, indicating premature convergence and less focused reasoning—details that raw success numbers hide.
  • Follow-up: How does the Graphectory metric differ from simple trajectory length?
  • A: It specifically captures reduced reasoning focus and premature termination, not just step count.
  • Weak answer misses: That the Graphectory metric was introduced in Finding 6 to quantify reasoning degradation when the plan is absent.

Pair 3 (Medium-Hard, design question)

  • Q: Why evaluate trajectory adherence to a rigid Standard plan rather than letting agents define their own optimal sequence and scoring them against that?
  • A: The fixed plan acts as a control to compare internalized strategies across models. Finding 5 shows that different LLMs internalize problem-solving differently—DeepSeek models reduce trajectories to NP patterns—so a common baseline reveals how scaffold design biases behavior. Also, plan mutations like step reordering (RQ4) allow systematic testing of which phases are essential.
  • Follow-up: But if the plan isn’t followed, is it still useful?
  • A: Yes—Finding 6 shows that the plan positively impacts local reasoning even when compliance is low, guiding agents toward better solutions.
  • Weak answer misses: The concept of “plan mutations” (e.g., removing reproduction, adding regression phases) as deliberate perturbations to test phase necessity.

Pair 4 (Hard)

  • Q: How do you evaluate an agent’s ability to stop acting when the goal is unachievable, as part of its trajectory?
  • A: The CONVOLVE method (from the agentic abstention paper) distills full interaction trajectories into reusable stopping rules via context engineering. It improves the timely recall rate—for Llama-3.3-70B, that rate rose from 26.7 to 57.4 on WebShop, showing that trajectory-level abstention can be learned without retraining the model.
  • Follow-up: What makes this different from a single‑turn abstention check?
  • A: Agentic abstention is a sequential decision problem; the need to abstain may only become clear after interacting with the environment.
  • Weak answer misses: That CONVOLVE uses trajectory distillation (not just prompt engineering) and that the metric is “timely recall,” not raw abstention frequency.

Pair 5 (Hard)

  • Q: Trajectory evaluation often ignores token cost per step. How do you incorporate efficiency into the evaluation loop?
  • A: The Mem0 evaluation framework includes token consumption per query and latency as dimensions alongside accuracy. For example, its new algorithm achieved 92.5% on LoCoMo with only 6,956 tokens/query, while full‑context baselines used ~26,000 tokens—a gain that directly impacts the feasibility of multi‑step agent trajectories.
  • Follow-up: Why can’t you just expand the context window to handle long trajectories?
  • A: The BEAM benchmark explicitly states that its tasks cannot be solved by expanding the context window, making token‑efficient retrieval essential for production‑scale deployment.
  • Weak answer misses: The exact benchmark scores (LoCoMo 92.5, BEAM 10M 48.6) and the metric “average tokens per retrieval call.”
Failure modes

Plan Phase Omission

  • Trigger — The agent skips a required phase such as reproduction or validation during the trajectory.
  • Guard — None identified in source. The evaluation pipeline computes the metric PCPC to detect missing phases, but no runtime guard prevents the omission or handles it during execution.
  • Posture — Fail-soft. The agent continues its task but with degraded plan compliance; the overall run is not aborted.
  • Operator signal — Lower PCPC scores specifically reflecting “missing phases,” as measured by the pipeline.
  • Recovery — Not specified in source. Manual inspection of the trajectory log is required to determine why the phase was skipped.

Spurious Phase Insertion

  • Trigger — The agent performs actions that are not part of the defined plan alphabet (e.g., opening a pull request after patch validation).
  • Guard — None identified in source. The metric PPF (Plan Phase Fidelity) penalizes the appearance of phases outside the alphabet, but there is no runtime guard that filters or rejects such actions.
  • Posture — Fail-soft. The task continues, but the trajectory is considered less faithful; the overall compliance score is reduced.
  • Operator signal — A lowered PPF value and the presence of “spurious phases” in the phase flow analysis.
  • Recovery — Not specified in source. The operator must analyze which extraneous actions caused the penalty and decide whether to adjust the plan or retrain the agent.

Tool‑Calling Failure (DeepSeek‑R1)

  • Trigger — The model persistently makes incorrect tool calls, driven by optimization for short‑term reward (reference to “Guo et al., 2025”).
  • Guard — None identified in source. No retry or fallback is documented; the errors lead directly to failure.
  • Posture — Fail‑hard. The agent’s trajectory aborts with a “very low success rate”; the task is not completed.
  • Operator signal — “Pervasive tool‑calling failures observed in 413 instances” and a “very low success rate” for DeepSeek‑R1.
  • Recovery — Not specified in source. Manual intervention is required—either switching to a different model or adding an explicit tool‑call retry loop outside the current scaffold.

Eval Coverage Gap

  • Trigger — The evaluation framework only checks the final output of the agent, ignoring the sequence of tool calls and decisions.
  • Guard — None identified in source. The source states: “If your eval only checks the final output, you’ll never know why.” No guard exists that enforces trajectory‑level evaluation.
  • Posture — Fail‑soft. The agent runs normally, but hidden failures in the trajectory go undetected, allowing regressions to reach production.
  • Operator signal — “Unknown reason why” – the operator sees a failed final answer but has no trace of the faulty steps.
  • Recovery — Not specified in source. The operator must manually inspect raw agent logs or implement a trajectory‑eval pipeline (e.g., using a plan‑compliance metric like PCPC).

Non‑Determinism in Evaluation

  • Trigger — Variations in environment or model behavior cause the same agent to produce different results across runs.
  • Guard — None identified in source. The source mentions “impact of non‑determinism” (§6.2) but does not define a guard that mitigates it during evaluation.
  • Posture — Fail‑soft. The evaluation continues, but the results are inconsistent, making it hard to attribute improvements or regressions.
  • Operator signal — “Unresolved issues due to nondeterminism” – instances where agents “rarely resolve previously unsolved issues” because of run‑to‑run variability.
  • Recovery — Not specified in source. Operators must run multiple trials or enforce deterministic seeding if supported, but no automated recovery is documented.

Plan Augmentation Destabilization

  • Trigger — Adding a new phase to the plan (e.g., a change‑summary phase) that the model has not internalized, leading to behavioral collapse.
  • Guard — None identified in source. No guard checks whether the model can handle the augmented plan; the added phase directly degrades performance.
  • Posture — Fail‑hard for models like DeepSeek‑R1, which exhibit “substantial performance drop” and “pervasive tool‑calling failures.” Other models (Devstral‑small, GPT‑5 mini) show fail‑soft degradation.
  • Operator signal — “Substantial performance drop” and “pervasive tool‑calling failures observed in 413 instances” for DeepSeek‑R1; near‑unchanged PCPC for others.
  • Recovery — Not specified in source. The operator must revert the plan to the baseline (standard) setting or isolate the added phase to avoid destabilization.
STUDY AIDSevidence-backed memory techniques
Explain & elaborate · explain why

Why does the multi-sample uncertainty method described in the section cluster tool call outputs by their abstract syntax tree parsing to localize errors at a span level rather than giving a single verdict over the whole trace?

13. Agentic RAG Whats Next

Retrieval-Augmented Generation, or RAG, is the standard pipeline. But now retrieval is becoming a loop where the model decides when to search and refines its own queries. This shift is driven by a key insight: you need to know what to look for before you can retrieve it. Long context can surface unexpected findings, but retrieval requires knowing what to look for. That is why multi-hop reasoning across a single document is hard with chunked retrieval. The relevant facts get split into different segments that never appear together.

Context engineering is the discipline of curating what enters the window. The model's effective attention is a limited resource. Spending it on content unlikely to help the query is never free. So teams must decide what fraction of their corpus is relevant to a typical query. When the relevance ratio drops below twenty percent, retrieval consistently outperforms stuffing everything in.

The economics of per query cost also matter. At tens of thousands of queries per day, a one thousand two hundred fifty times cost difference becomes the dominant constraint. Long context can take forty five seconds on average, which is incompatible with interactive applications. Even with context windows reaching a million tokens, brute force is not the answer. Treating long context as a general purpose replacement for retrieval is how teams end up with forty percent fact miss rates and surprise bills.

So where is the frontier? Retrieval and memory are converging into one loop. The same store is written, ranked, and decayed. Selective forgetting becomes part of the system. New algorithms like single pass hierarchical extraction and multi signal retrieval achieve high scores on benchmarks while using only six to seven thousand tokens per query. That is far less than the twenty six thousand tokens full context requires. Temporal queries and multi hop reasoning saw the biggest gains. These are exactly the categories that reflect real user histories, where facts accumulate and change over time.

But challenges remain. Temporal abstraction is still hard. A move from one city to another should be understood as evolution, not replacement. And application level evaluation is still manual. Benchmarks do not tell you how your system performs on your specific workload. The infrastructure for memory has expanded to cover many frameworks and vector stores. The open problems are specific and bounded, not fundamental. Curated retrieval, not brute force long context, will remain the substrate.

Using Mem0's memory client to add and retrieve user preferences — a simple retrieval loop.

python
from mem0 import MemoryClient
client = MemoryClient(api_key="your-key")
client.add("I prefer Python over JavaScript", user_id="aashi")
results = client.search("programming language preferences", user_id="aashi")
print(results)
In plain words

Think of an AI agent like a detective who doesn’t just look up a single clue and stop—they decide when to search again, refine the question based on what they find, and keep going until the case is solved. That’s what this subsystem does: it turns retrieval into a loop where the model itself chooses when to fetch more information and how to reformulate its search. It’s made for answering questions that need multiple steps, where the answer isn’t in one piece.

In practice, the model cycles through a think-act-observe pattern: it reasons about the task, decides to call a retrieval tool (that’s the “act”), then reads the result and observes what it got. If the answer isn’t complete, it loops. The source calls this the atomic unit of an agent. But the loop can’t just grab everything—it needs to curate what enters the model’s limited attention span. That curation is called context engineering: deciding what information each agent sees, as mentioned in the LangChain docs. The system also uses intelligent routing—for example, start with RAG for routine lookups and only use long context for rare, full-document understanding.

The hardest part is multi-hop reasoning: facts that are split across different chunks never appear together, so the model must connect them across separate retrievals. The Mem0 research shows this is exactly where traditional chunked retrieval falls short—their algorithm improved multi-hop reasoning by over 23 points. Without this loop, the model would give incomplete or contradictory answers because it never knew to look for the missing pieces.

System design

The retrieval loop in this design begins with query classification: the model reflects on whether the query is a factual lookup, synthesis task, comparison, or implicit exploration, using a mechanism termed "Self-Route" from EMNLP 2024. Based on this classification, the system estimates the fraction of the corpus likely to be relevant and routes the request accordingly—simple queries go to focused RAG, while complex multi-hop queries that require global understanding go to long context. Within the RAG path, the ordered mechanism follows LlamaIndex's "Small-to-Big Retrieval" pattern: first index fine-grained chunks for precise retrieval, then at inference time expand those chunks to larger surrounding context windows. On failure—for example, when retrieval returns no relevant chunks or the model judges the information insufficient—the loop can retry by refining the query or widening the retrieval scope, though the source cautions against over-fetching as a fallback.

The invariant the design preserves is a curated prompt: "curate what goes into the prompt. The model's effective attention is a limited resource." This guarantee ensures that no irrelevant material dilutes the model's reasoning. Concretely, the "order-preserving RAG approach with 48K well-chosen tokens" is the canonical implementation that upholds this invariant by tightly controlling which tokens enter the context window. The design explicitly rejects the obvious alternative of always using full-context retrieval without routing—a choice that leads to "context stuffing" where 30 chunks are retrieved because "there's room in the context window." That rejection avoids the lost-in-the-middle effect and a measured 13 F1 point drop compared to the curated 48K approach, while also cutting the token budget to roughly one-seventh of the stuffed alternative.

The key trade-off is between architectural simplicity and accuracy. A one-size-fits-all long-context pipeline is easier to implement but suffers from attention dilution and higher per-query costs as the context window is always fully loaded. The design chooses intelligent routing instead, accepting the overhead of a classification step and a two-phase retrieval pattern. This rejection of the "always stuff" alternative avoids the 1,250x cost difference that appears at tens of thousands of queries per day between long-context and RAG, while also sidestepping the degradation caused by context stuffing—the operator would see that benchmarks drop by 13 F1 points and token usage spikes because attention spreads across partially relevant material.

A concrete failure mode is when the retrieval layer over-fetches by default, retrieving 30 chunks instead of the curated top-3. The operator would observe two signals: first, a noticeable increase in token consumption per query (the 30-chunk prompt far exceeds the 48K sweet spot), and second, a degradation on standard benchmarks—the "order-preserving RAG approach" reports a 13 F1 point advantage over this stuffed condition at 117K tokens. The underlying symptom is the lost-in-the-middle effect, where facts that appear in the middle of the oversized context become inaccessible to the model. The operator would see logs showing high retrieval counts and a puzzling drop in answer accuracy even though raw recall (documents containing the answer) remained high.

Interview Q&A

Q — "Why can’t we use standard RAG for a user asking ‘what are the most concerning parts of this agreement?’ They haven’t specified a section—how does this challenge the pipeline?"

A — Standard RAG presupposes you can write a query, but this is an implicit query where the user doesn’t know which section is relevant. The source explicitly states: “Long context can surface unexpected findings; retrieval requires knowing what to look for.” This forces a loop where the model must decide when to search and refine its own probes, rather than relying on a static retrieval step.

Follow-up — “So how does the Self-Route mechanism handle such open-ended questions?”

One-line grounded answer — Self-Route classifies the query by type (e.g., implicit exploration) and routes it to long-context processing instead of simple RAG.

Weak answer misses — Fails to mention that without an explicit query, chunked retrieval cannot surface the relevant segments at all.


Q — “Why build an intelligent router that sends some queries to RAG and others to long context, instead of always using RAG for lower latency and cost?”

A — The Self-Route approach from EMNLP 2024 lets the model reflect on whether it needs full context or focused retrieval. This improves overall accuracy while cutting computational cost because simple factual queries go to RAG and complex multi-hop questions go to long context. The source shows that an order-preserving RAG with 48K well-chosen tokens outperforms full-context at 117K by 13 F1 points at one-seventh the token budget—proving that one-size-fits-all is suboptimal.

Follow-up — “What specific metric proves that routing is worth the overhead?”

One-line grounded answer — The 13 F1 point gain and 7× token reduction come from directly comparing the order-preserving RAG approach with full-context retrieval.

Weak answer misses — Leaves out the exact F1 improvement and the “one-seventh token budget” ratio, which are the strongest evidence for routing.


Q — “Why does chunk-based retrieval fail on multi-hop reasoning across a single document, and how does Small-to-Big Retrieval fix it?”

A — When an answer requires connecting facts from different parts of the same document, chunk-based retrieval may separate the relevant facts into different segments that never appear together. The source calls this the multi-hop reasoning problem for a single corpus. The Small-to-Big Retrieval pattern from LlamaIndex mitigates it by indexing fine-grained chunks for precise retrieval, then expanding to larger surrounding context windows at inference time, giving the model more reasoning breadth.

Follow-up — “What benchmark specifically measures this failure at million-token scale?”

One-line grounded answer — The BEAM benchmark at 1M and 10M tokens cannot be solved by expanding the context window, making it the most relevant test for production-scale multi-hop reasoning.

Weak answer misses — Ignores the lost-in-the-middle effect and the fact that overfilling context—even with RAG—dilutes attention and degrades performance.


Q — “Why not just replace RAG entirely with a 1M-token long-context model for knowledge tasks?”

A — The five governing factors—corpus size, relevance ratio, latency SLO, data freshness, and query volume—show that long context is a ceiling, not a floor. The source warns that treating 1M-token context as a general-purpose replacement leads to “40% fact miss rates, 45-second latencies, and AWS bills that surprise nobody.” For example, when the relevance ratio drops below roughly 20% , RAG consistently outperforms full-context stuffing due to the distraction effect, and the 45-second latency makes long context incompatible with interactive sub-2-second requirements.

Follow-up — “How does the relevance ratio actually drive the decision? Give the threshold.”

One-line grounded answer — When relevance ratio falls below 20%, RAG outperforms full-context because irrelevant content dilutes attention (the distraction effect).

Weak answer misses — Omits the 20% threshold entirely or fails to mention the distraction effect as the mechanism.


Q — “Why implement a retrieval loop where the model iteratively refines its own queries instead of a single static retrieval step?”

A — The core insight is that “you need to know what to look for before you can retrieve it.” The loop allows the model to adapt its queries based on initial results. The Self-Route mechanism operationalizes this by classifying query complexity and choosing retrieval depth. Moreover, Mem0’s single-pass hierarchical extraction and multi-signal retrieval algorithm achieved a +23.1 point gain on multi-hop reasoning, demonstrating that iterative refinement dramatically improves recall on tasks that require connecting facts across sessions or documents.

Follow-up — “What token efficiency metric proves this loop doesn’t become prohibitively expensive?”

One-line grounded answer — Mem0’s algorithm scored 92.5% on LoCoMo with only 6,956 average tokens per query, far less than full-context’s 26,000 tokens per conversation.

Weak answer misses — Fails to cite the specific token count (6,956 vs. 26,000) and the benchmark (LoCoMo) that quantifies the efficiency gain.

Failure modes

Failure 1: Retrieval Loop Plan Phase Skipping

  • Trigger – The model’s internalized strategy omits the Navigation phase and jumps to Reproduction before performing a proper codebase search, leading to repeated, wasted edits.
  • Guardperiodic plan reminders (the Standard plan is re-inserted every five steps to refocus the agent).
  • Posture – fail‑soft: success rate changes negligibly (38.3% to 38% after accounting for nondeterminism), but trajectory efficiency degrades.
  • Operator signalP​C score drops; P​P​F increases as phases outside the instructed plan appear in the Langutory.
  • Recovery – The automatic re‑insertion of the plan every five steps reduces drift; no manual step is required unless compliance remains low.

Failure 2: Canonicalization Failure of Retrieved Facts

  • Trigger – Adversarial test cases with identifier‑obfuscation (e.g., variable renaming) cause the retrieval pipeline to miss the canonical form of a stored fact.
  • Guardmutation‑time hook (inscribed at mutation time, recovers canonicalization with 100% accuracy).
  • Posture – fail‑soft without the guard (5% success); with the guard the system degrades and continues correctly.
  • Operator signalForgetEval score on the identifier‑obfuscation category is 5% when only deterministic primitives are used, and 100% when the mutation‑time hook is active.
  • Recovery – The mutation‑time hook automatically canonicalizes the fact; no manual intervention needed.

Failure 3: Guardrail Absence for Retrieval Tool Call

  • Trigger – The agent attempts a retrieval tool call that violates authorization policy (e.g., accessing restricted data) because no runtime guardrail has been implemented.
  • Guardguardrails before action pattern (a recognized pattern for enforcing authorization at the tool execution layer, but deployment is DIY and often absent in prototypes).
  • Posture – fail‑open: the agent proceeds without restriction, potentially causing harm.
  • Operator signal – Silent absence of any guardrail log; the first indication is a production incident report from users.
  • Recovery – Manual incident response and custom policy implementation; the NeMo Guardrails framework can be used to author rules from scratch.

Failure 4: Crash During Retrieval Without Durable Boundaries

  • Trigger – A worker crash occurs after a retrieval API call but before the response is recorded; without durable state the agent loses progress.
  • Guardctx.run‑style durable steps (Restate’s journaling mechanism) or the Temporal Workflow/Activity split (which separates deterministic orchestration from nondeterministic agent steps).
  • Posture – fail‑hard without the guard (abort and loss of progress); fail‑soft with the guard (resumes from the last recorded boundary).
  • Operator signalworkflow event history replay (Temporal) or journal replay (Restate) is invoked; the operator sees the agent resuming from the last durable step.
  • Recovery – Automatic replay of the journal or event history; no manual step required if the guard is in place.

Failure 5: Lexical/Temporal Forgetting Due to Reliance on LLM Memory Alone

  • Trigger – The system uses only inscribe‑time LLM for memory management, causing straightforward lexical or temporal facts (e.g., a filename or date) to be forgotten because the inscribe‑time call did not record them.
  • Guarddeterministic primitives (the source states they suffice for lexical/temporal categories).
  • Posture – fail‑soft: without deterministic primitives the fact is lost; with them the system retrieves correctly and continues.
  • Operator signalForgetEval score on lexical/temporal categories is 0% when only the LLM is used, and 100% when deterministic primitives are employed.
  • Recovery – Adding deterministic primitives (exact substring matching, timestamp checks) automatically recovers the fact; no manual step needed.
STUDY AIDSevidence-backed memory techniques
Spaced review

In a few days, come back and re-test yourself on these concrete ideas: how the model decides when to search and reformulates its own queries, the role of a domain detector in filtering distractions and verifying claims, and the practical token ceiling of 32,000 to 64,000 tokens for most models.

The learning science behind it

The agentic patterns this field guide surveys are not just engineering conventions — several of them are, structurally, working applications of memory science. Each lens below pairs one industry mechanism with the documented memory-science principle it mirrors, states the mechanism in plain terms, and links to the full write-up on the learning-science principles page. The prose is generated by LlamaIndex, grounded ONLY in that principles corpus — not paraphrased from memory.


Desirable difficulties works because effortful processing builds storage strength distinct from retrieval strength. In the self-healing agent loop, the deliberate re-verification and retry steps slow performance but force deeper processing of the failure information, making each correction more durable and reliable than a first-pass answer. This maps the principle onto the industry pattern.

Mirrors Self-Healing Systems

Machine-learning analog Curriculum learning

Bengio et al. (2009) · Bjork (1994) · Hwang et al. (2026) · Lee et al. (2026) · Shu et al. (2026)


The spacing effect makes memory stick because distributed practice—spacing repetitions over time—flattens the forgetting curve. A durable-execution engine that checkpoints workflow state and resumes after hours or days uses the same pattern: the long gap between suspension and resumption is spaced re-exposure, fighting loss of state just as spaced retrieval fights forgetting in human memory.

Mirrors Durable Execution

Machine-learning analog Experience replay (continual learning)

Cepeda et al. (2006) · Cepeda et al. (2008) · Ebbinghaus (1885) · Rolnick et al. (2019) · Settles & Meeder (2016) · Spens & Burgess (2024) · Xiao & Wang (2024)

Structure

Working memory is limited in chunks, not bits; recoding raw material into meaningful units multiplies capacity. Splitting a large task into a small set of distinct agent roles recodes the whole problem into a handful of bounded chunks, each fitting a context window, thereby circumventing the capacity limit. This orchestration pattern directly applies Chunking.

Mirrors Multi-Agent Orchestration

Machine-learning analog Subword tokenization (BPE)

Cowan (2001) · Elsner et al. (2026) · Ericsson et al. (1980) · Lee et al. (2025) · Miller (1956) · Sennrich et al. (2016)


The principle Elaboration and levels of processing holds that memory deepens with semantic processing—elaboration helps most when the cue makes the meaning recoverable. A panel of judge agents forces multiple, independent semantic elaborations of an answer, each building an integrated structure that surfaces connections and errors a single pass misses, exactly as deep processing yields durable traces.

Mirrors Judges Panels And Debate

Machine-learning analog Masked / self-supervised pretraining

Balepur et al. (2024) · Craik & Lockhart (1972) · Craik & Tulving (1975) · Devlin et al. (2019)


The mechanism that retrieval succeeds only when the cue was part of the original encoding makes memory stick. An agent memory system encodes context into a specific representation; when it later retrieves that fact, it uses the same encoded cue, ensuring the retrieval cue lands exactly where the trace was stored. This application of encoding specificity and transfer-appropriate processing guarantees the cue-trace match.

Mirrors How Agents Remember

Machine-learning analog Retrieval-augmented generation

Godden & Baddeley (1975) · Kang et al. (2025) · Lewis et al. (2020) · Tulving & Thomson (1973)


The bizarreness effect makes memory stick because unusual items receive more elaborative processing and are more discriminable at retrieval—but only when they are rare in their context. A guardrail system that flags outputs merely because they deviate from the system’s typical pattern applies this relative distinctiveness: catching the standout, rare output, not a banned one, mirrors the mixed-list advantage.

Mirrors Guardrails And Safety

Machine-learning analog Prioritized experience replay

Atzert et al. (2026) · Lee et al. (2024) · McDaniel & Einstein (1986) · Schaul et al. (2015)

The shared mechanism is that these principles are not arbitrary study tricks but general constraints for any system that must store and retrieve under interference. Encoding quality (principles 1–7) determines a trace’s starting strength, retrieval practice (9–10) grows that strength, spacing (8) determines whether growth compounds, and specificity (13) keeps the loop connected. A system combining them is more robust than any single pattern, as encoding without spaced retrieval fades, but together they ensure retention.

Explore the memory principles →