@markus-global/cli 0.11.2 → 0.11.3-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/start.js +5 -2
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +1254 -1121
- package/dist/web-ui/assets/{CommentInput-Cgu8208h.js → CommentInput-C-niUbUY.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-rzRUDj8T.js → ContentRenderer-DxsnJJRX.js} +2 -2
- package/dist/web-ui/assets/{DeliverableShareModal-BvfmqTNG.js → DeliverableShareModal-DV3TiZx0.js} +1 -1
- package/dist/web-ui/assets/{Deliverables-DKTLnaF8.js → Deliverables-tlLsJnxZ.js} +1 -1
- package/dist/web-ui/assets/{Notifications-CWaO9onn.js → Notifications-4KXYRdkr.js} +1 -1
- package/dist/web-ui/assets/{Search-D_C5Eyed.js → Search-CPFwZv1U.js} +1 -1
- package/dist/web-ui/assets/{Settings-B5Ib6SFf.js → Settings-DIa-_qre.js} +6 -6
- package/dist/web-ui/assets/{Store-D__pfqoc.js → Store-JWjwXfTU.js} +1 -1
- package/dist/web-ui/assets/Team-COBxn96h.js +84 -0
- package/dist/web-ui/assets/{Work-BJ7kXixx.js → Work-BScJUqWL.js} +1 -1
- package/dist/web-ui/assets/{arc-BN0GMYN6.js → arc-DPZmpo1U.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-BP5Nnl2Y.js → architectureDiagram-3BPJPVTR-DlOs02JO.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-nKHUCU_z.js → blockDiagram-GPEHLZMM-C7qsXNUe.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-DoS0wcHh.js → c4Diagram-AAUBKEIU-Drwp-rtM.js} +1 -1
- package/dist/web-ui/assets/channel-DCChB-1T.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-CP54_XNl.js → chunk-2J33WTMH-VgR09Mqk.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-DMvJaJb7.js → chunk-4BX2VUAB-CuwDpBRL.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-DQnZgoOO.js → chunk-55IACEB6-nC7YWJ_i.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-B5_3LI53.js → chunk-727SXJPM-Dw6mBsRE.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-B5Mh5bI_.js → chunk-AQP2D5EJ-CPhNJbHl.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-mjYTpuBm.js → chunk-FMBD7UC4-AyhQakG8.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-BxTrseJg.js → chunk-ND2GUHAM-DgYemv8I.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-C1do5brE.js → chunk-QZHKN3VN-CLdqxrFB.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-CrNiYfSI.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-CrNiYfSI.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-DMn7aSDK.js → cose-bilkent-S5V4N54A-DrOgwDIH.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-CE-tTagY.js → dagre-BM42HDAG-DhoJiA83.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-BwyvxbJa.js → diagram-2AECGRRQ-BDILSgqK.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-Nopndxl0.js → diagram-5GNKFQAL-CeXywd1i.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-CGTjHHnD.js → diagram-KO2AKTUF-Bi4RlMT0.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-DhC3AqLA.js → diagram-LMA3HP47-Cw1yxk8b.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-BIuzyWJO.js → diagram-OG6HWLK6-Bl857da2.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-ClO_djcO.js → docx-preview-CjoUhrMq.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-Nmfi9Wv0.js → erDiagram-TEJ5UH35-DEiaMhuV.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-BVAM5QzO.js → flowDiagram-I6XJVG4X-BgKZhO0h.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-BGdTbY0A.js → ganttDiagram-6RSMTGT7-Dkx-EaS8.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-BMfug5mp.js → gitGraphDiagram-PVQCEYII-DXaQwA0y.js} +1 -1
- package/dist/web-ui/assets/{index-1X1Ykov8.js → index-C_QhfMcC.js} +72 -72
- package/dist/web-ui/assets/index-DEN_qReg.css +1 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-DAqSLNMU.js → infoDiagram-5YYISTIA-Dpx9IOkx.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-Bro4RrlG.js → ishikawaDiagram-YF4QCWOH-BWqWgitQ.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-CdRHOaID.js → journeyDiagram-JHISSGLW-BBwIZ4k9.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-9iLNl-rB.js → kanban-definition-UN3LZRKU-C_MRWV8R.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-BRHCbDDt.js → mermaid.core-BMAh3nnq.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-BLm-XQ6W.js → mindmap-definition-RKZ34NQL-B6vJQcat.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-ith90T5A.js → pieDiagram-4H26LBE5-BxdEttqt.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-Cb08oHG7.js → quadrantDiagram-W4KKPZXB-gsNs2VfP.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-DzMKi4w8.js → requirementDiagram-4Y6WPE33-BSC9KvC2.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-C0Wv4A7m.js → sankeyDiagram-5OEKKPKP-DktAZfe_.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-C_HL9WB0.js → sequenceDiagram-3UESZ5HK-BIPt8kGU.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-BFfTVEYQ.js → stateDiagram-AJRCARHV-DiXmJWB0.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-COOgTXIX.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-cyPnAADn.js → timeline-definition-PNZ67QCA-LRi7H35g.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-Cb82-9OZ.js → vennDiagram-CIIHVFJN-DWQ1I022.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-BTW1NXXR.js → wardley-L42UT6IY-BUb6dYqN.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-C_F_dT6n.js → wardleyDiagram-YWT4CUSO-BYE1B3xT.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-clcfplhG.js → xychartDiagram-2RQKCTM6-D-pS2-Sa.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/README.md +93 -0
- package/docs/api/api.md +353 -0
- package/docs/architecture/agent-runtime.md +341 -0
- package/docs/architecture/architecture-fragility.md +184 -0
- package/docs/architecture/architecture.md +938 -0
- package/docs/architecture/cognitive-architecture.md +322 -0
- package/docs/architecture/concurrent-processing.md +550 -0
- package/docs/architecture/frontend/team-chat.md +312 -0
- package/docs/architecture/learning-loop.md +340 -0
- package/docs/architecture/llm-provider-timeouts.md +60 -0
- package/docs/architecture/mailbox-system.md +1635 -0
- package/docs/architecture/memory-system.md +533 -0
- package/docs/architecture/prompt-engineering.md +1377 -0
- package/docs/architecture/state-machines.md +665 -0
- package/docs/architecture/state-ownership.md +83 -0
- package/docs/architecture/streaming-and-reattach.md +193 -0
- package/docs/architecture/tool-system.md +266 -0
- package/docs/design/deliverable-sharing.md +238 -0
- package/docs/guides/coding-tools.md +765 -0
- package/docs/guides/community.md +104 -0
- package/docs/guides/development.md +179 -0
- package/docs/guides/guide.md +362 -0
- package/docs/guides/release-and-distribution.md +165 -0
- package/docs/guides/remote-access.md +286 -0
- package/docs/guides/skill-ecosystem.md +129 -0
- package/docs/records/agent-platform-friction-2026-10.md +98 -0
- package/docs/records/animation-budget-focus-vs-visibility-2026-10-08.md +110 -0
- package/docs/records/audit-fixes-2026-09.md +173 -0
- package/docs/records/branch-consolidation.md +597 -0
- package/docs/records/file-edit-literal-replacement-fix.md +132 -0
- package/docs/records/message-stop-cancel-fix-plan.md +209 -0
- package/docs/records/platform-hardening-2026-10.md +1365 -0
- package/docs/records/session-identity-plan.md +130 -0
- package/docs/records/settings-model-routing-first-visit-fix.md +101 -0
- package/docs/records/team-chat-stream-transport-vs-turn-2026-10-08.md +152 -0
- package/package.json +2 -1
- package/templates/roles/HANDBOOK.md +12 -7
- package/dist/web-ui/assets/Team-FFbGLcXj.js +0 -84
- package/dist/web-ui/assets/channel-C_kHFvaW.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-UF2PuXCi.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-UF2PuXCi.js +0 -1
- package/dist/web-ui/assets/index-3PQIqBtv.css +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-DuO1A2q2.js +0 -1
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
# Agent Memory System
|
|
2
|
+
|
|
3
|
+
Architecture and data flows for the Markus agent memory system. Persistent cognition uses
|
|
4
|
+
**NOTEBOOK.md** (cognitive workspace) plus **`knowledge.md`** as the single long-term store
|
|
5
|
+
(permanent curated knowledge + the observation buffer). The former second half of the old
|
|
6
|
+
"dual store", `state.md`, has **retired** — its situational state now lives in the notebook's
|
|
7
|
+
`system` tier (see §2 / §3). Legacy `MEMORY.md` / `memories.json` / `state.md` files are still
|
|
8
|
+
read once on load and migrate into `knowledge.md` (migration-read layer: read old, write new only).
|
|
9
|
+
Grounded in Tulving-style procedural / semantic / episodic persistence plus cognitive-science
|
|
10
|
+
working-memory models.
|
|
11
|
+
|
|
12
|
+
> **SSOT budgets/injection**: [agent-runtime.md](./agent-runtime.md) §6.
|
|
13
|
+
> **Learning / dream librarian**: [learning-loop.md](./learning-loop.md).
|
|
14
|
+
|
|
15
|
+
## 1. Design Principles
|
|
16
|
+
|
|
17
|
+
1. **Workspace + single semantic store**: `NOTEBOOK.md` is the situational cognitive workspace;
|
|
18
|
+
`knowledge.md` holds permanent curated knowledge plus the observation buffer. Situational
|
|
19
|
+
("current") state lives in the notebook's `system` tier rather than a second file — the old
|
|
20
|
+
`state.md` half **retired** (see §2). Observations buffer is never fully prompt-injected.
|
|
21
|
+
Legacy `MEMORY.md` / `memories.json` / `state.md` MUST migrate into `knowledge.md` on first load (read old, write new only).
|
|
22
|
+
2. **Tulving mapping + notebook**: Persistent layers align with Tulving-style cognition — **Procedural** (ROLE.md), **Semantic** (`knowledge.md`), **Episodic** (sessions + activities). The **Notebook** replaces volatile in-memory working memory with a persistent scratchpad always injected (via the volatile `[Live context]` tail by Scheme A — not as a system-prompt segment).
|
|
23
|
+
3. **SQLite for history**: Activity history lives in SQLite — indexed, searchable, and queryable via tools.
|
|
24
|
+
4. **Context is currency**: Every byte in the LLM prompt competes for limited context window. Retrieval must maximize signal-to-noise.
|
|
25
|
+
5. **Agent autonomy**: Agents decide what to remember (`memory_save`), what to distill (`memory_update`), and how to evolve (ROLE.md edits).
|
|
26
|
+
|
|
27
|
+
### Cognitive Science Foundations
|
|
28
|
+
|
|
29
|
+
| Concept | Markus mapping |
|
|
30
|
+
|---------|----------------|
|
|
31
|
+
| **Baddeley — Working Memory Model** | `NOTEBOOK.md` = central executive + visuospatial sketchpad: limited-capacity, actively maintained situational state |
|
|
32
|
+
| **Cowan — Embedded Processes** | Capped `knowledge.md` = activated long-term memory in prompt (profile-dependent) |
|
|
33
|
+
|
|
34
|
+
### 1.1 Spec: knowledge.md (single long-term store)
|
|
35
|
+
|
|
36
|
+
MUST: Prefer `knowledge.md` on disk under the agent data dir as the single long-term store.
|
|
37
|
+
MUST: On first load, if only legacy `MEMORY.md` exists, migrate it into `knowledge.md`.
|
|
38
|
+
MUST: Prompt injection of knowledge MUST honor `KNOWLEDGE_PROMPT_MAX_TOKENS`
|
|
39
|
+
(`0` for reflex profile — omit full dump).
|
|
40
|
+
MUST: `MEMORY_MD_CURATED_MAX_CHARS` (injected-section budget, 15,000) is a **soft** line, enforced at load in
|
|
41
|
+
**report-only** mode: `MemoryStore.enforceMemoryBudgets()` runs on construction/load and only
|
|
42
|
+
logs + feeds the in-prompt health banner. The platform never rewrites the agent's curated prose
|
|
43
|
+
(the old load-time archiving of the largest curated sections was removed — see
|
|
44
|
+
[platform-hardening-2026-10.md](../records/platform-hardening-2026-10.md) §24). The **hard ceiling**
|
|
45
|
+
`MEMORY_MD_CURATED_HARD_MAX_CHARS` (3× the soft budget) IS enforced, but **fail-closed on the
|
|
46
|
+
write path**: `addLongTermMemory` refuses the write (nothing written, actionable reason) and the
|
|
47
|
+
agent consolidates with its own tools (`memory_organize` / `memory_update`). The observation
|
|
48
|
+
buffer (`MEMORY_OBSERVATIONS_MAX_CHARS`) is a **separate, independent** advisory line with its
|
|
49
|
+
own hard ceiling (`MEMORY_OBSERVATIONS_HARD_MAX_CHARS`), enforced on the append path.
|
|
50
|
+
MUST: `knowledge-archive.json` (`knowledge-archive-scaffolding.json` for the non-knowledge part)
|
|
51
|
+
is archive-only — searchable via `memory_search`, but **never prompt-injected**.
|
|
52
|
+
MUST: `memory_update mode="forget"` (`MemoryStore.removeLongTermSection`) is the curated-section
|
|
53
|
+
**forget primitive**; forgetting `## _observations` is refused (delete observations by id instead).
|
|
54
|
+
MUST: `knowledge.md` / `NOTEBOOK.md` MUST be persisted with `writeFileAtomic` (tmp + rename) so a
|
|
55
|
+
half-written file is never parsed back as real state on the next load.
|
|
56
|
+
MUST: `memory_update_longterm` / curated updates write `knowledge.md`.
|
|
57
|
+
MUST: `memory_save` → `## _observations`; `memory_update` → named curated section.
|
|
58
|
+
|
|
59
|
+
Test IDs: `A-knowledge-cap`.
|
|
60
|
+
| **Kahneman — Dual Process** | System 1 = fast retrieval (`memory_search`, prompt injection); System 2 = slow, deliberate recall the agent triggers explicitly (`memory_search` / `kb_search`) — the old pre-call CPP pipeline is gone |
|
|
61
|
+
|
|
62
|
+
## 2. Four-Layer Architecture
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
┌───────────────────────────────────────────────────────────────┐
|
|
66
|
+
│ Procedural Memory — "how I operate" │
|
|
67
|
+
│ ROLE.md + HEARTBEAT.md + Skills │
|
|
68
|
+
│ Most stable. Loaded at startup. Shapes every response. │
|
|
69
|
+
│ Code: RoleLoader, Agent.reloadRole(), skill system │
|
|
70
|
+
├───────────────────────────────────────────────────────────────┤
|
|
71
|
+
│ Semantic Memory — "what I know" │
|
|
72
|
+
│ knowledge.md — permanent curated sections │
|
|
73
|
+
│ (retired) —> NOTEBOOK.md system tier (situational state) │
|
|
74
|
+
│ ## _observations — raw buffer (not fully injected) │
|
|
75
|
+
│ Code: MemoryStore (addEntry, search, addLongTermMemory) │
|
|
76
|
+
│ Tools: memory_save, memory_search, memory_update, notebook ops│
|
|
77
|
+
├───────────────────────────────────────────────────────────────┤
|
|
78
|
+
│ Episodic Memory — "what I've experienced" │
|
|
79
|
+
│ Current episode: sessions/*.json (active conversation) │
|
|
80
|
+
│ Past episodes: SQLite agent_activities (searchable history)│
|
|
81
|
+
│ Code: MemoryStore (sessions) + SqliteActivityRepo │
|
|
82
|
+
│ Tools: recall_activity (list / search / get) │
|
|
83
|
+
├───────────────────────────────────────────────────────────────┤
|
|
84
|
+
│ Notebook — persistent cognitive workspace │
|
|
85
|
+
│ NOTEBOOK.md — keyed entries (agent / system managed) │
|
|
86
|
+
│ Tools: notebook_upsert, notebook_clear, notebook_read │
|
|
87
|
+
│ Code: Agent + MemoryStore (loadNotebook / saveNotebook) │
|
|
88
|
+
└───────────────────────────────────────────────────────────────┘
|
|
89
|
+
|
|
90
|
+
Not memory (never read back by agent):
|
|
91
|
+
daily-logs/*.md — audit trail for humans only
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Notebook (NOTEBOOK.md)
|
|
95
|
+
|
|
96
|
+
Persistent markdown replacing the former volatile in-memory working memory.
|
|
97
|
+
|
|
98
|
+
| Attribute | Value |
|
|
99
|
+
|-----------|-------|
|
|
100
|
+
| Storage | `~/.markus/agents/{id}/NOTEBOOK.md` |
|
|
101
|
+
| Format | `## key` headings with metadata comments + body text |
|
|
102
|
+
| Entry fields | `key`, `text`, `managed` (`agent` \| `system`), `updatedAt` |
|
|
103
|
+
| Prompt injection | Always loaded as `## Notebook`, bounded to `NOTEBOOK_MAX_ENTRIES` (16) entries / `NOTEBOOK_PROMPT_MAX_CHARS` (6000) chars. Oversized entries are truncated inline (never dropped whole). |
|
|
104
|
+
| Limits | **16 total** entries (`NOTEBOOK_MAX_ENTRIES`) — the CROSS-TIER cap; **4 agent** entries (`NOTEBOOK_MAX_AGENT_ENTRIES`); `NOTEBOOK_MAX_CHARS_PER_ENTRY` (6000) per entry; key ≤ `NOTEBOOK_KEY_MAX_CHARS` (64). |
|
|
105
|
+
| TTL | Per tier: `agent` 96h, `system` 24h (`NOTEBOOK_TTL_MS_AGENT` / `NOTEBOOK_TTL_MS_SYSTEM`). Entries past their TTL are dropped on load, after every write, and again before injection. |
|
|
106
|
+
| Eviction | Oldest-`updatedAt`-first. Tier order: `system` → `agent` — the agent's own notes are the **last** to go. |
|
|
107
|
+
|
|
108
|
+
**Managed tags**:
|
|
109
|
+
|
|
110
|
+
- `agent` — written via `notebook_upsert` / `notebook_clear`
|
|
111
|
+
- `system` — triage → `"triage-decision"`, deliberation → `"deliberation"`, etc.
|
|
112
|
+
|
|
113
|
+
**Lifecycle**: Loaded at agent startup → **normalized on load** (TTL + caps; trimmed result is persisted immediately) → updated in-process → persisted with a 2s debounce **bounded by `NOTEBOOK_PERSIST_MAX_WAIT_MS` (10s)** so a chatty turn cannot defer the write indefinitely. Survives restarts.
|
|
114
|
+
**Cleanup**: `notebook_clear({ key })` removes one entry; `notebook_clear` without key clears the whole notebook. TTL handles passive expiry; `notebook_clear` handles deliberate removal. Prompt guidance: clear when a task completes or context goes stale.
|
|
115
|
+
|
|
116
|
+
#### Invariants (§2 Notebook lifecycle)
|
|
117
|
+
|
|
118
|
+
The notebook is a RESIDENT prompt region, so it needs all four mechanisms that keep a
|
|
119
|
+
resident region honest. Historically only the storage-side per-entry cap existed, and
|
|
120
|
+
the entry cap was applied on **one** write path — the other writers
|
|
121
|
+
(`triage` → `triage-decision`, `deliberation`) called
|
|
122
|
+
`workingMemory.set()` directly and were never counted. The load path trimmed
|
|
123
|
+
nothing. Result: a real notebook reached **26 entries / 33 KB** against a nominal
|
|
124
|
+
cap of 4, including an 18-day-old triage decision that
|
|
125
|
+
was re-injected on every turn.
|
|
126
|
+
|
|
127
|
+
| # | Invariant | Authority |
|
|
128
|
+
|---|-----------|-----------|
|
|
129
|
+
| 1 | Entry count ≤ 16 (and agent tier ≤ 4) | `pruneNotebookEntries` |
|
|
130
|
+
| 2 | No entry older than its tier TTL | `pruneNotebookEntries` + `notebookTtlMs` |
|
|
131
|
+
| 3 | Per-entry char cap; `relevant-context` capped tighter (`NOTEBOOK_RELEVANT_CONTEXT_MAX_CHARS`) | `Agent.writeNotebookEntry` |
|
|
132
|
+
| 4 | Injected block ≤ 6000 chars, deterministic order, index line for what did not fit | `Agent.getDynamicContext` |
|
|
133
|
+
| 5 | Every write goes through `Agent.writeNotebookEntry` | call-site discipline |
|
|
134
|
+
| 6 | Disk matches memory after normalization | `Agent.enforceNotebookLimits` + `persistNotebookSync` |
|
|
135
|
+
|
|
136
|
+
`pruneNotebookEntries` is the single authority for "notebook state is legal" and is
|
|
137
|
+
idempotent. It is applied at three points: **on load**, **after every write**, and
|
|
138
|
+
**before injection**. Because it is called on load, an oversized notebook written by
|
|
139
|
+
an older build self-heals at the next startup instead of persisting forever.
|
|
140
|
+
|
|
141
|
+
Ordering in the injected block is `updatedAt` DESC with a `key` ASC tie-break. Two
|
|
142
|
+
properties matter: staleness ranking (the entries that matter most are read first)
|
|
143
|
+
and **byte stability** — for the same logical state the block must serialize
|
|
144
|
+
identically, or every assembly dirties the volatile tail and re-bills those tokens.
|
|
145
|
+
Map insertion order satisfied neither (evict + re-insert permutes the block).
|
|
146
|
+
|
|
147
|
+
**Relationship to other layers**:
|
|
148
|
+
|
|
149
|
+
- More volatile than `knowledge.md` curated sections but always injected (volatile `[Live context]` tail)
|
|
150
|
+
- Raw observations → `memory_save` → `knowledge.md` `## _observations`
|
|
151
|
+
- Validated knowledge → `memory_update` → curated sections above `_observations`
|
|
152
|
+
|
|
153
|
+
### Code Location
|
|
154
|
+
|
|
155
|
+
| Concern | Implementation | File |
|
|
156
|
+
|---------|---------------|------|
|
|
157
|
+
| Semantic + Episodic (sessions) | `MemoryStore` | `packages/core/src/memory/store.ts` |
|
|
158
|
+
| Notebook parse/serialize | `loadNotebook`, `saveNotebook` | `packages/core/src/memory/store.ts` |
|
|
159
|
+
| Interface | `IMemoryStore` | `packages/core/src/memory/types.ts` |
|
|
160
|
+
| Episodic (history) | `SqliteActivityRepo` | `packages/storage/src/sqlite-storage.ts` |
|
|
161
|
+
| Episodic retrieval | `recall_activity` tool | `packages/core/src/tools/recall.ts` |
|
|
162
|
+
| Procedural | `RoleLoader` | `packages/core/src/role-loader.ts` |
|
|
163
|
+
| Semantic tools | `memory_save`, `memory_search`, `memory_update` | `packages/core/src/tools/memory.ts` |
|
|
164
|
+
| Notebook tools | `notebook_upsert`, `notebook_clear`, `notebook_read` | `packages/core/src/tools/mailbox-tools.ts` |
|
|
165
|
+
| Vector search | `SemanticMemorySearch` | `packages/core/src/memory/semantic-search.ts` |
|
|
166
|
+
| Notebook runtime | `Agent.workingMemory`, prompt injection | `packages/core/src/agent.ts` |
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## 3. Semantic Memory (`knowledge.md` SSOT)
|
|
171
|
+
|
|
172
|
+
**Canonical on-disk store** for curated knowledge + the observation buffer is
|
|
173
|
+
`knowledge.md` under the agent data dir. Legacy `MEMORY.md` is migrated once on first
|
|
174
|
+
load (`ensureKnowledgeStateFiles`) and MUST NOT be written afterward. Tool results
|
|
175
|
+
SHOULD report `store: "knowledge.md"` so agents do not invent a wrong path.
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
knowledge.md
|
|
179
|
+
├── ## conventions ← agent-organized curated sections
|
|
180
|
+
├── ## procedures
|
|
181
|
+
├── ## preferences
|
|
182
|
+
├── ...
|
|
183
|
+
└── ## _observations ← raw observation buffer (NOT in prompt)
|
|
184
|
+
├── ### obs_123...
|
|
185
|
+
└── ### obs_456...
|
|
186
|
+
|
|
187
|
+
NOTEBOOK.md (system tier) ← short-lived situational state (per-tier TTL)
|
|
188
|
+
NOTEBOOK.md ← situational workspace (always in prompt)
|
|
189
|
+
MEMORY.md ← DEPRECATED legacy; migrate → knowledge/state once
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Lifecycle (Inject / Update / Clean)
|
|
193
|
+
|
|
194
|
+
| Phase | What | When |
|
|
195
|
+
|-------|------|------|
|
|
196
|
+
| **Inject** | Curated sections → `## Your Knowledge` (capped; omitted for reflex). Observations **not** injected. Notebook always (it carries the situational state that the retired `state.md` used to hold). | Every non-reflex turn packing |
|
|
197
|
+
| **Update** | `memory_save` → `_observations` (one entry; `content` required). `memory_update` / `memory_update_longterm` → named curated section (`replace` / `patch`; `append` aliases `patch`). | Immediate on tool call |
|
|
198
|
+
| **Clean** | Dream (`memory_consolidation` only): dedupe / merge / promote (3+ theme) when ≥50 observations (≤1×/day; ≤4×/day if ≥500). Empty observations rejected on write and pruned on load. Section ≤3000 (`MEMORY_MD_SECTION_MAX_CHARS`) enforced on write; the curated soft budget (≤15000, `MEMORY_MD_CURATED_MAX_CHARS`) is **report-only** at load, and the write path refuses only at the hard ceiling `MEMORY_MD_CURATED_HARD_MAX_CHARS` (45000). (The old load-time convergence/rewrite of an over-budget file was **removed** — see §8.8.) Notebook per-tier TTL prune runs on every notebook write. Post-task encode is **Distillation** (`scenario: distillation`), not Dream — see [learning-loop.md](./learning-loop.md) §0. | `consolidateMemory()` + write-time guards |
|
|
199
|
+
|
|
200
|
+
### Curated Sections
|
|
201
|
+
|
|
202
|
+
| Attribute | Value |
|
|
203
|
+
|-----------|-------|
|
|
204
|
+
| Write triggers | `memory_update` tool, Dream Cycle promotion |
|
|
205
|
+
| System prompt | Loaded as `## Your Knowledge` when knowledge token cap > 0 (excludes `## _observations`) |
|
|
206
|
+
| Limits | 3000 chars/section (`MEMORY_MD_SECTION_MAX_CHARS`), 15000 chars **injected** (`MEMORY_MD_CURATED_MAX_CHARS`); the non-injected `## _observations` buffer has its own budget (`MEMORY_OBSERVATIONS_MAX_CHARS`) |
|
|
207
|
+
| Body rule | Section bodies MUST NOT introduce sibling `## ` headings (store sanitizes `## ` → `### `) |
|
|
208
|
+
|
|
209
|
+
The agent organizes sections freely — common patterns: `conventions`, `procedures`, `preferences`, `domain-knowledge`.
|
|
210
|
+
|
|
211
|
+
### `## _observations` — Observation Buffer
|
|
212
|
+
|
|
213
|
+
| Attribute | Value |
|
|
214
|
+
|-----------|-------|
|
|
215
|
+
| Format | `### {id}` subsections with HTML comment metadata + content |
|
|
216
|
+
| Entry types | `fact`, `note`, `insight`, `task_result`, `conversation` |
|
|
217
|
+
| Write triggers | `memory_save` tool (single object; not an array), task reflection |
|
|
218
|
+
| Prompt injection | **Not** injected — searched on demand via `memory_search` |
|
|
219
|
+
| Search | Substring match + optional vector overlay (`SemanticMemorySearch`) |
|
|
220
|
+
| Max entries | 500 (oldest trimmed on save); empty `content` refused |
|
|
221
|
+
|
|
222
|
+
**Entry lifecycle**: `memory_save` → buffered in `_observations` → searched via `memory_search` → consolidated by Dream Cycle (merge/prune/promote) → promoted to curated sections in `knowledge.md`.
|
|
223
|
+
|
|
224
|
+
**Tags** (in metadata comments): `insight`, `role-evolution`, `domain:<topic>`
|
|
225
|
+
|
|
226
|
+
### Migration
|
|
227
|
+
|
|
228
|
+
1. On first load, if only legacy `MEMORY.md` exists → migrate **wholesale** into `knowledge.md` (the old knowledge/state split is gone; a retired `state.md`, if present, folds into the notebook's `system` tier as key `legacy-state`).
|
|
229
|
+
2. If `memories.json` exists → migrate entries into `knowledge.md` `## _observations`, delete JSON.
|
|
230
|
+
3. After migration, all reads/writes use `knowledge.md`; stale `MEMORY.md` is ignored.
|
|
231
|
+
|
|
232
|
+
### Convergence test IDs
|
|
233
|
+
|
|
234
|
+
`A-memory-save-rejects-array`, `A-memory-save-no-empty-write`, `A-memory-update-append-alias`,
|
|
235
|
+
`A-section-no-h2-bleed`, `A-tool-result-store-path`, `A-legacy-memory-not-written`.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 4. Memory Tools
|
|
240
|
+
|
|
241
|
+
Five primary tools. Legacy memory aliases (`memory_list`, `memory_delete`, `memory_update_longterm`) remain for backward compatibility; the notebook aliases `update_working_memory` / `clear_working_memory` were **removed** — use `notebook_upsert` / `notebook_clear`.
|
|
242
|
+
|
|
243
|
+
| Tool | Purpose |
|
|
244
|
+
|------|---------|
|
|
245
|
+
| `notebook_upsert` | Upsert a keyed entry in NOTEBOOK.md |
|
|
246
|
+
| `notebook_clear` | Remove one entry or all agent-managed entries |
|
|
247
|
+
| `memory_save` | Append one observation to `knowledge.md` `## _observations` (`content` required; rejects arrays / empty) |
|
|
248
|
+
| `memory_update` | Update curated `knowledge.md` section (`replace` / `patch`; `append`→`patch`) or delete observations (`mode: delete`) |
|
|
249
|
+
| `memory_search` | Keyword search over observations **and** curated `knowledge.md` sections (token OR-match, ranked by hits); empty query lists recent observations. Falls back from semantic→keyword when embeddings miss. |
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## 5. Episodic Memory
|
|
254
|
+
|
|
255
|
+
Everything the agent has experienced. Two substores serving different time horizons:
|
|
256
|
+
|
|
257
|
+
### Current Episode — Active Conversation
|
|
258
|
+
|
|
259
|
+
| Attribute | Value |
|
|
260
|
+
|-----------|-------|
|
|
261
|
+
| Storage | `~/.markus/agents/{id}/sessions/sess_{ts}_{rand}.json` |
|
|
262
|
+
| Format | `ConversationSession` — `{ id, agentId, messages: LLMMessage[], startedAt, lastActivityAt }` |
|
|
263
|
+
| Write triggers | `appendMessage()` on every LLM turn |
|
|
264
|
+
| Prompt injection | Automatically included as conversation history |
|
|
265
|
+
| Compaction | Full transcript kept by default; storage-side safety compaction only at `SESSION_STORAGE_COMPACT_TRIGGER = 2000` messages → keep `SESSION_STORAGE_COMPACT_KEEP = 1000`. Per-LLM-call token packing is separate (see [prompt-engineering.md](./prompt-engineering.md) §3.2) |
|
|
266
|
+
| Lifetime | Per-session; new session per task or chat |
|
|
267
|
+
|
|
268
|
+
Session ID prefixes identify type: `hb_` (heartbeat), `a2a_`, `comment_`, `sys_`, `task_`.
|
|
269
|
+
|
|
270
|
+
> **Storage compaction is a high-volume safety net, not a token saver.** Below 2000
|
|
271
|
+
> messages the full transcript is kept on disk; only pathological on-disk tool results are
|
|
272
|
+
> shrunk (`SESSION_STORAGE_TOOL_SHRINK_CHARS = 100k`). This mirrors the window-first packing
|
|
273
|
+
> policy — we do not drop turns early to "save tokens".
|
|
274
|
+
|
|
275
|
+
### Past Episodes — Activity History
|
|
276
|
+
|
|
277
|
+
| Attribute | Value |
|
|
278
|
+
|-----------|-------|
|
|
279
|
+
| Storage | SQLite `agent_activities` + `agent_activity_logs` |
|
|
280
|
+
| Format | Structured rows with `summary` + `keywords` for indexed retrieval |
|
|
281
|
+
| Write triggers | `Agent.startActivity()` / `Agent.endActivity()` — every agent action |
|
|
282
|
+
| Prompt injection | NOT automatic — retrieved on demand via `recall_activity` tool |
|
|
283
|
+
| Lifetime | Persistent; never deleted. Grows continuously. |
|
|
284
|
+
|
|
285
|
+
**Activity types**: `task`, `chat`, `heartbeat`, `a2a`, `internal`, `respond_in_session`
|
|
286
|
+
|
|
287
|
+
**Data model**:
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
agent_activities (one per action session)
|
|
291
|
+
├── id — act-{agentId}-{timestamp}-{rand}
|
|
292
|
+
├── agent_id — owner
|
|
293
|
+
├── type — task | chat | heartbeat | a2a | internal | respond_in_session
|
|
294
|
+
├── label — human-readable description
|
|
295
|
+
├── task_id — for task-type activities
|
|
296
|
+
├── summary — 1-3 sentence summary (computed at endActivity)
|
|
297
|
+
├── keywords — comma-separated (tool names, error types, file paths)
|
|
298
|
+
├── started_at / ended_at
|
|
299
|
+
├── total_tokens / total_tools
|
|
300
|
+
└── success — outcome
|
|
301
|
+
|
|
302
|
+
agent_activity_logs (N per activity, ordered)
|
|
303
|
+
├── activity_id — parent
|
|
304
|
+
├── seq — ordered sequence number
|
|
305
|
+
├── type — status | text | tool_start | tool_end | error | llm_request
|
|
306
|
+
├── content — event description
|
|
307
|
+
└── metadata — JSON (tokensUsed, durationMs, etc.)
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Write path**:
|
|
311
|
+
|
|
312
|
+
```
|
|
313
|
+
Agent.startActivity(type, label)
|
|
314
|
+
→ onActivityStartCb → SqliteActivityRepo.insertActivity()
|
|
315
|
+
|
|
316
|
+
Agent.emitActivityLog(activityId, type, content)
|
|
317
|
+
→ onActivityLogCb → SqliteActivityRepo.insertActivityLog()
|
|
318
|
+
|
|
319
|
+
Agent.endActivity(activityId, {summary, keywords})
|
|
320
|
+
→ onActivityEndCb → SqliteActivityRepo.updateActivity()
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**Retrieval** — the `recall_activity` tool gives agents access to their own history:
|
|
324
|
+
|
|
325
|
+
| Operation | What it does |
|
|
326
|
+
|-----------|-------------|
|
|
327
|
+
| `list` | Recent activities, filterable by type/taskId |
|
|
328
|
+
| `search` | Keyword search across summary + keywords + label |
|
|
329
|
+
| `get` | Detailed event logs for a specific activity |
|
|
330
|
+
|
|
331
|
+
This is how an agent answers "what did I do last time with X?" — it searches its own episodic memory.
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## 6. Procedural Memory
|
|
336
|
+
|
|
337
|
+
How the agent operates — managed outside `MemoryStore` by the role/skill system.
|
|
338
|
+
|
|
339
|
+
| Component | Storage | Loader |
|
|
340
|
+
|-----------|---------|--------|
|
|
341
|
+
| ROLE.md | `~/.markus/agents/{id}/role/ROLE.md` | `RoleLoader` / `EnhancedRoleLoader` (`enhanced-role-loader.ts`) |
|
|
342
|
+
| HEARTBEAT.md | `~/.markus/agents/{id}/role/HEARTBEAT.md` | Loaded by heartbeat processor |
|
|
343
|
+
| Skills | Installed via `discover_tools` | Skill registry + MCP |
|
|
344
|
+
|
|
345
|
+
ROLE.md is loaded at startup and hot-reloaded when the agent modifies it via `file_edit`. Changes require proven experience — platform **Learning Habits** ([learning-loop.md](./learning-loop.md) §8) govern when and how agents modify identity, memory, HEARTBEAT, or skills (including user-initiated Remember sessions in §9).
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## 7. Storage Layout
|
|
350
|
+
|
|
351
|
+
### File System (per agent)
|
|
352
|
+
|
|
353
|
+
```
|
|
354
|
+
~/.markus/agents/{agent-id}/
|
|
355
|
+
├── NOTEBOOK.md # Notebook: persistent cognitive workspace
|
|
356
|
+
├── knowledge.md # Semantic SSOT: curated knowledge + ## _observations
|
|
357
|
+
├── (state.md removed — situational state → NOTEBOOK.md `system` tier)
|
|
358
|
+
├── MEMORY.md # DEPRECATED legacy (migrate once; do not write)
|
|
359
|
+
├── metrics.json # Health counters (not memory)
|
|
360
|
+
├── role/
|
|
361
|
+
│ ├── ROLE.md # Procedural: identity
|
|
362
|
+
│ └── HEARTBEAT.md # Periodic self-check checklist
|
|
363
|
+
├── sessions/
|
|
364
|
+
│ └── sess_{ts}_{rand}.json # Episodic: current conversation
|
|
365
|
+
├── daily-logs/
|
|
366
|
+
│ └── YYYY-MM-DD.md # Audit trail (NOT memory — never read back)
|
|
367
|
+
├── workspace/ # Working files (not memory)
|
|
368
|
+
└── tool-outputs/ # Tool result offloads (not memory)
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
> **Note**: `memories.json` and `MEMORY.md` are deprecated. They auto-migrate into
|
|
372
|
+
> `MEMORY.md` on first load; subsequent tool writes target `knowledge.md` only. `state.md` **retired 2026-09-16** (situational state → notebook `system` tier).
|
|
373
|
+
|
|
374
|
+
### SQLite (`~/.markus/data.db`)
|
|
375
|
+
|
|
376
|
+
| Table | Memory Layer | Purpose |
|
|
377
|
+
|-------|-------------|---------|
|
|
378
|
+
| `agent_activities` | **Episodic** | Past episodes — searchable via `recall_activity` |
|
|
379
|
+
| `agent_activity_logs` | **Episodic** | Event-level detail within episodes |
|
|
380
|
+
| `chat_sessions` + `chat_messages` | *(UI persistence)* | Web UI chat history; synced to file sessions on restore |
|
|
381
|
+
| `mailbox_items` + `agent_decisions` | **Episodic** | Stimulus/response record (what the agent received and decided) |
|
|
382
|
+
|
|
383
|
+
**The test**: if the agent can retrieve it to inform future decisions, it's memory. If only humans read it, it's audit trail.
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## 8. Consolidation (Dream Cycle)
|
|
388
|
+
|
|
389
|
+
Periodic process that maintains semantic memory health. Runs via `consolidateMemory()`. All consolidation happens within `knowledge.md`. Notebook per-tier TTL pruning runs on every notebook write (the separate `state.md` TTL prune was removed with that store).
|
|
390
|
+
|
|
391
|
+
### Trigger
|
|
392
|
+
|
|
393
|
+
- `## _observations` has 50+ entries
|
|
394
|
+
- Dream cycle has not run today (`lastDreamDate`); up to 4×/day when heavily bloated (500+ entries)
|
|
395
|
+
|
|
396
|
+
### Process (LLM-assisted)
|
|
397
|
+
|
|
398
|
+
1. Cap entries at 500, send to LLM with: id, type, date, tags, content preview
|
|
399
|
+
2. LLM responds with JSON: `{ remove: [...ids], merge: [...groups], promote: [...] }`
|
|
400
|
+
3. Apply removals: delete from `## _observations` + vector index
|
|
401
|
+
4. Apply merges: replace groups with merged entry in `_observations`
|
|
402
|
+
5. Apply promotions: append synthesized content to curated sections above `_observations`
|
|
403
|
+
|
|
404
|
+
### knowledge.md Hygiene (write-entry only)
|
|
405
|
+
|
|
406
|
+
There is **no** load-time hygiene pass over the file. The platform does not rewrite, prune or
|
|
407
|
+
dedupe the agent's curated prose — that was `pruneMemoryMd()` (**removed**; it did title/size
|
|
408
|
+
heuristic surgery on the agent's own sections). See
|
|
409
|
+
[platform-hardening-2026-10.md](../records/platform-hardening-2026-10.md) §24.
|
|
410
|
+
|
|
411
|
+
What remains is **single-point cleaning at the write entry**: `sanitizeSectionBody()` strips
|
|
412
|
+
leaked `<think>` blocks (closed and unclosed) and demotes a sibling `## ` inside a body to
|
|
413
|
+
`### `, so the injected region can never grow a section the agent did not author. The
|
|
414
|
+
per-section and curated ceilings are enforced there too (see §8.8). Empty entries left by legacy
|
|
415
|
+
writes are dropped when the observation pool is read.
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## 8.7 Memory Flush (spec)
|
|
420
|
+
|
|
421
|
+
Before the working context fills up, the agent is prompted to persist anything important so
|
|
422
|
+
lossy compaction never silently discards decisions or learned facts. The prompt-side
|
|
423
|
+
mechanics live in [prompt-engineering.md §5.7](./prompt-engineering.md); this is the
|
|
424
|
+
authoritative behavior spec.
|
|
425
|
+
|
|
426
|
+
- **Behavior**: a **turn-level preflight** runs `memoryFlush` once per session when the
|
|
427
|
+
previous turn's context usage crossed a high-water threshold (~75%). The flush asks the
|
|
428
|
+
agent to `memory_save` key decisions/facts and `notebook_upsert` current state. It runs
|
|
429
|
+
as an independent `sys_` session.
|
|
430
|
+
- **Invariants**:
|
|
431
|
+
- Flush fires **at most once per session** (deduplicated), and **before** the compression
|
|
432
|
+
that would drop older turns.
|
|
433
|
+
- The flush session is independent, so a flush cannot recurse into another flush or into
|
|
434
|
+
storage compaction (no `flush → compact → flush` loop).
|
|
435
|
+
- Low-usage turns never trigger a flush.
|
|
436
|
+
- **Design rationale (Hermes)**: Hermes's compression flushes durable memory to disk *first*;
|
|
437
|
+
Markus adopts the same "flush before you lose it" ordering, implemented as a preflight so it
|
|
438
|
+
does not reenter the packing path.
|
|
439
|
+
- **Testing** (`packages/core/test/memory-flush-preflight.test.ts`): the pure decision
|
|
440
|
+
`shouldMemoryFlushPreflight` fires at/above threshold, not below, not twice per session,
|
|
441
|
+
never for `sys_` sessions, and not without prior usage. Wiring lives in
|
|
442
|
+
`Agent.maybeMemoryFlushPreflight` / `recordContextUsage`, invoked before the chat, stream,
|
|
443
|
+
and task `prepareMessages` calls.
|
|
444
|
+
- **Status**: implemented (`shouldMemoryFlushPreflight` + `maybeMemoryFlushPreflight`, wired
|
|
445
|
+
into all three main turn paths; `memoryFlush` runs in an independent `sys_` session).
|
|
446
|
+
|
|
447
|
+
## 8.8 knowledge.md write-refusal visibility (spec)
|
|
448
|
+
|
|
449
|
+
`knowledge.md` enforces a per-section cap (`MEMORY_MD_SECTION_MAX_CHARS = 3000`) plus two
|
|
450
|
+
curated-region thresholds: a **soft** budget (`MEMORY_MD_CURATED_MAX_CHARS = 15000` — the
|
|
451
|
+
injected part, NOT the whole file) that is **report-only** (log + in-prompt banner), and a
|
|
452
|
+
**hard ceiling** (`MEMORY_MD_CURATED_HARD_MAX_CHARS = 45000`, 3× the soft budget) at which the
|
|
453
|
+
write is **refused** fail-closed — nothing written, with an actionable reason. The
|
|
454
|
+
`## _observations` buffer is **not** injected and has its own advisory line
|
|
455
|
+
(`MEMORY_OBSERVATIONS_MAX_CHARS = 30000`, report-only) and hard ceiling
|
|
456
|
+
(`MEMORY_OBSERVATIONS_HARD_MAX_CHARS = 200000`), where the append path refuses.
|
|
457
|
+
|
|
458
|
+
- **Behavior**: a refused write returns a structured failure (`{ ok:false, reason }`,
|
|
459
|
+
recognized by `isToolErrorResult`) and is surfaced to the activity log / stream (see
|
|
460
|
+
[streaming-and-reattach.md](./streaming-and-reattach.md) §4.1) — never a silent no-op the
|
|
461
|
+
model mistakes for success.
|
|
462
|
+
- **Testing** (`packages/core/test/memory-store.test.ts` "B1:", `memory-tools-extended.test.ts`):
|
|
463
|
+
an over-cap write returns `{ ok:false, reason }`; the memory tools propagate it as a
|
|
464
|
+
structured `{ status:'error', ok:false }` result the caller/UI can observe.
|
|
465
|
+
- **Status**: implemented (`MemoryStore.addLongTermMemory` returns `{ ok, reason }`;
|
|
466
|
+
`memory_update` / `memory_update_longterm` return a structured error on refusal).
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
|
|
470
|
+
## 9. Key Rules
|
|
471
|
+
|
|
472
|
+
1. **`knowledge.md` curated sections are sacred** — only distilled knowledge. Never raw LLM output or debug info. Do not teach agents to write `MEMORY.md`.
|
|
473
|
+
2. **`## _observations` is the observation buffer** — not injected into prompts; vector index is a secondary search overlay.
|
|
474
|
+
3. **NOTEBOOK.md is always in prompt** — keep entries concise; use `memory_save` for durable observations.
|
|
475
|
+
4. **Activity history is episodic memory** — retrieved via `recall_activity` to inform future decisions.
|
|
476
|
+
5. **Sessions are thin** — hold current conversation only, auto-compacted.
|
|
477
|
+
6. **Daily logs are NOT memory** — append-only audit trail for humans. Never read back into prompts.
|
|
478
|
+
7. **Dream Cycle is conservative** — err on keeping entries; incorrect removal is worse than duplicates.
|
|
479
|
+
8. **One MemoryStore per agent** — file-system based, no cross-agent contamination.
|
|
480
|
+
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
## 10. Layering criterion, consolidation record, known limits
|
|
484
|
+
|
|
485
|
+
### 10.1 The single criterion: `(scope × durability)`
|
|
486
|
+
|
|
487
|
+
Every state a running agent carries is placed by asking two questions only — *who can see it*
|
|
488
|
+
(scope) and *how long it must survive* (durability). Anything that cannot be placed is a smell.
|
|
489
|
+
|
|
490
|
+
| Layer | Scope | Durability | Carrier | Write path | Injected as |
|
|
491
|
+
|---|---|---|---|---|---|
|
|
492
|
+
| **Identity** | agent-lifetime | permanent (human-owned) | `role/ROLE.md`, `role/HEARTBEAT.md`, skills | human edit / explicit file write | fixed segment (system) |
|
|
493
|
+
| **Knowledge** | agent-lifetime | long, forgettable | `knowledge.md` (curated sections + `## _observations`) | `memory_save`, `memory_update` (incl. `mode="forget"`) | volatile tail, budget-capped |
|
|
494
|
+
| **Working** | agent-lifetime | short, auto-expiring | `NOTEBOOK.md` (per-tier TTL: agent 96h / system 24h) | `notebook_upsert` | volatile tail (`## Notebook`) |
|
|
495
|
+
| **Session** | one session/worker | session-scoped | slots / `summary` / fragments | `session` tool family | fixed segment + history |
|
|
496
|
+
|
|
497
|
+
### 10.2 Consolidation record — what was merged away
|
|
498
|
+
|
|
499
|
+
Before this criterion was applied, 13 state-like mechanisms competed for the same jobs. The
|
|
500
|
+
merges below are the reason the count is now small; **do not re-introduce the retired halves**.
|
|
501
|
+
|
|
502
|
+
| Removed | Why it existed | Folded into | Date |
|
|
503
|
+
|---|---|---|---|
|
|
504
|
+
| `state.md` (store) | "short-lived situational state" half of a knowledge/state dual store — it had a reader (reflex prompt) and a TTL pruner (dream) but **no write tool at all**, so every writer actually went to the notebook | `NOTEBOOK.md` `system` tier; existing files migrate once to notebook key `legacy-state` with a tombstone left behind | 2026-09-16 (option A) |
|
|
505
|
+
| `working-memory` (lock domain) | the notebook's older name; kept as a second *domain* after the tool alias was added | `agent-memory:notebook` — one resource, one lock key (see [concurrent-processing.md](./concurrent-processing.md) §4.3) | 2026-09-16 |
|
|
506
|
+
| knowledge/state **split** on migration | `splitLegacyMemory` guessed which `MEMORY.md` sections were "state" by keywords | whole-file migration into `knowledge.md` (keyword guessing was itself an incident source) | 2026-09-16 |
|
|
507
|
+
| `getStateMemory` / `pruneStateMemory` / `STATE_TTL_DAYS` / `STATE_PROMPT_MAX_LINES_REFLEX` | supported the retired `state.md` | notebook per-tier TTL (`NOTEBOOK_TTL_MS_*`); constants deleted with in-place NOTE comments | 2026-09-16 |
|
|
508
|
+
|
|
509
|
+
Principles this produced:
|
|
510
|
+
- **A store with no writer is dead weight** — `state.md` was documented, initialized, read and
|
|
511
|
+
pruned, yet unwritable. Documentation and tooling drifted apart; the tool surface is the truth.
|
|
512
|
+
- **A store with no delete inflates** — the curated half had no removal path, so superseded
|
|
513
|
+
knowledge could only be overwritten. `mode="forget"` closes this (§1.1).
|
|
514
|
+
- **One resource must have one lock key** — see [concurrent-processing.md](./concurrent-processing.md) §4.3.
|
|
515
|
+
|
|
516
|
+
### 10.3 Known limits / deliberate non-goals
|
|
517
|
+
|
|
518
|
+
| Limit | Why it is accepted for now |
|
|
519
|
+
|---|---|
|
|
520
|
+
| Curated knowledge does **not** decay by age | distinguishing "durable principle" from "temporary conclusion" is a semantic judgement only an LLM can make → belongs in the dream-cycle curation prompt, not the storage layer. Bounded instead by the curated soft budget (report-only at load) and the write-path hard ceiling `MEMORY_MD_CURATED_HARD_MAX_CHARS`; the load-time total cap was **removed** (see §8.8). |
|
|
521
|
+
| No write queue for memory writes | lock-key unification + atomic writes removed the main interleaving surface; a queue would add a serialisation bottleneck without evidence of remaining contention. |
|
|
522
|
+
| `relevant-context` may repeat what `## Your Knowledge` already says | deliberate: deduplicating raises "which copy is authoritative?" ambiguity. |
|
|
523
|
+
| Frontend renders the notebook; there is no jsdom-level render test | helper-level unit tests only (`packages/web-ui/src/lib/notebookDisplay.test.ts`); render-level harness is a separate piece of work. |
|
|
524
|
+
|
|
525
|
+
## 11. Cross-Reference
|
|
526
|
+
|
|
527
|
+
| Document | Relationship |
|
|
528
|
+
|----------|-------------|
|
|
529
|
+
| [cognitive-architecture.md](./cognitive-architecture.md) | How agents use memory for context preparation |
|
|
530
|
+
| [prompt-engineering.md](./prompt-engineering.md) | How memory is assembled into system prompts |
|
|
531
|
+
| [architecture.md](./architecture.md) | Overall system architecture |
|
|
532
|
+
| [mailbox-system.md](./mailbox-system.md) | Mailbox stimulus/response feeds into episodic memory |
|
|
533
|
+
| [streaming-and-reattach.md](./streaming-and-reattach.md) | Surfaces memory-write refusals as visible events |
|