← Back to Guides

Companion to the book Building Real-World Agentic AI Systems with LangGraph · this part maps to Book Part I · Chapters 1–3

GuideFor: AI Engineers, ML Engineers, Platform Engineers, AI Systems Architects

LangGraph or a While Loop? You Already Have a Runtime

A checkpointer makes the run's past readable and leaves its next-step space exactly as wide as it was. Production agents fail in that gap.

Updated
#langgraph#agent-runtime#durable-execution#agent-control-flow#production-ai#state-management

16 November 2026: re-verified the graph code on langgraph 1.2.22 / langchain 1.5.0 / langchain-core 1.8.1. Added Temporal's LangGraph plugin (GA 30 October 2026), the vendor disagreement over whether checkpoints are durable execution, and create_agent's built-in call-limit and human-in-the-loop middleware. Re-ran the falsifiability test in the prior-art section, which now half-fails. Fixed two reference links, and drew a D2 diagram for each concept section. Thesis unchanged.

In July 2025, a coding agent on Replit deleted a live production database during an active code freeze. The freeze had been communicated to the agent, repeatedly, in writing. The agent then reported that rollback was impossible, which was also wrong, and the wrong report delayed recovery.

This is the argument for reaching for LangGraph instead of a hand-rolled while loop, and it is not that the loop is broken. It is that every agent already has a runtime, specified or not.

Sourcing first, because it matters for how hard I lean on this. The incident is reported by the affected user and corroborated by press coverage. Replit acknowledged it and apologised. There is no published engineering postmortem, so treat what follows as reported rather than as verified internal root cause.

That caveat cuts to the useful part. No public account describes the reachable action set that night, and the absence is the point. Nothing in the record suggests any mechanism existed that could have made destructive commands unreachable during the freeze. The freeze lived in the context window. A constraint had been written down, and nothing in the running system had been told to enforce it.

Note what Replit changed afterwards: development and production database separation, with staging databases. The remediation was a reachability constraint. The narration was about a disobedient agent; the fix was about what the agent could reach.

Nobody on that team thought they had shipped a runtime. They had, and its guarantees turned out to be whatever the code did that night.

The thesis: you cannot opt out of having a runtime

A while loop around a model call is not the absence of a runtime. It is a runtime whose guarantees were never specified.

Something in your system already decides what happens when the process dies mid-run. Something already decides whether a completed step can run twice. Something already decides which tools are reachable at step forty. In a hand-rolled loop, that something is not a design decision. It is whatever your code happened to do. I call this the Accidental Runtime: the runtime you shipped without deciding to build one, whose specification is the emergent behaviour of the code you wrote for other reasons.

So the real choice is not "framework or no framework." That argument is loud, and it is measuring the wrong axis. What separates these systems is whether the runtime was specified or inherited.

Here is the contested part:

Durable execution externalises the run's past. It leaves the next-step space exactly as wide as it was.

Checkpointing gives you resumption, replay, and a readable history, and none of that narrows what the agent may do next. Add a checkpointer to a hand-rolled loop and you largely address two of this series' three failure modes, lost state and no recovery, while the third, hallucinated control flow, does not move at all. (Largely, because naive checkpointing has its own gaps, which Part 4 takes apart.) Teams routinely read that as closing all three. I call the resulting condition Backward-Only Durability: the run's history is durable, and its reachable next step is still anything the model names.

Read the grid by row: each failure mode, as the bare loop handles it and as the loop with a checkpointer handles it. Only the bottom row stays red.

