It is late afternoon. The broker's email has been through seven steps: the address is verified, the property record is read, the underwriting rules say "quote, high band". In step 8 the model asks for send_reply. The harness does not send it, because a reply to a broker needs an underwriter's approval, and the underwriter has gone home.
The answer comes the next morning. During the night the service was redeployed, as it is most nights, and the process that held this run no longer exists.
With the thirty-line agent from The loop, that is the end of the story. The whole run was a Python list in a local variable. The three tool calls, the four model calls and the drafted reply are gone, and nothing recorded that a run was ever waiting. And had the model kept asking for tools, nothing in those lines would have stopped it.
A run is a row with a status, and a process is something that visits it. Every exit from the loop has a name, and every step ends with a save. Code decides both. The model decides neither.
These are jobs 3 and 4 of the eight: control flow, and state, memory and durability. Job 3 says when the loop stops and why. Job 4 says where a stopped run continues.
1. Two things the short loop cannot say#
The loop function in agent_minimal.py is twelve lines, and two of them matter here. One is while True:. The only thing that can end that loop is a response from the model whose stop reason is not tool_use. The other is messages = [...], a list created inside the function. That list is the run. When the function returns or the process dies, the list is gone.
So the short loop is missing two things. The first is a second authority over the loop. The model can say "I am finished". Nothing else can say "you have used enough" or "this needs a person".
The second is a place outside the process where the run lives. One call showed that the model keeps nothing between two calls. That has a useful consequence: the message history, plus a few counters, is everything there is to know about a run. If that is saved, any process can continue the run at any time.
Two words need a fixed meaning first. A turn is one model call plus the tool calls it asked for. A step, in the miniature, is smaller: one model call, or one batch of tool calls. The run in the opening had reached turn 4 and step 8. A limit is set on turns. A save is keyed on steps.
2. A loop in which every exit has a name#
The function below is run from examples/quote-email/harness.py. It is the same loop as the twelve lines, with a status in place of while True. It shows where each stop is decided and where the save happens. It proves nothing about a real model; it shows the order in which code checks things.
def run(db: sqlite3.Connection, model, state: dict, *, approve: bool = False,
crash_after: int | None = None, verbose: bool = False) -> dict:
"""Job 3: the loop. One step is one model call or one batch of tool calls."""
caller = Caller(**state["caller"])
if state["status"] in ("waiting_approval", "paused:model_unavailable"): # a resume continues these
state["status"] = "running"
while state["status"] == "running":
if over_budget(state): # stop: token budget (job 7)
state["status"] = "stopped:token_budget"
elif pending_tool_calls(state):
state["step"] += 1
tool_step(db, state, caller, approve, verbose) # may stop: waiting_approval (job 5)
elif state["turn"] >= state["max_turns"]: # stop: max turns
state["status"] = "stopped:max_turns"
else:
state["step"] += 1
model_step(model, state, caller, verbose) # may stop: done, refusal, invalid, paused
if crash_after == state["step"]:
raise SystemExit(f"simulated crash in step {crash_after}, before its checkpoint. "
f"Continue with: --resume {state['run_id']}")
checkpoint(db, state) # durability (job 4)
return state
Each pass does one of four things, and then saves. The crash_after lines exist only so that section 4 can simulate a crash at a chosen step.
Look at the order of the four branches. The token budget is checked first, so a run that has spent too much stops before it spends more. Pending tool requests come next, before the turn limit. That placement is deliberate: the turn limit is checked only when the next thing to do is a model call, so a stopped run never ends on a tool request that nobody answered.
Each check that ends the loop is a stop condition: a rule in code that ends the loop and records why. The record is the status. The miniature has seven, in four families.
Diagram: Every way the loop in the miniature can end · and whether it can continue
Read left to right. The first column is the loop. Each other column is a family of exits, and each box is one status the run can end with. The name of the status tells the next person what to do. Click any box.
- The loop
- One step, then a checkpoint: The run function does one model call or one batch of tool calls, then saves the whole state.
- Finished
- done: The model ended its turn and the answer passed the output contract.
- Stopped by a limit
- stopped: max_turns: The turn counter reached the limit before the model finished. Code set this status, not the model.
- stopped: token_budget: The tokens used so far reached the budget for one run.
- Stopped by the answer
- stopped: refusal: The model's stop reason was neither a tool request nor a normal end. The status carries that stop reason.
- failed: invalid_output: The final answer did not match the output contract, and the one repair attempt did not fix it.
- Paused, can continue
- waiting_approval: The model asked for send_reply and no person has approved it. The request is saved in the checkpoint.
- paused: model_unavailable: Every retry and the fallback model failed. The steps done so far are saved.
The table says where each status is set and what can happen next.
| Status | Set in | What happened | Can the run continue? |
|---|---|---|---|
done | model_step | The model ended its turn and the answer passed the output contract | It is finished |
stopped:max_turns | run | The turn counter reached the limit, 8 by default | No. A person looks at it |
stopped:token_budget | run | The tokens used reached the budget, 60,000 by default | No. A person looks at it |
stopped: plus a stop reason | model_step | The model's stop reason was neither tool_use nor end_turn, for example refusal or max_tokens | No. A person gets the reason |
failed:invalid_output | model_step | The answer failed the output contract, and one repair attempt did not fix it | No. A person looks at it |
waiting_approval | tool_step | The model asked for send_reply and no person has approved | Yes, with an approval |
paused:model_unavailable | model_step | Every retry and the fallback model failed | Yes, when the provider is back |
Two things in this table are easy to confuse. A stop reason belongs to one response: it is the model's field that says why it stopped writing, and One call lists its values. A stop condition belongs to the run: it is the harness's decision. model_step reads the first to make the second. Even done is decided by code: when the model ends its turn, model_step checks the answer against the output contract before it writes done. Guardrails covers that check, and Reliability and cost covers the budget and the retries.
The turn limit can be seen at work by lowering it. With the miniature's --max-turns option set to 2, the same email ends like this.
{
"run_id": "run-a3270496",
"status": "stopped:max_turns",
"decision": null,
"reply": "none",
"turn": 2,
"tokens": 1320
}
There is no decision, and the status says exactly why. Where does the default of 8 come from? This email needs five turns: four that ask for a tool and one that answers. The limit is the normal path plus room for a correction or two. It is a number for this example, not a recommendation.
3. The run as a row#
Now the second missing thing. The three functions below are the whole of job 4 in the miniature: checkpoint, load_checkpoint and start_run from harness.py. They show that saving a run is one database write and continuing it is one read. They do not protect against repeating a side effect; section 4 shows why that needs something more.
def checkpoint(db: sqlite3.Connection, state: dict) -> None:
"""Job 4: save the whole run state after every step. The model remembers nothing; this row does."""
db.execute("INSERT OR REPLACE INTO checkpoints VALUES (?, ?, ?, ?)",
(state["run_id"], state["step"], state["status"], json.dumps(state)))
db.commit()
def load_checkpoint(db: sqlite3.Connection, run_id: str) -> dict:
"""Job 4: resume = load the newest checkpoint and enter the same loop."""
row = db.execute("SELECT state FROM checkpoints WHERE run_id = ? ORDER BY step DESC LIMIT 1", (run_id,)).fetchone()
if not row:
raise SystemExit(f"no checkpoint found for {run_id}")
return json.loads(row[0])
def start_run(db: sqlite3.Connection, email: str, caller: Caller, max_turns: int = MAX_TURNS,
token_budget: int = TOKEN_BUDGET) -> dict:
"""Create the state for a new run and save checkpoint 0."""
run_id = "run-" + hashlib.sha256(f"{email}{time.time()}".encode()).hexdigest()[:8]
state = {"run_id": run_id, "caller": asdict(caller), "email": email, "status": "running", "step": 0,
"turn": 0, "tokens": 0, "repairs": 0, "max_turns": max_turns, "token_budget": token_budget,
"tainted": bool(screen_untrusted(email)), "reply": "none", "decision": None,
"messages": [wrap_email(email)]}
checkpoint(db, state)
return state
Read start_run as a list of what a run is: an id, created before the first model call; the caller and the email; the message history; the counters that the stop conditions read and the limits they are compared with; and the status. Nothing else exists, and all of it is plain data that can be written as JSON.
That saved copy is a checkpoint: everything the run needs to continue, written outside the process after a step. checkpoint writes one row per run and step. load_checkpoint reads the row with the highest step number.
The important design choice is in what is missing: there is no recovery function. Resuming a run means loading the newest row and calling run, the same loop that a new run enters. A separate recovery path is a path that is exercised only on bad days. Here the bad day and the normal day run the same code.
4. Four runs, and what each one proves#
Everything below was run against the scripted model, with no network, from examples/quote-email. Run ids differ on every run.
The run stops at the approval gate#
This command runs the broker's email as an underwriter, without an approval. It shows a run that stops for a named reason and leaves a complete record. A successful run proves that the process can exit while the run stays resumable. It does not prove anything about who is allowed to approve.
/opt/homebrew/bin/python3 harness.py --fake --verbose
{"run_id": "run-7b49f7c9", "step": 1, "turn": 1, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 61, "output_tokens": 31, "cache_read": 0, "latency_ms": 0}
{"run_id": "run-7b49f7c9", "step": 2, "turn": 1, "kind": "tool", "tool": "verify_address", "verdict": "allow", "is_error": false, "latency_ms": 0}
{"run_id": "run-7b49f7c9", "step": 3, "turn": 2, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 145, "output_tokens": 31, "cache_read": 526, "latency_ms": 0}
{"run_id": "run-7b49f7c9", "step": 4, "turn": 2, "kind": "tool", "tool": "lookup_property", "verdict": "allow", "is_error": false, "latency_ms": 0}
{"run_id": "run-7b49f7c9", "step": 5, "turn": 3, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 227, "output_tokens": 42, "cache_read": 526, "latency_ms": 0}
{"run_id": "run-7b49f7c9", "step": 6, "turn": 3, "kind": "tool", "tool": "check_underwriting_rules", "verdict": "allow", "is_error": false, "latency_ms": 0}
{"run_id": "run-7b49f7c9", "step": 7, "turn": 4, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 328, "output_tokens": 51, "cache_read": 526, "latency_ms": 0}
send_reply is waiting for a human. Continue with: --resume run-7b49f7c9 --approve
{
"run_id": "run-7b49f7c9",
"status": "waiting_approval",
"decision": null,
"reply": "waiting_approval",
"turn": 4,
"tokens": 3020
}
Seven trace lines, then the stop. Step 7 is the model asking for send_reply. Step 8 has no trace line because no tool ran. The first lines of tool_step show why.
def tool_step(db: sqlite3.Connection, state: dict, caller: Caller, approve: bool, verbose: bool) -> None:
"""Run every tool the model asked for and send all results back in one user message."""
calls = pending_tool_calls(state)
verdicts = [authorize(caller, call["name"], state, approve) for call in calls] # permissions (job 5)
if "wait" in verdicts: # pause the run; a human resumes it later with --resume RUN_ID --approve
state.update(status="waiting_approval", reply="waiting_approval")
return
This is the start of the function, not all of it. The model asks, the harness decides and calls, the tool does. Here the harness decides not to call yet. It sets a status and returns, run saves the state, and the process ends.
After the command returned, the checkpoints table in runs.sqlite held these rows for the run.
| Step | Status | Size of the saved state |
|---|---|---|
| 0 | running | 659 bytes |
| 1 to 7 | running | 823 to 1,968 bytes |
| 8 | waiting_approval | 1,989 bytes |
Row 8 is the run. It holds the email, eight messages, the counters, and as its last message the model's unanswered request for send_reply. It is under two kilobytes, and it can wait for a minute or for a month.
The underwriter answers the next day#
This command is what the approval triggers. It shows a new process continuing a run it has never seen. A successful run proves that the row was enough.
/opt/homebrew/bin/python3 harness.py --fake --resume run-7b49f7c9 --approve --verbose
{"run_id": "run-7b49f7c9", "step": 9, "turn": 4, "kind": "tool", "tool": "send_reply", "verdict": "allow", "is_error": false, "latency_ms": 1}
{"run_id": "run-7b49f7c9", "step": 10, "turn": 5, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "end_turn", "input_tokens": 430, "output_tokens": 37, "cache_read": 0, "latency_ms": 0}
{
"run_id": "run-7b49f7c9",
"status": "done",
"decision": {
"decision": "quote",
"missing_fields": [],
"reasons": [
"eligible; flood zone AE"
],
"premium_band": "high"
},
"reply": "sent",
"turn": 5,
"tokens": 4013
}
The run continues at step 9, not at step 1, and the token count goes on from 3,020. Trace the path through run: the loaded status is waiting_approval, so the first lines set it back to running. The last message still holds the pending tool request, so the loop goes to tool_step. The gate is asked again, this time with an approval, and answers allow.
Diagram: A run that waits for a person · the row waits, no process does
Time runs down the page. The first process stops at the approval gate, saves the run and exits. The next day a different process loads the row and continues from the same step. Click any step.
- Harness, first process to Run database: Save step 7: the model asked for send_reply. The tool request is the last message in the saved history. Nothing has been sent.
- Harness, first process: Step 8: this tool needs approval. The gate before every tool call answers: wait. The harness does not run the tool.
- Harness, first process to Run database: Save step 8: waiting_approval. The status says why the run stopped and what it is waiting for.
- Harness, first process: The process exits. Nothing stays in memory. A deploy or a restart during the night loses nothing.
- Underwriter to Harness, second process: Next day: approve this run. The answer arrives with the run id. That id is the only handle needed.
- Harness, second process to Run database: Load the newest row for the run. load_checkpoint reads the row with the highest step number.
- Run database to Harness, second process: The state at step 8. The email, the whole message history, the counters, the limits and the pending tool request.
- Harness, second process: Step 9: send the reply, once. The same loop runs. It finds the pending tool request, asks the gate again, and this time the answer is allow.
- Harness, second process to Run database: Save steps 9 and 10: done. The model reads the tool result and returns the final decision. The last row has the status done.
This is why a pause for a person is a state problem before it is anything else. Waiting for a person who answers in a minute or in two days is called human in the loop, and it needs three things that have nothing to do with approval rules: the pending request saved somewhere durable, an id that the answer can carry, and a status that says what the run is waiting for. Which actions need a person, and who may approve them, are permission questions for Guardrails. In the miniature the approval is a command-line flag, which is enough to show the pause and far too little for a real gate.
The process dies after the email is sent#
A wait is the kind case: the run chose its stopping point. A crash chooses for you. The next command approves the reply in advance and simulates a crash in step 8, after the email is sent and before the checkpoint for that step is written. That is the worst moment for a save to be missing.
/opt/homebrew/bin/python3 harness.py --fake --approve --crash-after 8 --verbose
The first seven lines are the same seven steps as before, with a new run id. The output ends like this.
{"run_id": "run-72967328", "step": 8, "turn": 4, "kind": "tool", "tool": "send_reply", "verdict": "allow", "is_error": false, "latency_ms": 0}
simulated crash in step 8, before its checkpoint. Continue with: --resume run-72967328
The database now disagrees with the world. The checkpoints table has rows 0 to 7 for this run: as far as it knows, step 8 never happened. But the email was sent. A second table, outbox, has one row for this run, with the key 78f4f81ffc34882f.
Now resume. A successful run here proves one thing: repeating step 8 did not send the email a second time.
/opt/homebrew/bin/python3 harness.py --fake --approve --resume run-72967328 --verbose
{"run_id": "run-72967328", "step": 8, "turn": 4, "kind": "tool", "tool": "send_reply", "verdict": "allow", "is_error": false, "latency_ms": 0}
{"run_id": "run-72967328", "step": 9, "turn": 5, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "end_turn", "input_tokens": 434, "output_tokens": 37, "cache_read": 0, "latency_ms": 0}
{
"run_id": "run-72967328",
"status": "done",
"decision": {
"decision": "quote",
"missing_fields": [],
"reasons": [
"eligible; flood zone AE"
],
"premium_band": "high"
},
"reply": "sent",
"turn": 5,
"tokens": 4017
}
Step 8 ran again, with the same trace line as before the crash. What differs is not on the screen. After this run the outbox table still had one row for the run, and the tool result saved in checkpoint 8 reads {"status": "duplicate_suppressed", "idempotency_key": "78f4f81ffc34882f"}. The model was told the truth, and the broker received one email.
Two mechanisms made this work, and each did a different part. The checkpoint decided where the run continues: at the last step that was saved, so the unfinished step is repeated. The outbox remembered the send itself, under a key, so that the repeat could be recognized. The checkpoint alone would have sent the email twice. Making a side effect safe to repeat is called idempotency, and Reliability and cost explains it. What belongs here is the rule that creates the need.
A step whose checkpoint was not written will run again. Saving state decides where a run continues. It does not undo what an unfinished step already did.
The model stays unavailable#
The last case is a pause that nobody chose: the provider goes down after the first model call. This command shows that an outage can be a status and not an exception. A successful run proves that the steps already paid for are kept.
/opt/homebrew/bin/python3 harness.py --fake --fault down --verbose
{"run_id": "run-eaec3764", "step": 1, "turn": 1, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 61, "output_tokens": 31, "cache_read": 0, "latency_ms": 0}
{"run_id": "run-eaec3764", "step": 2, "turn": 1, "kind": "tool", "tool": "verify_address", "verdict": "allow", "is_error": false, "latency_ms": 0}
[retry] HTTP 529, attempt 1, waiting 0.01s
[retry] HTTP 529, attempt 2, waiting 0.02s
[retry] HTTP 529, attempt 3, waiting 0.04s
The model stayed unavailable. The run is saved. Continue with: --resume run-eaec3764
{
"run_id": "run-eaec3764",
"status": "paused:model_unavailable",
"decision": null,
"reply": "none",
"turn": 1,
"tokens": 618
}
When the retries and the fallback model are exhausted, model_step does not raise. It writes the status and the error into the state, and run saves it as step 3. A failed call had no effect outside the process, so repeating it later is safe.
/opt/homebrew/bin/python3 harness.py --fake --resume run-eaec3764 --verbose
{"run_id": "run-eaec3764", "step": 4, "turn": 2, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 145, "output_tokens": 31, "cache_read": 0, "latency_ms": 0}
{"run_id": "run-eaec3764", "step": 5, "turn": 2, "kind": "tool", "tool": "lookup_property", "verdict": "allow", "is_error": false, "latency_ms": 0}
{"run_id": "run-eaec3764", "step": 6, "turn": 3, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 227, "output_tokens": 31, "cache_read": 526, "latency_ms": 0}
{"run_id": "run-eaec3764", "step": 7, "turn": 3, "kind": "tool", "tool": "verify_address", "verdict": "allow", "is_error": false, "latency_ms": 0}
{"run_id": "run-eaec3764", "step": 8, "turn": 4, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 310, "output_tokens": 42, "cache_read": 526, "latency_ms": 0}
{"run_id": "run-eaec3764", "step": 9, "turn": 4, "kind": "tool", "tool": "check_underwriting_rules", "verdict": "allow", "is_error": false, "latency_ms": 0}
{"run_id": "run-eaec3764", "step": 10, "turn": 5, "kind": "model", "model": "claude-opus-5-5", "stop_reason": "tool_use", "input_tokens": 411, "output_tokens": 51, "cache_read": 526, "latency_ms": 0}
send_reply is waiting for a human. Continue with: --resume run-eaec3764 --approve
{
"run_id": "run-eaec3764",
"status": "waiting_approval",
"decision": null,
"reply": "waiting_approval",
"turn": 5,
"tokens": 3970
}
The run continues at step 4 with turn 2, and the token count goes on from 618. Steps 1 and 2 were not repeated. Then the run reaches the same approval gate as every other run.
One line needs an honest note. In step 7 the scripted model asks for verify_address a second time. That is a flaw in the scripted model, not in the resume: it numbers its tool requests from 01 in each new process, so after a resume two requests in the history carry the same id and the script loses track of the first. It is still a useful reminder. A new process shares nothing with the old one except the row.
5. What breaks when one piece is missing#
The four runs worked because four small things were in place. Take each away in turn.
No limit: a loop that never ends#
Suppose the rules tool answers that the address is not recognized, and the model responds by asking again with the address spelled a little differently, and again. Every response has the stop reason tool_use, so a loop that listens only to the model continues.
The cost does not grow evenly. Every model call sends the whole history, and the history is longer each time. In the first run above, the scripted model reported 61, 145, 227 and 328 input tokens for its four calls. Those are simulated counts, but the shape is real: a run that goes around a hundred times pays for the first tool result a hundred times.
The cause is that the model is the only authority over the loop. A turn limit does not make the model behave. It puts a ceiling on what misbehaviour can cost.
A stop with no reason: nobody knows what to do next#
Now add a limit, and record nothing but "failed". The next morning someone finds twelve failed runs. Which hit the turn limit on a hard case and need a person? Which stopped because the provider was down and only need to be started again? Which are bugs?
Each status in section 2 has a different next action, and that is the whole reason for the names. stopped:max_turns goes to an underwriter with the history so far. paused:model_unavailable can be resumed by a scheduled job. failed:invalid_output is a signal for the people who own the prompt. One word for all of them turns every stop into an investigation.
No checkpoint, or only a checkpoint#
A crash without a checkpoint has two possible outcomes. If nothing restarts the run, the broker's request has vanished without an error, because nothing was left running to report one. If something does restart it, the run begins at step 1: every model call is paid for again, and every side effect of the first attempt happens again. For this email that is a few thousand tokens. For an agent that worked for an hour it is the hour.
A checkpoint after each step reduces the repeated work to at most one step. The crash run showed the part that remains: the step in progress is repeated, so a step with a side effect needs its own guard.
What the miniature's checkpoint leaves outA simplified demonstration, and what production must add
The miniature shows where the save sits. It leaves out several things a production system needs.
| Left out | Why it matters | What a real system does |
|---|---|---|
| A lock on the run | Two processes can resume the same run at the same moment. Both would do the same step and write the same row | Claim the run before working on it: a version column, a lease, or a queue that delivers each run to one worker |
| One paid call can repeat | A crash after the model answers and before the checkpoint repeats that model call. It is billed twice | Accept it, or save the response before acting on it |
| Growth | Every row holds the whole state. In the first run the rows grew from 659 to 2,424 bytes over ten steps | Keep only the newest rows, or store the history once and append to it |
| Code that changes under a waiting run | A run saved by yesterday's code is loaded by today's. A renamed field breaks the resume | Version the saved state, and keep old readers until waiting runs are finished |
| A real database | A single file on one machine is lost with the machine | A database that every worker can reach, with backups |
A person who answers after the process is gone#
The obvious way to wait for a person is to block on the answer inside the running process. In a service that fails for three reasons. A deploy ends the process, and the pending request with it. Every waiting run holds memory and a worker for as long as the person takes. And the answer arrives as a new request, possibly at a different machine, which cannot reach the process that is waiting.
The cause is the same each time: the pending request lives in a process, the least durable thing in the system. The fix is the one from section 4. The wait is a status in a row.
6. The abstractions, each for the cause it removes#
Everything so far was about a hundred and twenty lines of Python. The same two jobs appear on every rung of the ladder under other names. The quotations below were read in each vendor's documentation on 2026-11-16.
An agent SDK: the turn limit is an option#
The cause it removes: writing the counter and the named exits yourself. An agent SDK wraps the loop, so the limit becomes a setting on the loop.
In the Claude Agent SDK the option is max_turns in Python and maxTurns in TypeScript. A run that reaches it ends with a result whose subtype is error_max_turns, one of five documented subtypes. That is section 2 again: each exit has a name. The OpenAI Agents SDK takes max_turns on its run functions, and its documentation says: "If we exceed the max_turns passed, we raise a MaxTurnsExceeded exception."
What it costs: the option exists, and its value is still your decision. The Claude Agent SDK documentation gives the default for this limit as "No limit". An unset option is the while True of section 1, one rung higher.
The same SDKs keep the conversation. The Claude Agent SDK calls it a session, "the conversation history the SDK accumulates while your agent works". It is stored as files under ~/.claude/projects/ on the machine that ran it and continued with the resume option. That is a checkpoint on a local disk; a service with several machines needs the session_store option, which "mirrors transcripts to your own backend".
The pause for a person shows why a saved conversation is not always enough. The Claude Agent SDK asks for approval through a callback, and the documentation says: "The callback can stay pending indefinitely. Execution remains paused until your callback returns." That is a process waiting, the fourth failure of section 5. The same page names the other path, a PreToolUse hook that returns the defer decision, "so the process can exit and resume later from the persisted session". The OpenAI Agents SDK returns pending approvals as interruptions, and its RunState can be written with to_json() "to store pending work in a database or queue".
A graph runtime: checkpointers and interrupts#
The cause it removes: writing the save, the load and the pause for every step yourself. In a graph runtime you describe the work as nodes and edges, and the runtime saves the state between them.
LangGraph is the example here; LangChain's create_agent, one rung lower, runs its loop on it. Its persistence layer is a checkpointer, which the documentation says is used to "persist a thread's graph state as checkpoints". A thread is a saved run, named by a thread_id that you choose. The saves happen between steps: "LangGraph saves checkpoints at super-step boundaries, not mid-function inside a node."
The pause is a function. "The interrupt function pauses graph execution and returns a value to the caller", and "you resume the graph by invoking it again with a Command that contains the resume value". It needs a checkpointer and a thread id, and then: "Graph waits indefinitely until you resume execution with a response."
The sketch below puts the parts together: a node that pauses, a graph compiled with a checkpointer, a call that stops at the pause, and a call that continues. It is adapted from the LangGraph documentation and was not run here; State, builder, checkpointer and initial_input are defined elsewhere.
from langgraph.types import interrupt, Command
def approval_node(state: State):
approved = interrupt("Do you approve this action?")
return {"approved": approved}
graph = builder.compile(checkpointer=checkpointer)
config = {"configurable": {"thread_id": "thread-1"}}
graph.invoke(initial_input, config) # pauses at interrupt()
graph.invoke(Command(resume=True), config) # resumes; True becomes interrupt()'s return
Compare it with section 4. thread_id is the run id, the state saved at the pause is row 8, and the second invoke is the --resume command.
What it costs: three things. The first is the rule from section 4, now stated by the vendor. On resume, "the runtime restarts the entire node from the beginning", so "any code that ran before the interrupt will execute again", and the documentation makes the consequence a heading: "Side effects called before interrupt must be idempotent". The runtime does not make your side effects safe to repeat. It tells you that you must.
The second is a database that somebody runs. The documentation names PostgresSaver under "Use a persistent checkpointer for production", and describes SqliteSaver as "Local file-based storage for development".
The third is that the built-in limit is a backstop, not a budget. LangGraph's recursion_limit "caps how many super-steps one run may execute" and raises GraphRecursionError. The documentation gives its default as 10,007 super-steps from version 1.1.4. A limit that fits a quote email is still a number the team sets.
A durable execution engine: record every result, replay the code#
The cause it removes: treating durability as something each program builds for itself. A durable execution engine is a separate service that makes ordinary code survive the death of its process, whether or not a model is involved.
Durable execution is the general name for what this chapter has been building: the progress of a run is recorded outside the process, so another process can continue it.
Temporal is the example; its documentation calls it "the open source Durable Execution platform for crash-proof applications and AI agents". Its design differs from a checkpoint in an instructive way. It does not save a snapshot of the state. It saves an event for every completed step, and the documentation describes what happens after a crash: "It starts the Workflow code from the beginning, replays the Event History step by step." The result: "the Workflow code is re-run, but uses the recorded events instead of redoing work."
Replay puts a condition on the code. If it is run again from the top, it must take the same path every time, or the recorded events will not fit: "A Workflow Definition must be deterministic to support replay." A model call is not deterministic, and the documentation names model calls, with API calls and database queries, as operations that belong in Activities, which "execute outside the replay path and are automatically retried". In an agent built this way, each model call and each tool call is an Activity, and the loop around them is the Workflow. The wait for a person is a message to the waiting Workflow, and Workflows "can run—and keep running—for years".
What it costs: a service to operate or to buy, and a discipline in the code. The side-effect rule is unchanged. Of an Activity the documentation says: "We recommend that it be idempotent, so retries can be processed without duplicate side effects." And the history has a ceiling: a Workflow is terminated when its Event History "exceeds 51,200 Events", with a feature named Continue-As-New as the remedy for long runs.
The three designs so far are close relatives.
| Design | What is saved | What runs again after a crash | What you must still guarantee |
|---|---|---|---|
| The miniature | The whole state, after each step | The step that was in progress | Side effects are safe to repeat; one run has one worker |
| A graph runtime checkpointer | The graph state, as the run proceeds | The node that was in progress, from its beginning | Side effects in a node are safe to repeat; the database is yours |
| A durable execution engine | The result of each completed step, as an event | The code from the top, with recorded results filled in; the unfinished Activity is retried | The Workflow code is deterministic; Activities are safe to repeat |
Read the last column. In no row is it empty, and every row contains the same sentence about side effects. Durability decides where a run continues. It never removes the question of what the interrupted step already did.
A managed platform: the session is the run#
The cause it removes: operating any of it. On a managed platform the vendor runs the loop and keeps the state, and the run is an object you address through an API.
Claude Managed Agents, in beta, is the example read for this page. Its unit is a session, "an agent instance within an environment", with four statuses: running, idle, rescheduling and terminated.
The four session statuses, next to the miniature'sClaude Managed Agents documentation, read 2026-11-16
| Session status | The documentation's words | The nearest status in the miniature |
|---|---|---|
running | "Agent is actively executing." | running |
idle | "Agent is waiting for input, including user messages or tool confirmations." | done, waiting_approval or a stop, told apart by a stop reason |
rescheduling | "Transient error occurred, retrying automatically." | The retries before paused:model_unavailable |
terminated | "Session has ended, either because of an unrecoverable error or because it was archived." | No equivalent |
When a session goes idle, an event says why. Its stop_reason.type is end_turn, requires_action or budget_reached. The middle one is the approval gate: "One or more tool calls need an answer from you, such as a custom tool call or a confirmation request." The documentation then says what this chapter took four runs to show: "The session waits indefinitely for a response." The answer is an event the client sends, user.tool_confirmation, with result set to "allow" or "deny". The history is kept on the vendor's side: "The Managed Agents service keeps the event history, and you can fetch it in full."
What it costs: the state lives with the vendor, in the vendor's shape, and the limits are the ones the platform offers. The pages read for this chapter document a spending budget per session and state no limit on turns. A session that reaches its budget goes idle with the stop reason budget_reached, and the documentation adds: "it is not terminated". Your own system still keeps the session id next to the quote it belongs to, decides which tools ask for confirmation, and makes its own side effects safe.
A workflow: fewer loops to stop and less state to save#
The cause it removes: the loop itself, wherever the next step is known in advance. This is a design choice, and it comes before all the others.
The eight jobs made the distinction: in a workflow, code fixes the order of the steps, and a model works inside a step. That shrinks both jobs of this chapter. A step with one model call cannot run away, so it needs no turn limit. The state between steps is an ordinary record with a status, and the pause for a person is one more status on that record.
In the full build: a workflow outside, two bounded loops insideDescribed from the full build, not shipped with this site
The full build of the quote example has seven stages. Message topics connect them, and no model chooses the next stage.
| Concern | How the full build handles it |
|---|---|
| Turn limits | One per model step: 1 for classify, 6 for the prefill loop, 10 for the resolve loop, 1 for reading a reply |
| No call when none is needed | If the rules clear every point, the resolve stage calls no model at all |
| A check after "done" | When the model says it is finished, code checks that the required steps happened. If not, it sends one corrective turn |
| Named stops | A refusal, the output limit or the turn limit sends the quote to an underwriter with the reason |
| State | Each quote has a status in the database: profiled, prefilled, awaiting review, awaiting information |
| One short transaction per stage | A stage makes its model and service calls outside any database transaction. Then one short transaction writes the results, the next event and a record that this event was handled |
| Paid once | A finished agent run is stored under its stage and event id. If the event arrives again, the stored result is reused |
| The wait for a person | A row on the underwriter's screen. No process stays alive for it |
The numbers come from that build and were not measured again for this site.
What it costs: a workflow handles the paths its author foresaw. A new kind of case needs a code change. That is why the full build keeps two loops, each with its own turn limit, for the two stages where the next lookup depends on the last result.
7. Who runs jobs 3 and 4#
A product can now be read by two questions. Who stops the loop, and with what? Who saves the run, and where? The table uses the site's fixed words: BUILT IN (the product does it in your process or deployment), INTEGRATES (it connects to another product for it), MANAGED (the vendor runs it) and YOU BUILD.
| Product | Job 3: running and stopping the loop | Job 4: saving and continuing the run |
|---|---|---|
| The miniature | YOU BUILD: run, seven named statuses, a turn limit | YOU BUILD: a row per step in SQLite, resume by run id |
| Claude Agent SDK | BUILT IN: agent loop; max_turns with no limit by default; named result subtypes | BUILT IN: sessions on local disk, resume; session_store for your own backend |
| OpenAI Agents SDK | BUILT IN: loop, handoffs; max_turns | BUILT IN: sessions for SQLite, SQLAlchemy, Redis and others; RunState for pending approvals |
LangChain create_agent | BUILT IN: the loop runs on LangGraph; ModelCallLimitMiddleware | BUILT IN: persistence through LangGraph |
| LangGraph | BUILT IN: graph runtime; recursion_limit | BUILT IN: checkpointers, interrupt. You run the database |
| LlamaIndex | BUILT IN: event-driven Workflows | YOU BUILD the saving: ctx.to_dict() and your own store. INTEGRATES: DBOS, to survive a crash |
| CrewAI | BUILT IN: Crews and Flows; max_iter, max_execution_time | BUILT IN: memory, checkpointing |
| Microsoft Agent Framework | BUILT IN: agents and graph workflows | BUILT IN: sessions; workflow checkpointing |
| Pydantic AI | BUILT IN: loop; pydantic-graph | YOU BUILD: you store the message history. INTEGRATES: nine durable execution engines, Temporal and DBOS among them |
| Google ADK | BUILT IN: graph Workflow Runtime, multi-agent | BUILT IN: sessions, state, memory, resumable runs |
| Strands Agents | BUILT IN: the loop, optional limits | BUILT IN: memory, sessions |
| Temporal | BUILT IN: Workflows as code | BUILT IN: durable execution. MANAGED on Temporal Cloud, which stores the history and "does not execute your application code": the workers stay with you |
| LangSmith Agent Server | NOT ITS JOB | MANAGED: threads, runs, durable execution |
| Claude Managed Agents | MANAGED: the vendor runs the loop; a spending budget per session | MANAGED: sessions and their event history |
| OpenAI Agents API | MANAGED: a managed harness | MANAGED: sessions, recovery |
| OpenAI Responses and Conversations API | The docs read do not say who runs the loop | MANAGED, optional: stored responses and conversation objects |
| Amazon Bedrock AgentCore | MANAGED: the Harness is the agent loop; maxIterations, timeoutSeconds | MANAGED: Memory, short and long term |
| Foundry Agent Service | MANAGED for prompt agents. A hosted agent runs your code instead | MANAGED: conversations, session state |
| Google Agent Runtime | The docs read do not say who runs the loop | MANAGED: Sessions, Memory Bank |
The Claude Agent SDK, OpenAI Agents SDK, LangGraph, Temporal and Claude Managed Agents rows were read on 2026-11-16. The LlamaIndex, Pydantic AI and Temporal Cloud cells follow Frameworks and Managed platforms, read the same day. The others come from the baseline fact check of 2026-11-14. This is two columns of the full matrix on Build or adopt, and it is not a ranking.
Two things stand out. Almost every product runs the loop for you, and very few choose your limit: the option is there, and its default may be no limit or a very large number. And the right-hand column uses one word, sessions, for things of different strength. A session that stores the conversation lets a later call continue the dialogue. It does not by itself say what happens to a step that was half done when the process died, or to a tool call that is waiting for a person. Those are the two questions to take to any product's documentation.
What you can do now, and what is still open#
You can now read a run as data: an id, a history, a few counters, and a status from a short list of names that each lead to a different next action. You can say where a stopped run continues and which step will be repeated when it does, in your own code or in a product's vocabulary of threads, sessions and event histories.
One rule holds on every rung, in every vendor's own words: the step that was interrupted runs again. Saving state is half of surviving a crash. Making the repeated step harmless is the other half.
The run in the opening stopped because code said "this tool needs a person". Nothing here asked the harder questions behind that sentence. Who is this caller, and which tools may they use at all? Who is allowed to approve, and what happens when the email itself contains instructions? The pause is solved. The decision in front of it is not, and Guardrails is the next chapter because a pause protects nothing if anyone can end it.