Skip to content

Vol. II · Production Doctrine · II.6

The Agent as a Stateless Reducer

Factor 12: (state, event) → (newState, effects). The model is a pure function over a context you serialize. Everything else is infrastructure.

6 min read

Doctrine

  • Serialize the whole working set. If you cannot, you cannot resume, fork, or evaluate.
  • Unify execution state and business state (Factor 5). One blob, one source of truth.
  • Effects (tool calls) happen outside the reducer. The reducer only records them.

Why this is the endgame

LangGraph checkpoints are this idea with a graph API. Event sourcing the loop means you can time-travel, A/B a prompt on the same event log, and recover from a crash. Letta persists memory as the state; the call is still a reducer step.

Once you see it, frameworks become I/O adapters around a function you could write yourself.

Anti-patterns

  • Hidden mutable globals, in-memory conversations that die with the process.
  • Two databases: the 'agent memory' and the actual ticket.
  • Non-deterministic context builders that prevent replay.

Related