Agent Run State Machine and the Action/Observation Trace
Agent-Assisted Engineering Check
Prerequisites
Day 73-75 agent loop and tool-protocol work, plus the Ticket 22 bounded agent project at projects/agent_learning.
Learning Objective
Identify the complete run state the bounded agent carries - the action/observation trace, the step counter, and the retry counter - and enumerate its three legal terminal states: goal_reached, tool_failure, step_budget.
Instructions
1. Open projects/agent_learning/agent.py and read run_task.
- Mutable state per run: trace (an append-only list of {action, observation} pairs), retries (count of observations with ok=false), and the implicit step counter len(trace).
- Terminal transitions: write_report returning ok=true -> status=completed, termination=goal_reached; retries exceeding max_retries (=2) -> status=failed, termination=tool_failure; the loop ending with neither -> status=budget_exhausted, termination=step_budget.
2. Note what is deliberately absent: no chain-of-thought field and no hidden scratchpad - the trace is the entire persisted state (project.json evidence.forbidden_fields lists thought and chain_of_thought).
3. Compare with production checkpointing: LangGraph checkpointers persist graph state at every super-step; Temporal rebuilds state by replaying an event history. Our trace is a minimal event log of the same idea.
4. Run python -m projects.agent_learning.cli evaluate --fixture summarize-notes --output /tmp/agent-run.json and inspect result.status and result.termination.
Practice & Prediction Log
Predict the four-step trace for the nominal run before executing, then run the CLI and mark each step's transition (action proposed -> observation recorded -> counters updated). Confirm the run ends with steps=4, retries=0, termination=goal_reached.
The only transition that yields completed is a write_report observation with ok=true; every other successful step just appends to the trace.
steps=4: list_notes -> read_note(alpha.txt) -> read_note(beta.txt) -> write_report. Status flips to completed at step 4 because the write_report observation returned ok. retries stayed 0 because no observation had ok=false. termination='goal_reached'.
Without executing code, name which counter increments on a failed observation (retries), which bound ends a healthy run (max_steps=6), and the only action whose success terminates the run early (write_report).
Authoritative Source Resources & Provenance
LangGraph Persistence: Checkpoints, Threads, and State Snapshots
Relevant Section / Range: Persistence: Checkpointer vs. store (checkpoints keyed by thread_id); the page now redirects to docs.langchain.com
Verified Version & Date: LangGraph documentation (Verified: 2026-10-30)
Primary reference for agent-run checkpointing: LangGraph checkpointers persist graph state at every super-step so interrupted runs resume from the last committed snapshot, the production analogue of this project's action/observation trace.
Agent loop fundamentals, tool calling, and JSON state serialization.
The checkpoint/replay exercise is implemented directly against the projects/agent_learning trace JSON; no framework installation is required.
Compared Candidate Sources & Selection Analysis (2)
Temporal persists event histories for replay-based recovery of arbitrary workflows; LangGraph targets agent graphs specifically and stays closer to the learner's tool-loop mental model.
Provider-scoped SDK sessions; LangGraph's explicit checkpoint model exposes the underlying state-transition semantics more transparently.
Temporal Documentation: Durable Execution and Event History Replay
Relevant Section / Range: What is Temporal?: Durable Execution
Verified Version & Date: Temporal documentation (Verified: 2026-10-30)
Standard industrial reference for durable execution: workflow state is rebuilt by replaying a persisted event history through deterministic code, exactly the checkpoint/replay mechanism learners reproduce against the agent trace.
State machines, event logs, and deterministic replay concepts.
Replay semantics are exercised offline against the deterministic adapter; Temporal itself is never installed.
Compared Candidate Sources & Selection Analysis (2)
Agent-specific checkpointing; Temporal supplies the general event-sourced replay model that motivates the exercise.
Temporal's predecessor with equivalent replay semantics; Temporal's docs are more actively maintained.