Managing Structured State in Agents
Deep technical dive into managing structured state safely across autonomous pipelines.
The problem with untyped memory#
Autonomous agents typically maintain context via unstructured chat transcripts. Over a long lifecycle, this leads to semantic drift: facts are forgotten, entity names subtly alter, and crucial parameters lose their precision.
When an agent is responsible for production infrastructure or a company's internal knowledge base, untyped memory becomes a liability. We need structured, durable state that agents can read and write reliably.
The append-only ledger#
Instead of giving the agent a mutable key-value store, we force all state changes through an append-only ledger. Agents emit strongly-typed JSON patch events.
{
"timestamp": "2026-09-18T14:32:00Z",
"actor": "agent-04",
"operation": "add",
"path": "/entities/project_apollo/status",
"value": "in_progress"
}A separate, deterministic reducer applies these patches to project the current state. This provides three guarantees:
- Auditability: We know exactly when and why the agent updated a value.
- Rollback: If an agent hallucinates, we simply truncate the ledger before the errant patch.
- Concurrency: Multiple agents can propose state changes simultaneously; the ledger enforces serialization.
Schema enforcement#
Before a patch is appended to the ledger, it must pass strict JSON Schema validation. If an agent attempts to write an invalid state transition (e.g., setting a status string where an enum is expected), the request is rejected and the agent is provided the validation error.
This forces the LLM to course-correct in real-time, treating schema violations as compilation errors. By enforcing types at the boundary, the projected state remains pristine regardless of the agent's internal reasoning.