Memory Management¶
Summary¶
An agent that does more than answer one question needs memory. Gulli splits it in two. Short-term (contextual) memory is what sits in the context window right now: recent turns, tool results, reflections. It is limited, costly to reprocess and lost when the session ends, so it has to be curated by summarizing, trimming and keeping only what matters. Long-term (persistent) memory lives outside the model in databases, knowledge graphs or vector stores. The agent queries it and pulls relevant pieces back into the short-term context. Long-term memory comes in three kinds: semantic (facts), episodic (past experiences or runs) and procedural (rules and instructions, which the agent can update). Frameworks give these parts names, such as a session/thread, a scoped state dictionary (user:, app:, temp: prefixes in ADK) and a searchable memory service. The book's rule of thumb is to use this pattern "whenever the agent is expected to learn or adapt based on past successes, failures, or newly acquired information" (ch. 8, "At a Glance").
When to use / not¶
Terms: § numbers refer to sections of the fleet's constitution (docs/constitution.md), its written governance rules. MCP (Model Context Protocol) is the standard way tools and data are exposed to agents; an MCP server offers them as callable tools. ADK is Google's Agent Development Kit. The "lake" is the fleet's local SQLite data store of agent sessions and runs; the "spool" is a capped log file of activity events.
- Use it for multi-step tasks, recurring bots that should not repeat past mistakes, and personalization.
- Skip it for stateless one-shot transforms. Persisting those only adds privacy risk and staleness.
Failure modes¶
- Unbounded growth (cost, slow recall).
- Stale memory treated as truth.
- Secrets written into memory.
- Changing state directly instead of through recorded events.
- No eviction or provenance.
- Recall that floods the context window.
Fleet evidence (bamr87/bamr87@2321b3a, bamr87/README@d4ea571)¶
| Memory kind | Fleet implementation | Permalink |
|---|---|---|
| Procedural (long-term rules every agent loads) | AGENTS.md + .claude/skills/* + constitution are the fleet's standing instructions, versioned in git |
AGENTS.md, .claude/skills |
| Short-term context injection at session start | A SessionStart hook (a script Claude Code runs when a session opens) adds standing context to every Claude Code session; if it fails, the session still starts (fails open) | settings.json L16-25, future_features_session_start.py L1-12 |
| Episodic (past sessions, turns, tool calls) | Data lake .dash-lake/fleet.sqlite: sessions, session_turns, session_tools tables; files whose modification time is unchanged are skipped, so re-ingesting is safe to repeat (idempotent) |
fleet_lake.py L128-142, L1577-1583, architecture HARNESS-OPS.md L96-109 |
| Episodic recall exposed to agents | Console MCP read tools agent_activity, lake_status, lake_runs |
mcp_layer/server.py L321-388 |
| Bounded, redacted event memory (eviction + provenance) | Activity spool capped at 5000 events, oldest dropped with a dropped marker, token redaction before write |
fleet_activity.py L50, L94-101, L196-215 |
| Semantic (distilled fleet facts) + fingerprinted AI cache | README context pyramid (layers of short summaries: per-project cards, facts, and a top-level apex) served read-only over MCP; AI cache keyed by fingerprint, so an unchanged corpus makes 0 API calls | mcp/server.py L1-19, PLAN.md L555 |
Reproduce¶
git clone -q https://github.com/bamr87/bamr87 /tmp/hub && cd /tmp/hub && git checkout -q 2321b3a7c1199688042339d68b628f9d08bb46eb
python3 -m pytest -q .github/scripts/dash-gen/test_fleet_lake.py # episodic store: session ingest
python3 -m pytest -q tools/test_backlog_fanout.py # exercises fleet_activity emit/retry events
git clone -q https://github.com/bamr87/README /tmp/readme && cd /tmp/readme && git checkout -q d4ea571b470cc826ff8ab10323e3aff68f64111d
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"context_status","arguments":{}}}' | python3 mcp/server.py
Expected (run 2026-10-31): 24 passed, 11 passed; context_status returns JSON with generated_at 2026-10-26T03:14:56+00:00, project_count 7 and per-project fingerprints. Green CI: hub Python tests 41256758330; README CI 41174877803.
Gaps¶
- GAP: no queryable long-term semantic memory for bots ("second brain"). The planned
brain.dband second-brain MCP server do not exist onmainof bamr87/bamr87 or bamr87/README. Searching code and issues forbrainfinds nothing. → bamr87/README#46. - GAP: no recall over session content.
session_turns.textis stored, but no MCP tool searches past sessions by meaning or keyword.agent_activityonly returns aggregates. → bamr87/bamr87#546. - GAP: no memory summarization or compaction policy for long sessions or the lake (the book's short-term curation). The spool caps size by dropping events; nothing summarizes them. → bamr87/bamr87#546 (digest option).
Editor note: the console MCP test (
tools/console/test_mcp_layer.py) was rerun with its optional deps (uv run --with mcp --with pytest --with pyyaml python -m pytest -q test_mcp_layer.py): 36 passed. The aggregateagent_activityreads are verified; recall over session content is still the gap in item 2.
Cross-links¶
ADP-14 RAG (long-term recall is retrieval; same store), ADP-19 monitoring (the lake is shared), ADP-12 (retry events in the spool); constitution §16 (MCP layer per repo), §15 testing evidence; #409 fleet activity log PRD.