Skip to content

Commit a41447f

Browse files
committed
docs: add persistent markdown working memory guide
1 parent c9f670c commit a41447f

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

docs/WORKING_MEMORY.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Persistent Markdown Working Memory
2+
3+
> A human-readable `.md` file that persists across conversations — inspired by Mastra's agent notepad pattern. Complements the Baddeley cognitive working memory with durable, editable state.
4+
5+
---
6+
7+
## Overview
8+
9+
Each agent maintains a markdown file at `~/.wunderland/agents/{seedId}/working-memory.md`. This file is:
10+
11+
- **Injected** into every prompt as a `## Persistent Memory` section
12+
- **Updated** by the agent via tools during conversation
13+
- **Human-editable** — open the file in any text editor to add or correct information
14+
- **Budget-capped** at 5% of the prompt token budget to avoid context bloat
15+
16+
```mermaid
17+
flowchart LR
18+
A[working-memory.md] -->|read on every turn| B[PromptBuilder]
19+
B -->|"## Persistent Memory"| C[LLM Prompt]
20+
C -->|tool call| D[update_working_memory]
21+
D -->|write| A
22+
```
23+
24+
## How It Coexists with Baddeley Cognitive Memory
25+
26+
| Aspect | Markdown Working Memory | Baddeley Cognitive Memory |
27+
|--------|------------------------|--------------------------|
28+
| **Persistence** | Survives restarts, stored on disk | Ephemeral, lives in RAM per session |
29+
| **Capacity** | 5% of token budget (~200-800 tokens) | 7 +/- 2 slots, personality-modulated |
30+
| **Content** | User preferences, project context, facts | Active reasoning slots, recent stimuli |
31+
| **Update mechanism** | Explicit tool call or manual edit | Automatic decay and activation |
32+
| **Visibility** | Human-readable `.md` file | Internal cognitive model |
33+
| **Purpose** | Long-term agent personalization | Short-term cognitive processing |
34+
35+
Both systems contribute to the prompt simultaneously — they are complementary, not competing.
36+
37+
## Tools
38+
39+
### `read_working_memory`
40+
41+
Returns the current contents of the agent's working memory file.
42+
43+
```json
44+
{ "name": "read_working_memory" }
45+
```
46+
47+
### `update_working_memory`
48+
49+
Replaces the entire file content. The agent decides what to keep, add, or remove.
50+
51+
```json
52+
{
53+
"name": "update_working_memory",
54+
"input": {
55+
"content": "## User Preferences\n- Prefers concise answers\n- Timezone: PST\n\n## Current Project\n- Building a REST API with Hono\n- Database: PostgreSQL\n"
56+
}
57+
}
58+
```
59+
60+
## Default Template
61+
62+
New agents start with a minimal template:
63+
64+
```markdown
65+
## User Preferences
66+
<!-- Agent will fill in learned preferences -->
67+
68+
## Current Project
69+
<!-- Context about what the user is working on -->
70+
71+
## Key Facts
72+
<!-- Important information to remember across sessions -->
73+
```
74+
75+
## Custom Templates
76+
77+
Override the default via `agent.config.json`:
78+
79+
```json
80+
{
81+
"workingMemoryTemplate": "## Client Profile\n\n## Open Tasks\n\n## Decisions Log\n"
82+
}
83+
```
84+
85+
## Prompt Injection
86+
87+
On every turn, `PromptBuilder` reads the file and injects it:
88+
89+
```
90+
## Persistent Memory
91+
<contents of working-memory.md>
92+
```
93+
94+
The section is capped at 5% of the total prompt token budget. If the file exceeds this limit, it is truncated with a warning appended to the prompt.
95+
96+
## Manual Editing
97+
98+
The file is plain markdown — edit it anytime:
99+
100+
```bash
101+
# Open in your editor
102+
vim ~/.wunderland/agents/my-agent/working-memory.md
103+
```
104+
105+
Changes are picked up on the next conversation turn with no restart required.

0 commit comments

Comments
 (0)