Skip to content

Commit 3b5c883

Browse files
committed
Improve agent protocol: peek-then-drill, concrete write triggers, multi-point recall
- Rewrite README workflow: two-phase recall (peek brief → drill get), recall trigger table (6 moments), write trigger table (6 types), end-of-task writes - Update MCP tool descriptions to reinforce peek-then-drill pattern: memory_recall emphasizes format=brief first, memory_get is the drill step, memory_add lists concrete trigger points - Address real agent behavior problems: agents reading body on broad queries, only recalling at session start, not knowing when to write memories
1 parent 9be4419 commit 3b5c883

2 files changed

Lines changed: 68 additions & 14 deletions

File tree

README.md

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,66 @@ Tags use `prefix:value` format for consistent discovery:
209209

210210
### Recommended Workflow
211211

212-
1. **RECALL before working** — always check existing knowledge before starting a task
213-
2. **ADD after learning** — record discoveries, decisions, and observations immediately
214-
3. **SUPERSEDE, don't edit** — when knowledge changes, add a new memory and deprecate the old one
215-
4. **CHECK STALENESS periodically** — use `memory stale` to maintain knowledge quality
212+
#### 1. READ — Peek then Drill (two-phase recall)
213+
214+
Always use a **two-phase** approach. Never go straight to body text on broad queries.
215+
216+
**Phase A — Peek** (scan titles, zero body text):
217+
```bash
218+
memory recall --tag topic:gateway --format brief --expand 0
219+
```
220+
Returns `[ID] Title (confidence)` one-liners. Minimal tokens. Do this FIRST.
221+
222+
**Phase B — Drill** (read full body of specific memories):
223+
```bash
224+
memory get DEC_handler_context_pattern
225+
```
226+
Only after peeking — pick the 2-3 most relevant IDs and `get` them individually.
227+
228+
**When to recall** — recall is NOT just a session-start ritual. Recall at each of these moments:
229+
230+
| Trigger | What to recall |
231+
|---------|---------------|
232+
| Session start | `recall --format brief --limit 20 --sort newest` |
233+
| New task or topic | `recall --tag topic:<X> --format brief` |
234+
| Entering unfamiliar code | `recall --tag repo:<X> --type fact --format brief` |
235+
| Before a design decision | `recall --tag topic:<X> --type dec` |
236+
| When stuck or debugging | `recall <error keywords>` |
237+
| Before implementing a pattern | `recall --tag intent:coding-style --type pref` |
238+
239+
#### 2. WRITE — Record at specific trigger points
240+
241+
Recording memories is NOT optional. Write at these concrete moments:
242+
243+
| Trigger | Type | Example |
244+
|---------|------|---------|
245+
| Chose approach A over B | `dec` | "Use tl::expected over exceptions" |
246+
| Fixed a non-obvious bug | `mem` | "EntityCache race condition fix" |
247+
| Discovered undocumented API | `fact` | "Routes match in registration order" |
248+
| User stated a preference | `pref` | "Prefer Zustand over Redux" |
249+
| Identified a risk | `risk` | "JWT secret hardcoded in tests" |
250+
| Question remains unanswered | `q` | "Should synthetic components expose operations?" |
251+
252+
**End-of-task writes**: summarize architecture learned (`fact`), record conventions (`pref`), note anything a future agent needs (`mem`), capture unfinished goals (`goal`).
253+
254+
**Write quality rules**:
255+
- `--tags` is mandatory — without tags, the memory is unfindable
256+
- `--body` must be self-contained with file paths and concrete details
257+
- Use `--rebuild` flag to make new memories immediately searchable
258+
259+
#### 3. SUPERSEDE, don't edit
260+
261+
When knowledge changes, add a new entry with `--supersedes OLD_ID` and deprecate the old one.
262+
263+
#### 4. CHECK STALENESS periodically
264+
265+
Run `memory stale` at the start of long sessions to keep the graph accurate.
216266

217267
### Context Window Optimization
218268

219-
- Default `recall` omits body text — use `memory get <ID>` only when you need details
220-
- Use `--format brief` for initial scanning, then drill into specific IDs
221-
- Use `--limit 10` when exploring broad topics
222-
- Use `--expand 0` to skip graph expansion for exact matches only
269+
- `recall` omits body by default — this is intentional, not a limitation
270+
- **Peek** with `--format brief`**drill** with `get <ID>` — this is the core pattern
271+
- Use `--limit 10` and `--expand 0` when exploring broad topics
223272
- Use `--tag` filters to narrow results instead of free-text
224273
- Use `memory tags` to discover available tag prefixes before filtering
225274

src/ai_memory_protocol/mcp_server.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def create_mcp_server(name: str = "ai-memory-protocol") -> Server:
6767
description=(
6868
"Search memories by free text query and/or tags. "
6969
"Returns matching memories formatted for context windows. "
70-
"Use this FIRST to check existing knowledge before starting work."
70+
"Use format='brief' FIRST to peek at titles, then memory_get to drill into specific IDs. "
71+
"Recall at EVERY topic transition: new task, unfamiliar code, before decisions, when stuck — not just session start."
7172
),
7273
inputSchema={
7374
"type": "object",
@@ -123,8 +124,9 @@ def create_mcp_server(name: str = "ai-memory-protocol") -> Server:
123124
Tool(
124125
name="memory_get",
125126
description=(
126-
"Get full details of a specific memory by ID. "
127-
"Always shows body text. Use after recall to drill into a specific memory."
127+
"Get full details of a specific memory by ID — the DRILL step. "
128+
"Always shows body text. Use AFTER memory_recall(format='brief') to read "
129+
"the 2-3 most relevant memories. Never skip the peek step."
128130
),
129131
inputSchema={
130132
"type": "object",
@@ -140,9 +142,12 @@ def create_mcp_server(name: str = "ai-memory-protocol") -> Server:
140142
Tool(
141143
name="memory_add",
142144
description=(
143-
"Record a new memory. Use when you discover, decide, or observe something important. "
144-
"Always include tags for discoverability. Always include body with enough context "
145-
"that a future agent can act on it without re-reading source files."
145+
"Record a new memory. You MUST use this at specific trigger points: "
146+
"chose approach A over B → dec; fixed non-obvious bug → mem; "
147+
"discovered undocumented pattern → fact; user stated preference → pref; "
148+
"identified risk → risk; question unanswered → q. "
149+
"Also batch-write at end of task: architecture learned → fact, conventions → pref. "
150+
"Tags are mandatory. Body must be self-contained with file paths and concrete details."
146151
),
147152
inputSchema={
148153
"type": "object",

0 commit comments

Comments
 (0)