Memory Model — What Gets Persisted
MemoryModel
The unit of persistence is MemoryModel — a Pydantic model holding the conversation history of one session:
from amrita_core.types.memory import MemoryModel
memory = MemoryModel() # empty history
memory.messages # list[Message | ToolResult]messages— the conversation:Messageentries (user / assistant) andToolResultentries paired with their tool calls.- Being a Pydantic model, it serializes with
model_dump()and validates withmodel_validate()— exactly what a file/DB backend needs (see Data Backend).
The Lifecycle
- Load — the workflow's
LOAD_STATEnode callsmemory.load_memory(session_id)and stores the result inMemoryContext(chat._di_memory.memory). - Mutate — strategies append to
SendMessageWrap; at the end (_post_runner) the assistant response is appended too, and the final list is written back intomem_ctx.memory.messages. - Commit — the
COMMIT_MEMORYnode callsmemory.commit_memory(session_id, memory).
So the same session_id + backend combination determines what the next conversation loads — the framework only orchestrates the calls.
MemoryContext (DI)
The runtime memory lives in the MemoryContext DI slot:
chat._di_memory.memory # MemoryModel | None — set after LOAD_STATEWorkflow nodes and strategies access it via type-matched injection (mem: MemoryContext).
Memory Summarization
LLMConfig.enable_memory_abstract + memory_abstract_threshold trigger summarization: when the prompt token count exceeds the threshold, older turns are replaced by a summary before the request is sent (see Tutorial 5 — Memory). The built-in step strategy additionally compresses history between Steps (see Step Loop).
StateContext (Legacy Accessor)
StateContext (session_id + memory + ability) still exists as a backward-compatible accessor: chat.state synthesizes one from the DI contexts, and LegacyBackend uses it as its in-process storage. New code should use the DI contexts (_di_memory, _di_ability, _di_session) directly.
Next
Data Management — back to the overview, or continue to Extensions & Integration.
