# Labs — Module 5: Memory Orchestration & Context Engineering > Four short labs that build a three-layer memory stack: durable > ADRs, curated harness memory, engineered retrieval, and a recovery > drill. Each fits in a single focused block; the whole set is ~75 > minutes. | Lab | Title | Time | Maps to | |-----|--------------------------------------------------|--------|----------------------------------| | 5.1 | Author one durable ADR | 20 min | §5.3 Layer 1 — source-of-truth | | 5.2 | Audit harness memory in one pass | 20 min | §5.3 Layer 2 — harness memory | | 5.3 | Run a hierarchical retrieval on one question | 20 min | §5.4 Context engineering | | 5.4 | Compaction recovery drill | 15 min | §5.1, §5.4 anti-patterns | --- ## Lab 5.1 — Author one durable ADR ### Objective Capture one currently-live decision as an ADR that future sessions (human or agent) can use as canonical context. ### Time 20 minutes. ### Real-world scenarios - **A — Tenant isolation strategy** (row-level security vs schema- per-tenant vs DB-per-tenant). - **B — Background-job platform** (BullMQ / Sidekiq / SQS / Temporal). - **C — Caching strategy** (Redis vs in-process vs CDN). ### Setup `mkdir -p docs && [ -f docs/DECISIONS.md ] || printf "# Architecture Decision Records\n\n" > docs/DECISIONS.md`. ### Steps 1. Pick one decision you've explained at least twice in chat. 2. Draft the ADR using the §5.3 template — ID, ISO date, Status, Context, Decision, **Consequences**. Make Consequences specific (paths, file patterns, forbidden alternatives). 3. Add a one-line pointer from `AGENTS.md` to `docs/DECISIONS.md`. 4. Smoke test: fresh session, ask the agent a question whose right answer requires this ADR. Confirm it references the ADR. ### Deliverable The committed ADR + `labs/notes/5.1-adr.md` with the ADR ID and the transcript snippet from step 4. ### Success criteria - The Consequences section names **at least one concrete** thing a future reader can act on (a path, a forbidden alternative, a re-test trigger). - The smoke test produces an answer that *references* the ADR, not one that re-invents the decision. ### Reflection - Which Consequence did you almost leave out because it felt "obvious"? Future-you and future-agents won't find it obvious. ### Stretch - Grep the repo for places that deviate from the ADR. Note them in the Consequences section ("currently honored except at `<path>`"). --- ## Lab 5.2 — Audit harness memory in one pass ### Objective Make your Layer-2 memory trustworthy: delete stale, merge duplicates, tighten the rest with explicit *why* and *how to apply* lines. ### Time 20 minutes. ### Real-world scenarios - **A — After 2 weeks of solo intensive work.** ~25 entries, some contradictory. Resolve. - **B — First month of team adoption.** Mix of legitimately-personal and project-scoped. Separate. - **C — Inheriting a months-old project.** Most entries written by someone else; trust unknown. One-pass cleanup. ### Setup Locate the directory (Claude Code: `~/.claude/projects/<project>/memory/`). ### Steps 1. List every memory file. Tag each as `user` / `feedback` / `project` / `reference` mentally. 2. Make a single pass: delete stale, delete inferable, merge duplicates. Edit any survivor missing a `Why:` or `How to apply:` line. 3. Update `MEMORY.md` so the index matches the file set exactly. ### Deliverable The pruned directory + `labs/notes/5.2-audit.md` with counts (before / after / merged / deleted / edited) and one example entry that survived rewrite for clarity. ### Success criteria - The file count went **down** (or stayed level via merges). - Every survivor has a `Why:` and a `How to apply:` (or equivalent). - `MEMORY.md` and the directory agree — no orphans either side. ### Reflection - Which memory was most embarrassing? Often: a phantom "user prefers X" written in a moment that wasn't a preference. ### Stretch - Add a quarterly audit reminder to your calendar. --- ## Lab 5.3 — Run a hierarchical retrieval on one question ### Objective Outperform "blanket-load the whole repo" with a Haiku → Sonnet pipeline on one real cross-repo question. ### Time 20 minutes. ### Real-world scenarios - **A — "Where do we depend on the old `created_at_unix` field?"** - **B — "What's the blast radius if I change the `User` shape?"** - **C — "Find every rate-limit policy across the monorepo."** ### Setup A scratch session. ### Steps 1. **Scout (Haiku).** `claude --model claude-haiku-4-5-20251001 "list files referencing <pattern>. Paths only."` Curate the top 5 paths. 2. **Reason (Sonnet, think hard).** Fresh session: feed the 5 paths and the question. Have it read those *and only those* and answer. 3. Compare against your gut answer. Note any hallucinated paths (there should be none). ### Deliverable `labs/notes/5.3-retrieval.md` with the question, the 5 paths, the final answer, and one-line "rule I now apply" (e.g., "for blast- radius questions, scout first, never blanket-load"). ### Success criteria - The final answer cites real files (no hallucinated paths). - Total tokens used are *measurably lower* than a "read the whole repo" approach would have been — explained in one sentence. ### Reflection - Where did the scout step's file choice surprise you — missing something obvious, or finding something you'd forgotten? ### Stretch - Bake the two-step pipeline into a sub-agent (Module 6 preview). --- ## Lab 5.4 — Compaction recovery drill ### Objective Rehearse the file-based recovery move so you reach for it instinctively when a session is damaged. ### Time 15 minutes. ### Real-world scenarios - **A — Multi-day refactor.** Day 1 you scoped, Day 3 the session is wrecked. - **B — Vacation return.** Branch has open conflicts; you need a briefing. - **C — Contractor handoff.** External engineer needs zero-prior- context ramp. ### Setup A real branch covered by your ADRs (Lab 5.1). ### Steps 1. Start a session. Have it summarize current state. Save the summary as `tmp/before.md`. 2. Force decay: run `/compact` (or push past the auto threshold). 3. Ask the same question; save as `tmp/after-damage.md`. 4. **Recover via files**, not chat: end the session, confirm `AGENTS.md` points at `docs/DECISIONS.md`, start a fresh session, re-ask. Save as `tmp/recovered.md`. ### Deliverable `labs/notes/5.4-recovery.md` showing the three snippets side by side and a one-line "first move when I see drift." ### Success criteria - The recovered summary matches `tmp/before.md` in substance, without you re-explaining in chat. - If it doesn't, your `AGENTS.md` pointer is too vague or the ADR is missing detail — note which. ### Reflection - What was your *instinct* upon seeing the damaged summary — chat re-explain, or file edit? Train toward the file. ### Stretch - Add a `ramp` skill that loads `docs/DECISIONS.md`, `AGENTS.md`, and the top-3 recent diffs. Default cold-start. --- ## Wrap-up In the repo (committed): `docs/DECISIONS.md` with at least one ADR; `AGENTS.md` linking to it; possibly a `ramp` skill. In your harness memory dir: curated, deduped, with `Why:`/ `How to apply:` on each entry. In `labs/notes/`: `5.1` through `5.4`. The next module's specialized agents read from this stack. Without it, they guess. **Next:** [Labs — Module 6: The Meta-Agent Factory & Verification Frontier](06-meta-agent-factory-labs.md)