d2
classes: {
  hdr: {style: {fill: "#95A5A6"; stroke: "#6F7E7F"; font-color: "#2C2C2A"; bold: true}}
  mode: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  bad: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
  good: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
grid-rows: 4
grid-columns: 3
grid-gap: 10
h0: "Failure mode" {class: hdr}
h1: "Hand-rolled loop" {class: hdr}
h2: "Loop + checkpointer" {class: hdr}
m1: "Lost state" {class: mode}
m1a: "Message list dies\nwith the process" {class: bad}
m1b: "History persisted\n(gaps: Part 4)" {class: good}
m2: "No recovery" {class: mode}
m2a: "Restart from scratch" {class: bad}
m2b: "Resume and replay\nfrom the history" {class: good}
m3: "Hallucinated\ncontrol flow" {class: mode}
m3a: "Any bound tool,\nfrom any step" {class: bad}
m3b: "Any bound tool,\nfrom any step\n(unchanged)" {class: bad}

Not "backward" in the backward-error-recovery sense, where a system rolls back instead of repairing forward. The direction here is temporal: the durable object is the run's past, and the run's future is untouched.

What a hand-rolled agent loop actually guarantees

Here is Atlas, the customer-support agent this series builds. This is the version that ships first, because it works.

Identifiers used but not defined below live in the companion repository: TOOL_SCHEMAS and the tool implementations, load_messages and save_messages, the model and classifier handles, ticket_api, billing, render_context, checkpointer, DB_URL, session, and user_text. All code targets the LangGraph 1.x line. In November 2026 I re-ran the graph code on langgraph 1.2.22, langchain 1.5.0 and langchain-core 1.8.1 on Python 3.13.9, with stand-ins for the companion helpers (langchain 1.5 needs Python 3.11 or later). Only the Anthropic SDK and Postgres blocks are syntax-checked rather than run, since they need a live model or database. Every primitive used here (StateGraph, nodes, edges, conditional edges, checkpointers) predates 1.0 and carries no beta marker. One helper carries a constraint worth stating: render_context must tolerate the refund-path keys being absent, since the question path never sets them, and must treat them as stale unless the current turn set them.

python
# atlas/loop.py - the version that looks fine in reviewimport jsonfrom anthropic import Anthropicclient = Anthropic()TOOLS = {    "search_kb": search_kb,    "get_ticket": get_ticket,    "update_ticket": update_ticket,    "issue_refund": issue_refund,}def run(user_message: str, max_steps: int = 25) -> str:    messages = [{"role": "user", "content": user_message}]    for _ in range(max_steps):        response = client.messages.create(            model="claude-sonnet-5",            max_tokens=2048,            tools=TOOL_SCHEMAS,            messages=messages,        )        messages.append({"role": "assistant", "content": response.content})        tool_calls = [b for b in response.content if b.type == "tool_use"]        if not tool_calls:            return "".join(b.text for b in response.content if b.type == "text")        results = []        for call in tool_calls:            result = TOOLS[call.name](**call.input)            results.append({                "type": "tool_result",                "tool_use_id": call.id,                "content": json.dumps(result),            })        messages.append({"role": "user", "content": results})    raise RuntimeError("max steps reached")

There is nothing wrong with this code. It is competent, it is readable, and Thomas Ptacek is right that you should write one to understand what an agent is.

Now read one line as a specification rather than as code:

python
result = TOOLS[call.name](**call.input)

That line says: from any point in this run, any bound tool may execute next. issue_refund is reachable on step one, before any ticket is fetched and before any entitlement is checked. It is reachable on step twenty after the model has talked itself into a corner. There is no state in which it is unreachable, because there is no notion of state at all beyond a growing message list.

Here is that line as a table. Rows are steps of one run, columns are the four entries in TOOLS, and every cell is a tool that can be the next action at that step.

d2
classes: {
  hdr: {style: {fill: "#95A5A6"; stroke: "#6F7E7F"; font-color: "#2C2C2A"; bold: true}}
  open: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  danger: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
grid-rows: 4
grid-columns: 5
grid-gap: 8
c0: "TOOLS[call.name]" {class: hdr}
c1: "search_kb" {class: hdr}
c2: "get_ticket" {class: hdr}
c3: "update_ticket" {class: hdr}
c4: "issue_refund" {class: hdr}
s1: "step 1" {class: hdr}
s1a: "reachable" {class: open}
s1b: "reachable" {class: open}
s1c: "reachable" {class: open}
s1d: "reachable" {class: danger}
s20: "step 20" {class: hdr}
s20a: "reachable" {class: open}
s20b: "reachable" {class: open}
s20c: "reachable" {class: open}
s20d: "reachable" {class: danger}
s25: "step 25\n(max_steps)" {class: hdr}
s25a: "reachable" {class: open}
s25b: "reachable" {class: open}
s25c: "reachable" {class: open}
s25d: "reachable" {class: danger}

Absent an explicit mechanism, the transition relation of a loop like this is complete over the bound tool set. Every tool, from every point. (Not "total". In formal methods a total transition relation only means every state has some successor, which is nearly the opposite of what is happening here.) That is the narrow version of the claim, and the narrowness is the point. Four mechanisms narrow it without a graph, and they get their own section. This series grew into a book: Building Real-World Agentic AI Systems with LangGraph. Chapter 1, "The Agent Reliability Problem," builds a loop like this one and breaks it three ways on purpose, offline: an unbounded run, state lost on restart, and a tool failure swallowed into a false success.

Adding a LangGraph checkpointer: what it fixes and what it does not

The standard fix, and it is a real fix, is durability. Persist the run so a crash does not lose it.

python
def run(user_message: str, thread_id: str, max_steps: int = 25) -> str:    messages = load_messages(thread_id) or [        {"role": "user", "content": user_message}    ]    for _ in range(max_steps):        response = client.messages.create(            model="claude-sonnet-5",            max_tokens=2048,            tools=TOOL_SCHEMAS,            messages=messages,        )        messages.append({"role": "assistant", "content": response.content})        tool_calls = [b for b in response.content if b.type == "tool_use"]        if not tool_calls:            save_messages(thread_id, messages)            return "".join(b.text for b in response.content if b.type == "text")        results = []        for call in tool_calls:            result = TOOLS[call.name](**call.input)            results.append({                "type": "tool_result",                "tool_use_id": call.id,                "content": json.dumps(result),            })        messages.append({"role": "user", "content": results})        save_messages(thread_id, messages)  # durable now    raise RuntimeError("max steps reached")

This is a genuine improvement. The process can die and the run survives. An entire ecosystem exists because durable, resumable state is hard to get right: Temporal, Restate, DBOS, LangGraph's own checkpointers.

That last entry is contested, and the vendors disagree in public. Temporal's position is that "checkpoints are not durable execution" and that "The checkpoint preserves your data, not your execution": something still has to notice the dead process and restart the run. LangChain's answer is that LangSmith Agent Server is that something, with a task queue that hands a crashed run to another worker. Both are vendor framings. They agree on the part this article needs: a checkpointer, on its own, is a record of the past.

Now look at what did not change. TOOLS[call.name] sits there untouched, so the relation is still complete over the tool set. Durability bought you the history. On step forty it will still dispatch whatever the model names.

A later part has to fix two things here. The save happens after the whole tool batch, so a crash between issue_refund succeeding and save_messages returning loses the entire step: the tool call and its result. On resume the model is re-asked, and it will usually re-issue the refund, so the side effect happens twice with nothing recording that it did. And range(max_steps) restarts at zero on every resume, so a run that crashes repeatedly has no effective length bound at all. At-least-once side effects are the hard part of what the durable-execution vendors actually sell, and they are a Part 4 problem.

Follow the numbered edges through one crash. The red nodes are where the durable version still goes wrong.

d2
direction: down
classes: {
  step: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  save: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
  bad: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
  warn: {style: {fill: "#FFD93D"; stroke: "#C9A82E"; font-color: "#2C2C2A"}}
}
refund: "TOOLS[\"issue_refund\"](**call.input)\nmoney moves" {class: step}
crash: "process dies before\nsave_messages returns" {class: bad}
resume: "load_messages(thread_id):\nlast save predates the refund" {class: warn}
again: "model is re-asked and\nre-issues issue_refund" {class: bad}
reset: "range(max_steps) restarts at 0:\nno length bound across crashes" {class: save}
refund -> crash: "1. crash"
crash -> resume: "2. resume"
resume -> again: "3. same prompt"
again -> refund: "4. second refund"
resume -> reset: "also"

That is Backward-Only Durability, and the vendors are not hiding it. Restate's durable-agent post is titled "Fault Tolerance across Frameworks and without Handcuffs", and it positions durability as something you add without being forced into a structure: "Everything we show here is independent and orthogonal to any agent SDK." Read that carefully. The "handcuffs" are framework lock-in, not the agent's action space, so the title is not a confession about reachability. It is a statement about the same axis from the other end. A durability layer that imposed a control-flow model would be a worse product, so they correctly decline to impose one, and what they decline to impose is exactly the thing no other durability layer supplies either.

The problem is on the buying side. Buyers hear one word, reliability, and stop reading the datasheet.

The Temporal objection, and why it narrows the claim rather than defeating it

Anyone who has run Temporal in production will push back here, and they should. Temporal requires deterministic workflow code: the same input must produce the same sequence of workflow API calls. That sounds exactly like a constraint on the legal sequence of steps.

Temporal itself says otherwise, and published a post to say it:

"While Temporal requires that your Workflow code is deterministic, your AI Agent can absolutely make decisions based on non-deterministic LLM outcomes."

Temporal wrote that post because customers kept assuming the opposite, which makes them the vendor best positioned to observe this misconception in the wild. The mechanism is that Activities execute outside the replay path. Model calls and tool invocations are Activities, specifically so a non-deterministic choice does not blow up replay.

So the determinism requirement is a replay-consistency property over commands already issued. It constrains the past.

That is narrower than saying Temporal constrains nothing going forward, and the difference matters. A Temporal workflow body is a specified transition relation, enforced by the runtime with durable, automatically retried activities, plus signals and updates for out-of-band gating. Activities are at-least-once, not exactly-once, so idempotency stays yours to handle. DBOS workflows and Restate's virtual objects are specified transition relations in the same way. That is this article's first claim, arrived at from a different direction, and it is why Temporal shops rarely hit the failure described here. Part 8 returns to that comparison at the close of the series, against Temporal, DBOS, Convex and Microsoft Agent Framework, and turns it into a selection question: for each guarantee a runtime advertises, what is its unit of scope, and which artifact tells you?

The forward constraint came from the workflow code you wrote. Write an unconstrained loop inside the workflow and durability will not put the constraint back.

Since 30 October 2026 the two runtimes can be stacked as well as compared. Temporal's LangGraph integration, generally available by Temporal's own announcement, runs a StateGraph as a Temporal Workflow, and every node must declare execute_in as either "activity" or "workflow". (The integration's docs page still carried a Public Preview banner when I checked on 16 November.) That is the orthogonality made literal. Temporal supplies the durability, to the point that its docs say "third-party checkpointers (like PostgreSQL or Redis) are not needed." The edge set you wrote in LangGraph still supplies the reachability. What the plugin changes is where each node runs and what survives a crash, not which node may run next. Both sources are Temporal's.

Look at what each layer owns in the stacked version: the outer container is Temporal's, and the inner one is yours.

d2
direction: down
classes: {
  node: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  route: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  owns: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  dur: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
}
wf: "Temporal Workflow (replayed, deterministic)" {
  label.near: top-center
  style: {fill: "#EAF7F3"; stroke: "#5FA898"; font-color: "#2C2C2A"}
  durability: "Temporal owns: retries, timeouts,\nresume after a crash" {class: dur}
  g: "LangGraph StateGraph" {
    label.near: top-center
    style: {fill: "#EEF4FC"; stroke: "#2C6FB0"; font-color: "#2C2C2A"}
    model: "model node\nexecute_in: \"activity\"" {class: node}
    router: "conditional edge\n(your routing function)" {class: route}
    tool: "tool node\nexecute_in: \"activity\"" {class: node}
    reach: "You own: which node\nmay run next" {class: owns}
    model -> router
    router -> tool
  }
  durability -> g.model: "wraps every\nactivity node"
}

What Anthropic's multi-agent writeup shows about durability versus control flow

The best public exhibit is Anthropic's writeup of their multi-agent research system, because it is first-party and because durability was demonstrably in place.

They describe "retry logic and regular checkpoints" as deliberate deterministic safeguards. They state that agents "can resume from where the agent was when the errors occurred." Durability: present, working, designed.

In the same document, the control-flow failures are described separately and are not solved by any of it:

  • "early agents made errors like spawning 50 subagents for simple queries"
  • given one research task, "one subagent explored the 2021 automotive chip crisis while 2 others duplicated work investigating current 2025 supply chains"
  • "one step failing can cause agents to explore entirely different trajectories, leading to unpredictable outcomes"

Put the two halves of the writeup side by side: what was in place on the left, what still happened on the right.

d2
grid-rows: 1
grid-gap: 30
classes: {
  good: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  bad: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
dur: "Durability: in place" {
  label.near: top-center
  style: {fill: "#EEF9F0"; stroke: "#3F9E52"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  a: "retry logic and\nregular checkpoints" {class: good}
  b: "resume from where\nthe errors occurred" {class: good}
  c: "full production tracing" {class: good}
}
cf: "Control flow: not prevented" {
  label.near: top-center
  style: {fill: "#FDEDEB"; stroke: "#B03A2E"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  x: "50 subagents for\nsimple queries" {class: bad}
  y: "two subagents duplicating\none investigation" {class: bad}
  z: "one failed step sends\nthe run down a new trajectory" {class: bad}
}

Checkpoints did not prevent 50 subagents. They recorded that it happened. Those are different properties, and the gap between them is the whole argument.

I wanted to make a sharper claim than this one, and it would have been wrong. Durability is not useless against bad control flow. It makes a bad trajectory legible and replayable, which is a precondition for diagnosing it and then constraining it. Anthropic added full production tracing for exactly that reason. Durability makes bad control flow legible, not unreachable.

Constraining the next-step space with LangGraph StateGraph

The fix is to make the reachable next step a property of the system rather than a hope about the model.

python
from typing import Annotated, Literal, NotRequired, TypedDictfrom langchain.messages import AnyMessage, HumanMessage, SystemMessagefrom langgraph.graph import StateGraph, START, ENDfrom langgraph.graph.message import add_messagesfrom pydantic import BaseModelclass Triage(BaseModel):    """The only control-flow choice the model is allowed to make."""    intent: Literal["refund", "question"]    ticket_id: str | Noneclass AtlasState(TypedDict):    # Supplied by the caller at invoke() time. The model never writes this.    customer_id: str    messages: Annotated[list[AnyMessage], add_messages]    # Everything below is model-written or derived from a model-written field.    intent: NotRequired[Literal["refund", "question"]]    ticket_id: NotRequired[str | None]    refund_cents: NotRequired[int]    refund_allowed: NotRequired[bool]    receipt_id: NotRequired[str | None]def triage(state: AtlasState) -> dict:    """The model classifies the request. It picks an intent, not a next node."""    decision = classifier.with_structured_output(Triage).invoke(state["messages"])    return {"intent": decision.intent, "ticket_id": decision.ticket_id}def lookup_ticket(state: AtlasState) -> dict:    # Scoped to the caller. Raises if the ticket is not theirs.    ticket = ticket_api.get(state["customer_id"], state["ticket_id"])    return {"refund_cents": ticket["amount_cents"]}def check_entitlement(state: AtlasState) -> dict:    allowed = billing.refund_allowed(        state["customer_id"], state["ticket_id"], state["refund_cents"]    )    return {"refund_allowed": allowed}def issue_refund(state: AtlasState) -> dict:    receipt = billing.refund(        state["customer_id"], state["ticket_id"], state["refund_cents"]    )    return {"receipt_id": receipt["id"]}def answer(state: AtlasState) -> dict:    # State carries the facts; render_context turns them into a system message.    # Nothing here is a tool result, so there is no orphaned tool-call handshake.    context = SystemMessage(content=render_context(state))    return {"messages": [model.invoke([context, *state["messages"]])]}

The routing lives on edges, where you can read it. The Literal return annotations are load-bearing: LangGraph uses them (or an explicit path_map) to know a conditional edge's possible targets. Drop them and it has to assume the function could return any node name.

python
def after_triage(state: AtlasState) -> Literal["lookup_ticket", "answer"]:    if state["intent"] == "refund" and state.get("ticket_id"):        return "lookup_ticket"    return "answer"def after_entitlement(state: AtlasState) -> Literal["issue_refund", "answer"]:    return "issue_refund" if state["refund_allowed"] else "answer"builder = StateGraph(AtlasState)builder.add_node("triage", triage)builder.add_node("lookup_ticket", lookup_ticket)builder.add_node("check_entitlement", check_entitlement)builder.add_node("issue_refund", issue_refund)builder.add_node("answer", answer)builder.add_edge(START, "triage")builder.add_conditional_edges("triage", after_triage)builder.add_edge("lookup_ticket", "check_entitlement")builder.add_conditional_edges("check_entitlement", after_entitlement)builder.add_edge("issue_refund", "answer")builder.add_edge("answer", END)graph = builder.compile(checkpointer=checkpointer)

The schema is making a claim. Read which state fields the model may write: intent and ticket_id come from the model. customer_id comes from the caller at invoke() time and the model never touches it. That separation is what gives every call site the caller's identity to scope against: a model-supplied "refund ticket 88213" is evaluated together with customer_id rather than on its own. The enforcement itself still lives inside ticket_api.get, which is the same class of invariant as the one in the loophole section below, and enforceable the same way. A state schema that does not separate those two origins is ambient authority wearing a TypedDict, and the guarded edge above would be checking the wrong subject.

The model still chooses. triage is a model call, and its output decides whether the run heads toward a refund or toward an answer. What changed is the size of the set it chooses from. It emits one of two intents, and the system decides what each intent reaches.

The sloppy version of this sentence is wrong, so be precise. issue_refund is still reachable from START. Reachability is transitive, and the path runs triage → lookup_ticket → check_entitlement → issue_refund. What it has is a guarded mandatory predecessor: a single inbound source whose edge is guarded by state, not merely a node that every path happens to pass through. There is no edge into issue_refund except from check_entitlement, and that edge is taken only when refund_allowed is true. Every path to a refund goes through the entitlement check. No prompt wording changes that, because no prompt is consulted at the gate.

Compare that to TOOLS[call.name], where issue_refund has a predecessor that guards nothing.

This example is deliberately acyclic, because a graph you can read in one screen makes the point better than a realistic one. Real graphs have cycles, and a skeptic is entitled to ask whether the guarantee survives them. It does. A cycle widens the set of states from which a node is reachable, and it does not add an inbound edge. The guarded mandatory predecessor is a property of the edge set, not of the path length, so looping does not create a new way into the refund. That is the property to hold on to when Part 2 puts the cycles back.

Below, the refund step is drawn twice: once as the loop reaches it, once as the graph reaches it. Find the red node and the green node, then read the edge that enters each one.

On the left, the single edge into the refund is unguarded, and its source is a dispatch on a string the model emitted. Every completed tool returns to the model, which dispatches again, so there is no state in which that edge is closed. On the right there is also one edge in, but a named function over state decides whether it is taken, and the only way to reach that function is through an entitlement check. Guardedness is the difference, not arrow count.

d2
grid-rows: 1
grid-gap: 40
classes: {
  model: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  logic: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  tool: {style: {fill: "#95A5A6"; stroke: "#6F7E7F"; font-color: "#2C2C2A"}}
  danger: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
  safe: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  out: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
}
inherited: "Inherited: one edge in, no guard" {
  label.near: top-center
  style: {fill: "#FDEDEB"; stroke: "#B03A2E"; font-color: "#2C2C2A"}
  m: "Model names\na tool" {class: model}
  d: "Dispatch on\ntool name" {class: logic}
  a1: "search_kb" {class: tool}
  a2: "get_ticket" {class: tool}
  a3: "update_ticket" {class: tool}
  a4: "issue_refund" {class: danger}
  m -> d
  d -> a1
  d -> a2
  d -> a3
  d -> a4
  a1 -> m: {style.stroke-dash: 3}
  a2 -> m: {style.stroke-dash: 3}
  a3 -> m: {style.stroke-dash: 3}
  a4 -> m: {style.stroke-dash: 3}
}
specified: "Specified: one guarded edge in" {
  label.near: top-center
  style: {fill: "#EEF9F0"; stroke: "#3F9E52"; font-color: "#2C2C2A"}
  triage: "triage\n(model picks intent)" {class: model}
  lookup: "lookup_ticket" {class: model}
  check: "check_entitlement" {class: logic}
  refund: "issue_refund" {class: safe}
  answer: "answer" {class: out}
  triage -> lookup: "refund + ticket_id"
  triage -> answer: "otherwise"
  lookup -> check
  check -> refund: "refund_allowed"
  check -> answer: "not allowed"
  refund -> answer
}

Both of those systems can be fully durable. Durability is the other axis. In the API the two are separate arguments, literally:

python
from langgraph.checkpoint.postgres import PostgresSaver# from_conn_string is a context manager, not a constructor - it does not# return a checkpointer you can pass straight into compile().with PostgresSaver.from_conn_string(DB_URL) as checkpointer:    checkpointer.setup()          # once, at deploy time: creates the tables    graph = builder.compile(checkpointer=checkpointer)    # Every graph.invoke() must happen inside this block. For a long-lived    # server, build PostgresSaver over a connection pool you own instead.    graph.invoke(        {"customer_id": session.customer_id, "messages": [HumanMessage(user_text)]},        config={"configurable": {"thread_id": session.thread_id}},    )

The invoke shape carries the security property. customer_id is required by AtlasState, but a TypedDict is a type-checker guarantee and not a runtime one - LangGraph will not reject an input that omits it. Leave it out and the question path succeeds silently while the refund path dies on a bare KeyError inside lookup_ticket. If you want that enforced at invoke time rather than at review time, use a Pydantic state schema. Which is the article's own argument turned on itself: a constraint that lives only in a type annotation is enforced by whoever remembers to run the type checker.

Reachability is specified by add_edge and add_conditional_edges. Durability is specified by one keyword argument to compile(). They are independent inputs to the same object. You can compile a tightly constrained graph with no checkpointer, and you can compile a graph with no constraints at all and pass it a production-grade checkpointer. That second configuration is the hand-rolled loop with durability bolted on, the failing one, and LangGraph will build it for you without complaint.

The consequence nobody states: reachability is reviewable before the run

Here is what falls out of the orthogonality, and it is the practical reason to care about any of this.

When control flow lives in a function body, the only way to know whether issue_refund is reachable from step one is to reason about the code. When it lives in an edge set, it is data. The compiled graph can hand it back to you:

python
print(graph.get_graph().draw_mermaid())

Be careful about what that output is, because it is easy to oversell and I nearly did. The property is conditional, and the condition is worth stating exactly.

For a rendering where the routing targets are all declared - Literal annotations or an explicit path_map on the routing functions, any Command returns annotated Command[Literal[...]], and xray=True wherever a subgraph is embedded - the output is a sound over-approximation of the transition relation: an upper bound on which node can run after which. It shows that an edge from check_entitlement to issue_refund exists. It does not show the body of after_entitlement, so it cannot tell you when that edge is taken. A routing function that returns "issue_refund" unconditionally draws the identical picture. That is imprecision, and imprecision inside an upper bound is safe.

Two things break the bound itself, in the dangerous direction:

  • An unannotated Command(goto=...) creates a transition the picture does not contain. When that is in play the diagram stops bounding the transition relation at all.
  • get_graph() collapses a subgraph into a single box unless you pass xray=True. Since create_agent embeds as a subgraph, one tidy node can contain an unconstrained loop.

Send is easy to lump in with those two and it does not belong there. Send does not remove a node from the picture: its targets are declared node names, so a map-reduce fan-out still draws an edge to the worker. What Send removes is cardinality. One drawn edge can mean N concurrent instances of that node, each fed a payload that is not the graph state. The picture still bounds which nodes run. It stops bounding how many, and with what input.

Here is each case against what the printed graph still tells you. Green rows keep the upper bound, red rows break it.

d2
classes: {
  hdr: {style: {fill: "#95A5A6"; stroke: "#6F7E7F"; font-color: "#2C2C2A"; bold: true}}
  what: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  ok: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  partial: {style: {fill: "#FFD93D"; stroke: "#C9A82E"; font-color: "#2C2C2A"}}
  alt: {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
  broken: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
grid-rows: 6
grid-columns: 2
grid-gap: 10
h1: "In the graph" {class: hdr}
h2: "What draw_mermaid() shows" {class: hdr}
r1: "Routing declared:\nLiteral or path_map" {class: what}
r1v: "Sound upper bound: the edge\ncheck_entitlement -> issue_refund exists" {class: ok}
r2: "Guard body:\nafter_entitlement" {class: what}
r2v: "Not drawn: when the edge is taken.\nAnswer it with a unit test" {class: partial}
r3: "Send fan-out" {class: what}
r3v: "Which nodes, yes.\nHow many and with what input, no" {class: alt}
r4: "Unannotated\nCommand(goto=...)" {class: what}
r4v: "A transition the picture\ndoes not contain: bound broken" {class: broken}
r5: "Subgraph without\nxray=True" {class: what}
r5v: "One box can hide an\nunconstrained loop: bound broken" {class: broken}

So the artifact is only as good as the discipline that produces it. Annotate the routing functions, annotate the Command returns, and pass xray=True when subgraphs are involved. Do that and you have an upper bound on the transitions the run can take. Skip it and you have a picture.

An upper bound is still worth a great deal, because the only bound the loop offers is the trivial one. And the guard you cannot see in the diagram has a property the loop's dispatch never had: after_entitlement is a named, importable, unit-testable function. "When is this edge taken" is answerable by a test, not by squinting at a rendering.

The durability discourse has no analogue for either artifact. A checkpointer produces a record of what happened, readable after the fact, usually while something is on fire. An edge set states what may happen, and a reviewer can reject it on a Tuesday before anything runs. Research on statically verifying agent workflow graphs is starting to formalise the difference, precisely because runtime guardrails cannot catch a topology defect that a structural check can.

Which is why, for a graph-shaped agent, question 2 in the audit below can be answered with a printed upper bound and a testable guard. For the loop, you can print list(TOOLS), and that is the complete answer: all of them, always. Nobody prints it, because nobody thinks of it as a specification.

Why a guarded edge does not stop a node calling billing.refund() directly

The edge set constrains transitions between nodes. It constrains nothing about what a node body does. Nothing in the graph, in compile(), or in the printed diagram stops answer from calling billing.refund() directly. Chapter 3 of my book, "Thinking in Graphs," turns this into a rule for node bodies: a node reads state, returns what changed, and leaves the next step to an edge, because a node that fires a side effect and picks its own successor makes the drawn graph lie.

So the honest statement is narrower than "the refund is unreachable." The node named issue_refund has a guarded mandatory predecessor. The operation of refunding does not. I replaced "trust the model not to emit issue_refund" with "trust the developer to keep billing.refund() inside the issue_refund module." Both are trust, and this article's own standard says a constraint someone is expected to honour is not a constraint.

Follow the red edge: it is the one the edge set cannot see, running from a node body straight into the billing module, around the guard.

d2
direction: down
classes: {
  node: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  logic: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  safe: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  out: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
  money: {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
}
graph: "Edge set" {
  label.near: top-center
  style: {fill: "#EEF4FC"; stroke: "#2C6FB0"; font-color: "#2C2C2A"}
  check: "check_entitlement" {class: logic}
  refund: "issue_refund" {class: safe}
  answer: "answer" {class: out}
  check -> refund: "refund_allowed"
  check -> answer: "not allowed"
  refund -> answer
}
op: "billing.refund()\n(billing module)" {class: money}
graph.refund -> op: "intended call"
graph.answer -> op: "direct call: nothing\nin the graph stops it" {style: {stroke: "#E74C3C"; stroke-width: 3; stroke-dash: 4; font-color: "#B03A2E"}}

What changed is the class of guarantee. In the loop, the constraint depended on a model's runtime behaviour, which you cannot unit-test and cannot review. In the graph, it depends on a static property of code: side effects on billing live in exactly one module. That is the same class of invariant as "no raw SQL outside the repository layer," and we already know how to enforce that class: import boundaries, a lint rule, a test that asserts the call graph. You have not eliminated trust. You moved it from a runtime hope to a property a reviewer and a CI job can check.

Adopting LangGraph does not by itself buy you a specified runtime. LangChain's own documentation defines create_agent as "a model calling tools in a loop." That is the loop, with a better harness around it. You can inherit the Accidental Runtime inside the framework just as easily as outside it. create_agent's middleware can add enforced gates, such as HumanInTheLoopMiddleware on an irreversible tool or a guard in wrap_tool_call, but each one is something you write in, and the default is the loop. The primitive that buys you reachability as a printable artifact is the edge set, and nothing hands it to you for free.

Why recursion_limit is not a control-flow guarantee

But the loop already has a bound, and this is where most readers stop me. max_steps in the hand-rolled version, recursion_limit in LangGraph, ModelCallLimitMiddleware and ToolCallLimitMiddleware in create_agent, max_iterations elsewhere.

Those bound how far the run can go. They say nothing about where it can go.

One configuration looks like an exception. ToolCallLimitMiddleware(tool_name="issue_refund", run_limit=0) blocks every refund call. In a scripted run on langchain 1.5.0 the tool body never executed, and the model got back "Tool call limit exceeded. Do not call 'issue_refund' again." That is real narrowing, enforced outside the model. It is also all-or-nothing for the whole run. It can switch a tool off, and it cannot say "only after the entitlement check."

The framing is not mine. It belongs to whoever filed this LangChain issue, in the project's own tracker:

"Current safeguards (recursion/tool-call limits) only cap total steps. They do not detect stuck states."

Their reproduction is a tool called with invalid arguments, failing validation, and being called again with invalid arguments, repeating until the iteration ceiling. LangChain closed the issue on 5 June 2026, when the maintainers declined the middleware for core (status as of 16 November 2026); the observation is not. A parallel LangGraph issue shows a text-to-SQL agent cycling through three tools until it hits "Recursion limit of 20 reached without hitting a stop condition." That reporter notes the same configuration did not loop on 0.6.x, so it may well be a regression rather than an architectural property. The relevant part is that the ceiling was the only thing that stopped it.

Three bounds, side by side. Each container shows what that bound fixes about the run and what it leaves open.

d2
grid-rows: 1
grid-gap: 30
classes: {
  open: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  stop: {style: {fill: "#FFD93D"; stroke: "#C9A82E"; font-color: "#2C2C2A"}}
  off: {style: {fill: "#95A5A6"; stroke: "#6F7E7F"; font-color: "#2C2C2A"}}
  logic: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  safe: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
length: "Length bound" {
  label.near: top-center
  style: {fill: "#FFF9E0"; stroke: "#C9A82E"; font-color: "#2C2C2A"}
  s1: "step 1: any tool" {class: open}
  s2: "step 2: any tool" {class: open}
  sn: "step N: ceiling,\nrun stops" {class: stop}
  s1 -> s2
  s2 -> sn: "..."
}
zero: "Per-tool run_limit=0" {
  label.near: top-center
  style: {fill: "#F2F4F4"; stroke: "#6F7E7F"; font-color: "#2C2C2A"}
  any: "any step: search_kb,\nget_ticket, update_ticket" {class: open}
  blocked: "issue_refund:\nblocked all run" {class: off}
  any -> blocked: "a call to it:\nblocked"
}
shapeb: "Shape bound" {
  label.near: top-center
  style: {fill: "#EEF9F0"; stroke: "#3F9E52"; font-color: "#2C2C2A"}
  lookup: "lookup_ticket" {class: open}
  check: "check_entitlement" {class: logic}
  refund: "issue_refund" {class: safe}
  lookup -> check
  check -> refund: "only if\nrefund_allowed"
}

These are length bounds where you need a shape bound. A length bound is a cardinality limit on a relation that is still complete over the tool set. It guarantees the run stops, and guarantees nothing about what the run does before it stops. We cannot say whether any step ceiling would have helped at Replit. The public record never ties the destructive command to a step count. A length bound is the one safeguard whose usefulness you cannot assess without a trace, and there was no trace.

(Stopping conditions are a separate problem with a failure mode of their own, which I wrote about in the oracle problem and build step by step in the free Loop Engineering course.)

Prior art: admissible action sets and invalid action masking

An RL person reading this far is already annoyed, and they have a point.

The distinction between what an agent knows about the past and which actions are admissible right now is not new. It is textbook Reinforcement Learning (RL), where the history and the admissible action set A(s) are separate objects in the standard formulation. Restricting that set has a standard name, invalid action masking, and a literature going back years.

Masking and an edge set do not do the same job. Masking narrows what a policy can sample, inside the model. An edge set narrows what the runtime will execute, regardless of what the model sampled. That gap is why one of them survives a jailbreak.

The security people got here first, from a third direction, and they have the closer analogy. TOOLS[call.name] is ambient authority over the whole tool set. A state-scoped edge set is capability scoping. Saltzer and Schroeder wrote least privilege down in 1975, and what is new is only that we rebuilt ambient authority on purpose, because the loop was fifteen lines and it worked.

Three traditions, one distinction. Compare where each one puts the restriction, at the bottom of each column.

d2
grid-rows: 1
grid-gap: 30
classes: {
  concept: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  inside: {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
  outside: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  bad: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
rl: "RL" {
  label.near: top-center
  style: {fill: "#F3F1FD"; stroke: "#5A4BC4"; font-color: "#2C2C2A"}
  a: "history and admissible\naction set A(s) are\nseparate objects" {class: concept}
  b: "invalid action masking:\ninside the policy,\nwhat it can sample" {class: inside}
  a -> b
}
sec: "Security (1975)" {
  label.near: top-center
  style: {fill: "#F3F1FD"; stroke: "#5A4BC4"; font-color: "#2C2C2A"}
  a: "ambient authority:\nTOOLS[call.name]" {class: bad}
  b: "capability scoping:\nleast privilege" {class: outside}
  a -> b: "narrow to"
}
rt: "Agent runtime" {
  label.near: top-center
  style: {fill: "#F3F1FD"; stroke: "#5A4BC4"; font-color: "#2C2C2A"}
  a: "checkpointer: the past\nedge set: the next step" {class: concept}
  b: "edge set: outside the model,\nwhat the runtime will execute" {class: outside}
  a -> b
}

The distinction is old. My claim is narrower and, I think, still true:

The agent-infrastructure discourse collapsed the two, and needs them separated again. Durable-execution writing is careful and rigorous about the history. It mentions the other property only in the negative, as a constraint it declines to impose. Very little of it names the missing thing, gives it a handle, or tells the buyer to go specify it somewhere else. So the two get sold under one word, "reliability", and bought as one property. An RL researcher would never confuse them. An engineer adding a Postgres checkpointer to a production agent on a Thursday does it routinely.

That is a falsifiable claim, and it is the one I would most like to be wrong about. Produce durable-execution material that names the admissible action set as a separate thing the reader still has to go and specify, and this paragraph fails.

I re-ran that test in November 2026, and it half-failed. LangChain's runtime guide, published in April 2026, three months before this article, puts durable execution and guardrails in separate rows and sends the second to middleware:

Not every production concern can be expressed as "run the loop durably." Some have to shape the loop itself: intercepting model inputs, filtering tool outputs, enforcing limits on expensive operations.

Temporal's LangGraph announcement draws the same line from the other side: "LangGraph is an agent framework: a way to define what your agent does." So the division of labour is in vendor material, and I missed it. The admissible action set is still not. LangChain's worked examples are PII redaction and a cap on paid API calls, a filter and a length bound, and neither post names which action may come next as a thing to specify. So the narrow half of the claim stands, and the "nobody" in it does not.

Dex Horthy's 12-factor-agents is instructive here. Factor 8 is "Own your control flow." Factors 5, 6, and 12 are durability arguments: unified state, launch/pause/resume, the stateless reducer. He arrives at my conclusion from the anti-framework direction, which I take as strong support. But the factors sit in a list, separately numbered, and nothing says why the separation is load-bearing.

Viren Baraiya, in "Late-Bound Sagas", also argues the loop is not a runtime, then concludes that the workflow graph should be synthesised by the model at runtime rather than declared in advance. That is close to the opposite of my position, and I think he is wrong about it. Declaring the graph in advance is what makes the guarantee a guarantee, and a graph the model writes at runtime is a graph nobody reviewed. His underlying problems, liveness and out-of-band control, are genuine ones I do not solve here.

Do LangChain middleware and tool_choice make LangGraph unnecessary?

"Complete over the bound tool set" is precise, and it is only true absent other mechanisms. Several mechanisms narrow the next-step space without any graph at all:

  • Provider-side tool_choice can force, restrict, or forbid a tool call on a given turn.
  • Tool schemas reject malformed arguments. This is real narrowing, and it is what produces the validation loop in the LangChain issue above.
  • LangChain 1.x middleware hooks into the agent loop at before_model, after_model and wrap_tool_call, and can_jump_to lets a hook end the run early. The prebuilt catalogue includes HumanInTheLoopMiddleware, an enforced gate that pauses chosen tools for a human decision before they run. LLMToolSelectorMiddleware narrows the tool list too, but a model does the narrowing, which fails the test below.
  • A precondition guard inside the tool body, which is what most teams actually ship: if not ctx.checked_ok: return {"error": "entitlement not verified"}, where ctx is whatever ad-hoc object the codebase happens to pass around.

That fourth one is the strongest counter to this whole article. It constrains the next-step space. It is enforced outside the model. It costs three lines. Anyone who has shipped an agent with an irreversible action has written it.

Here is what it does not give you. The guard is scattered across N tool bodies. It is invisible to any artifact a reviewer can print. Its precondition reads an ad-hoc context object with no schema, so nothing checks that ctx.checked_ok was set by an actual check. And nothing at all tells you when you forgot one on the tool you added last sprint. That is a specified runtime with no specification document, which is a real thing that works right up until the team changes.

Middleware takes back two of those objections. One wrap_tool_call middleware can hold every guard in one place, and it reads typed agent state and runtime context from the request instead of an ad-hoc ctx, so the scattering and the missing schema are fixable inside create_agent. What it still is not is an edge set. The guard is a function body, so the reachable next step is something you reason about, not something you print.

So these are not edge cases. They are shipping features, and someone using them well may have a perfectly well-specified agent with no StateGraph anywhere. The book's Chapter 2, "The LangGraph Ecosystem in 2026," builds Atlas's first correct version on create_agent for that reason, and only drops to a raw StateGraph once a requirement calls for a custom topology.

I do not think this weakens the thesis. I think it is the thesis. Every one of those mechanisms is an act of specifying the runtime. Reaching for guardrail middleware is conceding that the loop's default reachability was wrong for your system. The disagreement is about where the specification lives, not whether you need one. What you cannot do is skip it and call the result simple.

The line is enforcement, not intent. A mechanism specifies the runtime if the constraint holds regardless of whether the model complies. tool_choice is enforced by the provider, a schema by the validator, an edge by the graph, a precondition by the interpreter. A sentence in the system prompt is enforced by nothing, which is exactly why the Replit code freeze was a request. That is the test, and it is what makes this thesis falsifiable rather than a definition that swallows everything.

Applied to every mechanism in this section, the test sorts them like this. Its middle column decides whether each one is a constraint, and its right column whether a reviewer can print it.

d2
classes: {
  hdr: {style: {fill: "#95A5A6"; stroke: "#6F7E7F"; font-color: "#2C2C2A"; bold: true}}
  mech: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  yes: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  no: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
  neutral: {style: {fill: "#FFD93D"; stroke: "#C9A82E"; font-color: "#2C2C2A"}}
}
grid-rows: 8
grid-columns: 3
grid-gap: 8
h1: "Mechanism" {class: hdr}
h2: "Enforced by" {class: hdr}
h3: "Printable as an edge set?" {class: hdr}
m1: "tool_choice" {class: mech}
e1: "the provider" {class: yes}
p1: "no" {class: neutral}
m2: "tool schema" {class: mech}
e2: "the validator" {class: yes}
p2: "no" {class: neutral}
m3: "wrap_tool_call guard,\nHumanInTheLoopMiddleware" {class: mech}
e3: "the middleware runtime" {class: yes}
p3: "no: a function body" {class: neutral}
m4: "precondition in\nthe tool body" {class: mech}
e4: "the interpreter" {class: yes}
p4: "no: one per tool" {class: neutral}
m5: "LLMToolSelectorMiddleware" {class: mech}
e5: "a model: fails the test" {class: no}
p5: "no" {class: neutral}
m6: "sentence in the\nsystem prompt" {class: mech}
e6: "nothing: a request" {class: no}
p6: "no" {class: neutral}
m7: "StateGraph edge" {class: mech}
e7: "the graph" {class: yes}
p7: "yes: get_graph()" {class: yes}

So the recommendation, with the caveat attached: if your agent's action set contains nothing irreversible, the loop's defaults may genuinely be fine, and Ptacek's fifteen lines are the right answer. The moment one reachable action moves money, mutates a production record, or contacts a customer, the defaults are a decision you did not make.

A five-question agent runtime audit

Run this against any agent you have in production. It takes about twenty minutes, and it does not require adopting anything.

  1. List every action that is irreversible. Refunds, writes to production, outbound mail, deletes, anything with a side effect outside your process. If the list is empty, stop - you are fine.
  2. For each one, name the states from which it can be the next step, and name its guarded mandatory predecessor. If the next-step answer is "any step of the run", or if the single inbound source guards nothing, you have an inherited runtime, whatever framework is in your imports. If you cannot produce that answer as an artifact (a printed edge set, a schema, a policy file), assume it is "any".
  3. Find where that constraint is written down. If it is in the system prompt, it is a request. If it is in the edge set, a schema, or a guardrail hook, it is a constraint. The Replit code freeze was a request.
  4. Separate your bounds. Write down your length bound (recursion_limit, max_steps) and your shape bound separately. Most teams have the first and no second. A missing shape bound is not a smaller version of a length bound, and neither of them bounds what the model may see, which is a third bound with its own failure mode. Add a fourth, width - how many tasks one dispatch may create - if your graph fans out with Send.
  5. Kill the process mid-run and see what happens. Then check what the agent does on resume. Durability answers this question. It answers only this question. Do not let a clean resume convince you that question 2 is handled.

Each question on the left, and what its answer tells you to do on the right.

d2
grid-rows: 5
grid-columns: 2
grid-gap: 20
classes: {
  q: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  stop: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  warn: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
  act: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  alt: {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
}
q1: "1. List every irreversible action" {class: q}
a1: "Empty list: stop, you are fine" {class: stop}
q2: "2. Which states reach each one?\nWhat is its guarded predecessor?" {class: q}
a2: "\"Any step\", no guard, or no artifact:\nan inherited runtime" {class: warn}
q3: "3. Where is the constraint written?" {class: q}
a3: "System prompt: a request.\nEdge set, schema, hook: a constraint" {class: act}
q4: "4. Write down each bound separately" {class: q}
a4: "Length, shape, context;\nwidth if you fan out with Send" {class: act}
q5: "5. Kill the process mid-run" {class: q}
a5: "Fails: add a checkpointer (Part 4).\nPasses: says nothing about question 2" {class: alt}
q1 -> q2
q2 -> q3
q3 -> q4
q4 -> q5

If questions 1 through 4 pass and question 5 fails, you need a checkpointer, and Part 4 of this series goes deep on them. If question 5 passes and question 2 fails, you have Backward-Only Durability, and no amount of additional durability work will touch it.

What constraining an agent's next-step space costs

Constraining the next-step space is not free, and the trade is real. A fixed edge set is one you have to change when requirements change. A model that could previously improvise its way around a gap now hits a wall, and the wall is your problem to move.

Here is the cost, in the same example, so it is not an abstraction. Atlas's edge set has no path back to lookup_ticket once check_entitlement has run. A message that names two tickets, or names the wrong one, commits the whole run to whichever id triage extracted. There is no way back inside that run. The loop would have called get_ticket again mid-trajectory and been right, without ceremony. I removed an edge, and with it a recovery the model was performing for free.

The second cost is subtler and it comes from the same schema. refund_cents, refund_allowed, and receipt_id persist on the thread. A later turn that routes straight to answer still sees them, so render_context has to treat every refund-path field as stale unless the current turn set it. The loop had no such state to go stale, because it had no state at all. Structure is not free, and both of these are the bill.

Both costs on Atlas's own graph: the edge that is not there on the left, the state that outlives its turn on the right.

d2
grid-rows: 1
grid-gap: 30
classes: {
  node: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  logic: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  stale: {style: {fill: "#FFD93D"; stroke: "#C9A82E"; font-color: "#2C2C2A"}}
  out: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
}
c1: "Cost 1: no way back" {
  label.near: top-center
  style: {fill: "#FDEDEB"; stroke: "#B03A2E"; font-color: "#2C2C2A"}
  triage: "triage\nextracts one ticket_id" {class: node}
  lookup: "lookup_ticket" {class: node}
  check: "check_entitlement" {class: logic}
  triage -> lookup
  lookup -> check
  check -> lookup: "no such edge:\nsecond ticket id" {style: {stroke: "#E74C3C"; stroke-dash: 4; font-color: "#B03A2E"}}
}
c2: "Cost 2: stale state" {
  label.near: top-center
  style: {fill: "#FFF9E0"; stroke: "#C9A82E"; font-color: "#2C2C2A"}
  t1: "turn 1, refund path sets\nrefund_cents, refund_allowed,\nreceipt_id" {class: node}
  t2: "turn 2: triage -> answer,\nthe fields are still on the thread" {class: stale}
  rc: "render_context treats them\nas stale unless this turn set them" {class: out}
  t1 -> t2: "same thread_id"
  t2 -> rc
}

There is evidence the trade is worth taking where the work is consequential. StateFlow, which imposes explicit state-machine control flow, reported 13% higher success than a ReAct-style loop on InterCode SQL and 28% higher on ALFWorld, at roughly five times and three times lower cost. Benchmarks are not your production system. The sharper caveat is that StateFlow is a 2024 paper measured on 2024-generation models, where the structure was partly compensating for weaker planning. Whether that gap narrows as models improve, or whether the cost advantage persists regardless, is an open question nobody has re-run.

State the cost side flat. Every constraint you add is a place the system can be wrong in a new way, and an over-constrained agent is its own recognisable failure. This series argues for tuning that dial per decision rather than per system, with the setting determined by the cost of being wrong.

Why there is no public data on agent failure causes

I looked for public data on how production agent failures split between reasoning failures and control-flow or state failures. It does not exist in any form I would cite. Everything that appeared to offer that split turned out to be generated content with unsourced numbers.

The gap is the finding. We are three years into building these systems, the incident stories are vivid and public, and nobody has published the denominator. Until someone does, "most agent failures are state failures" is a claim from experience, held by a lot of practitioners, and not a measured fact. I hold it, and it is not measured.

Specified or inherited: the only question that matters

Your agent has a runtime. You did not opt out by writing a loop, and you did not opt in by importing a framework. The only question is whether its guarantees were specified or inherited.

Durability specifies the past. It is necessary and it is hard. It is also not sufficient: a durable run whose transition relation is complete over the tool set will faithfully replay its way to the same wrong action. Reachability specifies the future, and it lives in a different part of the API, which is why it gets skipped.

The Replit agent's code freeze was written down. DROP was reachable anyway. Everything else in this series is about closing the distance between those two sentences.

Part 2 takes on what this part conspicuously avoided. The graph here is acyclic and single-threaded, which is why the edge set stayed easy to read. Real graphs have cycles and branches that write the same key at the same time, so Part 2 covers reducers under concurrent writes, Command and Send, subgraphs, and what happens to that printable upper bound once all three are in play.

Going deeper

  • The hand-rolled loop and its three failure modes: Chapter 1, "The Agent Reliability Problem"
  • Where create_agent sits relative to LangGraph, and when to drop to a raw StateGraph: Chapter 2, "The LangGraph Ecosystem in 2026"
  • Pinning the langgraph and langchain versions this code was verified on: Chapter 2, "The LangGraph Ecosystem in 2026"
  • Why control flow belongs on edges rather than in node bodies: Chapter 3, "Thinking in Graphs"
  • Why the graph's shape decides whether a run can resume after a crash: Chapter 3, "Thinking in Graphs"

References


Agentic AI

Follow for more technical deep dives on AI/ML systems, production engineering, and building real-world applications:


Books by Ranjan Kumar

Federated AI Agents cover

Federated AI Agents

Right-Sized AI cover

Right-Sized AI

Harness Engineering for Production AI Systems cover

Harness Engineering

The 7 GenAI Architectures cover

The 7 GenAI Architectures

Building Real-World Agentic AI Systems with LangGraph cover

Building Real-World Agentic AI Systems

The ChatML Handbook cover

The ChatML Handbook

The Chat Templates Handbook cover

The Chat Templates Handbook

Comments