#237 Enterprise architecture and AI agents 5.8 min
Where Should AI Agent State and Memory Live? A Crash Test
I killed my agent in the middle of a write, then reloaded its memory. Three kinds of memory behaved in three different ways.
Read what each store does
Copy the code folder first. Open stores.py and read the three classes. For each one, write one sentence saying where the memory is kept and what happens to it when the process ends. Then run python compare.py and match each output line to the class that produced it.
A hint
MemoryStore keeps a list, JsonStore rewrites a whole file, SqliteStore wraps each step in a transaction.
Crash earlier
In worker.py, change crash=(step == 6) to crash=(step == 3). Predict what the SQLite line will say, then run python compare.py. When I ran it, the SQLite line said it remembers 2 of the 5 finished steps, and the text still says 5 because that wording is fixed in compare.py. The labels also still say step 6 for the same reason. Then change crash=(step == 3) back to crash=(step == 6) before the next task.
A hint
The agent now dies in step 3, so only steps 1 and 2 are finished.
Never crash
In worker.py, change crash=(step == 6) to crash=False. Predict what each of the three stores remembers, then run python compare.py. When I ran it, the memory store remembered 0, the JSON file remembered 6 and SQLite remembered 6. The printed wording still says the 5 finished steps and a crash in step 6, because it is fixed text.
A hint
The memory store lives inside the worker process, which has ended by the time compare.py reads it.
Explain the lost item
In compare.py, find the lines where agents a and b both call load before either calls write. Write two sentences saying why only one item is kept, using the idea that each agent rewrites the whole file from what it read earlier. Then say which line of the SQLite part makes the second agent wait or fail instead.
A hint
Look at seen_a, seen_b and the begin immediate line.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
A staged crash and an arranged collision on one laptop; the half-written JSON file is written that way on purpose; an atomic rename was not tested; Redis and server databases were not tested; the stores hold plain text only.
Up next in Enterprise architecture and AI agents
More in Enterprise architecture and AI agents
- #229 A Reference Architecture for Enterprise AI Agents, as Code
- #230 Agent Gateway: One Front Door for Models, Tools, Agents
- #231 MCP Gateway: Per-Tool Policy for Agent Tools (Python)
- #232 Give Every AI Agent Its Own Identity
- #233 Delegated Authority: Let an AI Agent Act for a User, Safely
- #234 Authorisation for AI Agents With Policy as Code (Cedar)
Related videos
- #236 Agent Orchestration Patterns: Supervisor, Pipeline, Swarm Enterprise architecture and AI agents
- #238 Event-Driven AI Agents: Queues, Crashes and Duplicates Enterprise architecture and AI agents
- #239 Async AI Agents: Design for Timeouts With Job Polling Enterprise architecture and AI agents
- #243 Reliability Patterns for AI Agents: Bulkhead, Retry, Cache Enterprise architecture and AI agents
