02 Session and shared memory
Before you start
Read 01 Memory types overview so MemoryType and MemoryScope are clear. This lesson uses only the stub provider. No Qdrant, Postgres, or API keys are required.
Concept
Session and shared memory both live inside the runtime for the duration of a workflow run. When the run completes, that state is gone unless you also use persistent or vector backends elsewhere.
Session memory (MemoryType.SESSION) gives one agent a private key-value map for the current run. Use it for intermediate values the agent or its tools need within a single step loop: iteration counts, parsed flags, short-lived notes.
Shared memory (MemoryType.SHARED) exposes a namespace that multiple agents in the same workflow can read and write during one run. Use it when step two needs structured facts from step one and truncating prior step text through context policy would lose too much detail.
| Choice | Type | Scope | Namespace |
|---|---|---|---|
| One agent scratch pad | SESSION | AGENT | Optional but recommended for clarity |
| Two agents, same pipeline | SHARED | WORKFLOW | Required for predictable handoff keys |
Neither type talks to Qdrant. Trace events for reads and writes appear as MemoryRead and MemoryWrite with keys and hit flags, not chunk text (trace data policy).
Example
Two agents share a workflow-scoped namespace. The first agent writes a summary key; the second agent is configured to read shared memory so the runtime can inject prior shared state into its context.
Save as shared_memory_demo.py:
Session-only variant (single agent, agent-scoped scratch):
Run either script with python shared_memory_demo.py. Stub output is placeholder text, but the workflow completes and memory config serializes correctly to the Rust runtime.
Verify
| Check | Expected |
|---|---|
| Script exits without exception | Yes |
result.status | "completed" |
result.step_count | 2 for the shared demo, 1 for the session demo |
Shared demo uses same namespace on both agents | "handoff" on extractor and writer |
Inspect trace metadata after a run if you want to confirm memory events:
You may see MemoryWrite or MemoryRead depending on runtime version and stub behavior. Absence of those events on stub-only runs is not a failure; the config wiring is what this lesson validates.
Next
03 Vector memory setup connects MemoryType.VECTOR to Qdrant through ARCFLOW_QDRANT_URL and namespace alignment.