Agent Build Tutor
Map / Outline

State and storage

Where facts live between calls, who may write them, and how concurrent writers stay safe.

What it is and why it exists

What

State is everything that outlives one model call: the conversation so far, run state inside a request, conversation history across requests, the knowledge store, cursors that mark how far a background job has read, and locks.

Why

A model call has no memory. Each kind of state has a different lifetime and a different owner, and mixing them causes the worst bugs. The reference build's single-writer stores failed when a nightly job and a daily job wrote at once, and one file was corrupted.

How it works

Where it sits in the build order

Needs first

Nothing. You can start here.

Unlocks

  • RAG and knowledge graphChunks, vectors, the file ledger, and graph edges need a store that survives concurrent readers and a nightly writer. The reference build lost weeks to single-writer stores before moving to Postgres.
  • Harness engineeringThe loop is a state machine. Concurrent tool results have to merge into one conversation without overwriting each other, so the merge rules are defined before the loop that relies on them.
  • MemoryMemory is durable state with concurrent writers: live chats and background jobs. It needs the storage guarantees from the state module.

In the reference build

PathRole
apps/agent-server/graph.pymerge_state: the rules for run state.
apps/agent-server/pgstore.pyConnection handling and schema setup for Postgres.
apps/agent-server/pgschema.sqlSchemas by owner: learned knowledge, file ledger, chunk indexes.
apps/agent-server/conversation_store.pyThreads and messages across requests.

The same idea on other platforms

PlatformHow this module maps
DatabricksDelta tables for durable state. Lakebase for Postgres-style transactional state such as threads and checkpoints. Run state lives in your agent code.
IBM watsonxOrchestrate manages thread state for its agents. Durable domain state goes in watsonx.data or a database you connect.
CodexSession history is managed by the tool and can be resumed. Durable project state is files in the repo.
CursorChat history is managed by the editor. Durable state is files, plus whatever your MCP servers store.
Claude Code / Agent SDKSessions can be resumed. The SDK exposes session ids. Durable state is files and your own stores.
Another machinePostgres in a container gives the same guarantees. SQLite is fine for one writer.

Explain it back

Answer aloud first. Then open the answer and compare.

Name three kinds of state and their lifetimes.
A strong answerRun state lasts one request. Conversation state lasts a thread. Knowledge and memory last until retired. Mixing them leads to leaks across users or loss across requests.
Why did the reference build leave single-file stores?
A strong answerThey allow one writer at a time. Two scheduled jobs collided, one database was corrupted, and a vector segment became unreadable. Postgres gives concurrent access and crash recovery.

From the live build

Recent changes and files the sync job filed under this module.

Ask the tutor about this module