Agent Memory and Durable Execution
Summary
Save the research checkpoint separately from any chat transcript, then delete it.
Companion code: 10-memory in indian-legal-ai-lab.
Previous: Part 9: Event-Driven Judgment Ingestion
A research session should survive a restart. The file that survives should be the verified passages and the stage, not a chat transcript.
What is stored
`SessionStore` takes a directory and creates it. `PathFor` joins that directory with `{sessionId}.json`. `SaveAsync` serializes the whole `ResearchState`: question, passages, analyses, verification notes, report, and stage. There is no message list on that type, so a model transcript cannot be written by this store.
`LoadAsync` returns null when the file is missing. `Delete` removes the file if it exists. The API maps `DELETE /sessions/{id}` to that method. The Blazor history page loads the same file from the `session` query string.
Resume uses the stage gates from Part 8. A state saved at `analyze` skips discovery. `Session_can_resume_and_be_deleted` saves that stage, calls `RunAsync` with the loaded state and a Thappar question, expects `completed`, then deletes the file and expects a null load.
dotnet run --project labs/10-memoryThe lab saves stage `verify` under the temp directory `lab10-sessions`, prints `verify`, deletes the file, and prints `True` when the reload is null.
The files are plain JSON. Do not point the store at a directory of client matters. This sample uses public judgments and fictional fixtures.
Atomic write
`SaveAsync` writes `sessionId.json.tmp` and then moves it over the destination. A session id that is not letters and digits throws. `Session_id_rejects_path_traversal` uses `../etc`.
Next
Part 11: Evaluation, Security, and Reliability
Verified in this revision
`SessionStore.SaveAsync` writes a temp file and moves it. `PathFor` rejects a session id that is not letters and digits. A session is the `ResearchState` JSON, not a chat transcript.
More in Applied AI
Event-Driven Judgment Ingestion
A local queue retries extraction, dead-letters repeated failures, and skips a job id that already completed.
Evaluation, Security, and Reliability
Fixed checks for retrieval, unknown citations, hidden instructions in a judgment, and tools that are not allowed.
LLM Fundamentals in C#
A supplied judgment can be summarized only from passages you pass in. The same client, with no passage, names a citation that the catalog rejects.