Skip to content

Commit 28630a9

Browse files
authored
feat(memory): provenance-gated memory with dreaming on by default (#114819)
* feat(memory): add provenance and recall metadata to the memory index * feat(memory): provenance-gated promotion and capture hygiene * feat(dreaming): LLM consolidation with deterministic gates, on by default * feat(active-memory): deterministic recall lane with escalation default * feat(memory): user model file and standing intents * docs(memory): document the memory architecture * fix(memory): live-QA fixes — metadata writers, provenance classes, intent scope, claim accumulation
1 parent 4c2d06b commit 28630a9

137 files changed

Lines changed: 9630 additions & 857 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cbf4e2c3088f8886a7c9ea91325a66e0f0846cea21f0b2891f36399b4811306c module/account
44
8e985f345f21a1c9a2b0e94304aaaad6a326bec1c1ce3b26027d2862804a366e module/account-resolution
55
e5e67ddf3cab38fcbf9220bc3160715897e2709d9a9ff6ff36f1ecc9453c2367 module/agent-config-primitives
66
74daa746deb548379d3f0d6eac3c4d082df1034c4360cc03bf51fee0f10a2e4d module/agent-harness
7-
5de3d5c7eb5b863c12453666725cfe6473d884a1788ad905fbddda64983ef100 module/agent-harness-runtime
7+
ccfc54a6dc389b38bb06c2dbff05b30f35ff4efd953887cac8066e1aae7db45d module/agent-harness-runtime
88
5168648cd946abad8a92822889f13ceacc87ed502314a66190d0b1eb8ebe76ea module/agent-media-payload
99
2dcb4d62d90e5d71594f6b843c97534509a154784e378fb1c75bd86b5122b710 module/agent-runtime
1010
56b6d5fb6af3d95af1200065aca2e7d4f59e5fa59740505fe6ff433077ef6646 module/allow-from

‎docs/concepts/active-memory.md‎

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
---
2-
summary: "A plugin-owned blocking memory sub-agent that injects relevant memory into interactive chat sessions"
2+
summary: "Deep conversation-history recall that escalates only when deterministic memory recall is insufficient"
33
title: "Active memory"
44
read_when:
55
- You want to understand what active memory is for
66
- You want to turn active memory on for a conversational agent
77
- You want to tune active memory behavior without enabling it everywhere
88
---
99

10-
Active memory is an optional bundled plugin that runs a blocking memory
11-
recall sub-agent before the main reply, for eligible conversational sessions.
12-
It exists because most memory systems are reactive: the main agent has to
13-
decide to search memory, or the user has to say "remember this." By then the
14-
moment for the recalled fact to feel natural has passed. Active memory gives
15-
the system one bounded chance to surface relevant memory before the main
16-
reply is generated.
10+
Active Memory is the deep-recall lane for eligible conversational sessions.
11+
The default `escalate` mode runs its blocking recall sub-agent only when the
12+
message asks about the past and the deterministic memory lane found no strong
13+
trusted trigger match. This keeps ordinary replies fast while preserving a
14+
deeper search path for prior decisions, conversations, and temporal or
15+
multi-hop questions.
16+
17+
Flat retrieval is strongest for direct fact matches and weaker on temporal and
18+
multi-session questions. [LongMemEval (arXiv:2410.10813)](https://arxiv.org/abs/2410.10813)
19+
measures that gap, while the PrefEval benchmark highlights the value of
20+
preference-adjacent reminders. Escalation by default spends the blocking model
21+
call where those harder recall shapes are actually present.
1722

1823
## Remember across conversations
1924

@@ -76,6 +81,7 @@ Paste into `openclaw.json` for an advanced safe default: plugin on, scoped to
7681
enabled: true,
7782
config: {
7883
enabled: true,
84+
mode: "escalate",
7985
agents: ["main"],
8086
allowedChatTypes: ["direct"],
8187
modelFallback: "google/gemini-3-flash",
@@ -111,6 +117,7 @@ To inspect it live in a conversation:
111117
What the key fields do:
112118

113119
- `plugins.entries.active-memory.enabled: true` turns the plugin on
120+
- `config.mode: "escalate"` runs deep recall only for recall intent without a strong deterministic hit
114121
- `config.agents: ["main"]` opts only the `main` agent in
115122
- `config.allowedChatTypes: ["direct"]` scopes it to direct-message sessions (opt in groups/channels explicitly)
116123
- `config.model` (optional) pins a dedicated recall model; unset inherits the current session model
@@ -123,14 +130,17 @@ What the key fields do:
123130

124131
```mermaid
125132
flowchart LR
126-
U["User Message"] --> Q["Build Memory Query"]
127-
Q --> R["Active Memory Blocking Memory Sub-Agent"]
128-
R -->|NONE / no relevant memory| M["Main Reply"]
129-
R -->|relevant summary| I["Append Hidden active_memory_plugin System Context"]
130-
I --> M["Main Reply"]
133+
U["User Message"] --> D["Deterministic Trigger Recall"]
134+
D -->|strong trusted match| I["Inject Bounded Hidden Context"]
135+
D -->|weak or empty| H["Check Recall Intent"]
136+
H -->|no| M["Main Reply"]
137+
H -->|yes| R["Active Memory Deep Recall Sub-Agent"]
138+
R -->|NONE| M
139+
R -->|relevant summary| I
140+
I --> M
131141
```
132142

133-
The blocking sub-agent can call only the configured memory recall tools (see
143+
The deep-recall sub-agent can call only the configured memory recall tools (see
134144
[Memory tools](#memory-tools)). If the connection between the query and
135145
available memory is weak, it returns `NONE` and the main reply proceeds
136146
without extra context.
@@ -156,7 +166,7 @@ personalization would be surprising.
156166

157167
## When it runs
158168

159-
Active Memory has two activation paths:
169+
Active Memory has two targeting paths for the deep-recall lane:
160170

161171
1. **Remember across conversations** automatically targets agents whose
162172
effective `memory.search.rememberAcrossConversations` setting is enabled, but
@@ -170,6 +180,18 @@ persistent conversation. A session-scoped `/active-memory off` pauses both
170180
paths for that conversation. If any condition fails, active memory does not run
171181
for that turn, and the main reply is unaffected.
172182

183+
`config.mode` controls when a targeted turn starts the blocking sub-agent:
184+
185+
| Mode | Behavior |
186+
| ---------- | ----------------------------------------------------------------------- |
187+
| `escalate` | Default. Run only for recall intent when lane 1 has no strong hit. |
188+
| `always` | Preserve the previous behavior and run on every eligible targeted turn. |
189+
| `off` | Disable deep recall without unloading the plugin. |
190+
191+
The deterministic trusted-trigger lane remains available in `off` mode.
192+
`rememberAcrossConversations` is unchanged: it still controls whether deep
193+
recall may search other private conversations.
194+
173195
### Session types
174196

175197
`config.allowedChatTypes` controls which kinds of conversations may run the
@@ -620,6 +642,7 @@ All active memory configuration lives under `plugins.entries.active-memory`.
620642
| Key | Type | Meaning |
621643
| ---------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
622644
| `enabled` | `boolean` | Enables the plugin itself |
645+
| `config.mode` | `"escalate" \| "always" \| "off"` | Controls when the blocking deep-recall sub-agent runs; default `"escalate"` |
623646
| `config.agents` | `string[]` | Agent ids that may use active memory |
624647
| `config.model` | `string` | Optional blocking sub-agent model ref; when unset, inherits the current session model |
625648
| `config.allowedChatTypes` | `("direct" \| "group" \| "channel" \| "explicit")[]` | Session types that may run active memory; defaults to `["direct"]` |
@@ -665,6 +688,7 @@ Start with `recent`:
665688
enabled: true,
666689
config: {
667690
agents: ["main"],
691+
mode: "escalate",
668692
queryMode: "recent",
669693
promptStyle: "balanced",
670694
timeoutMs: 15000,
@@ -679,8 +703,9 @@ Start with `recent`:
679703

680704
Use `/verbose on` for the status line and `/trace on` for the debug summary
681705
while tuning — both are sent as a follow-up after the main reply, not
682-
before. Then move to `message` for lower latency, or `full` if extra context
683-
is worth the slower sub-agent run.
706+
before. Use `always` only when every eligible turn warrants the latency. Keep
707+
`escalate` for the recommended balance, then choose `message`, `recent`, or
708+
`full` for the deep-recall query itself.
684709

685710
### Cold-start grace
686711

‎docs/concepts/agent-workspace.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Standard files OpenClaw expects inside the workspace:
7070
<Accordion title="SOUL.md - persona and tone">
7171
Persona, tone, and boundaries. Loaded every session. Guide: [SOUL.md personality guide](/concepts/soul).
7272
</Accordion>
73-
<Accordion title="USER.md - who the user is">
74-
Who the user is and how to address them. Loaded every session.
73+
<Accordion title="USER.md - directive-based user model (optional)">
74+
Stable preferences, communication style, relationships, and active-project context. Write entries as dated active or superseded directives. Loaded every session with a separate 4,000-character budget. See [User model](/concepts/user-model).
7575
</Accordion>
7676
<Accordion title="IDENTITY.md - name, vibe, emoji">
7777
The agent's name, vibe, and emoji. Created/updated during the bootstrap ritual.
@@ -89,7 +89,7 @@ Standard files OpenClaw expects inside the workspace:
8989
Daily memory log (one file per day). Recommended to read today + yesterday on session start.
9090
</Accordion>
9191
<Accordion title="MEMORY.md - curated long-term memory (optional)">
92-
Curated long-term memory: durable facts, preferences, decisions, and short summaries. Keep detailed logs in `memory/YYYY-MM-DD.md` so memory tools can retrieve them on demand without injecting them into every prompt. Only load `MEMORY.md` in the main, private session (not shared/group contexts). See [Memory](/concepts/memory) for the workflow and automatic memory flush.
92+
Curated long-term memory: durable non-profile facts, decisions, and short summaries. Keep detailed logs in `memory/YYYY-MM-DD.md` so memory tools can retrieve them on demand without injecting them into every prompt. Only load `MEMORY.md` in the main, private session (not shared/group contexts). See [Memory](/concepts/memory) for the workflow and automatic memory flush.
9393
</Accordion>
9494
<Accordion title="skills/ - workspace skills (optional)">
9595
Workspace-specific skills. Highest-precedence skill location for that workspace, ahead of project agent skills, personal agent skills, managed skills, bundled skills, and `skills.load.extraDirs` when names collide.
@@ -100,7 +100,7 @@ Standard files OpenClaw expects inside the workspace:
100100
</AccordionGroup>
101101

102102
<Note>
103-
If a bootstrap file is missing, OpenClaw injects a "missing file" marker into the session and continues. Large bootstrap files are truncated when injected; adjust limits with `agents.defaults.bootstrapMaxChars` (default: `20000`) and `agents.defaults.bootstrapTotalMaxChars` (default: `60000`). `openclaw setup` can recreate missing defaults without overwriting existing files.
103+
If a required bootstrap file is missing, OpenClaw injects a "missing file" marker into the session and continues. Optional `USER.md` and `MEMORY.md` files are omitted when absent. Large bootstrap files are truncated when injected; adjust general limits with `agents.defaults.bootstrapMaxChars` (default: `20000`) and `agents.defaults.bootstrapTotalMaxChars` (default: `60000`). `USER.md` keeps its separate 4,000-character cap. `openclaw setup` can recreate missing defaults without overwriting existing files.
104104
</Note>
105105

106106
## What is NOT in the workspace
@@ -109,7 +109,7 @@ These live under `~/.openclaw/` and should NOT be committed to the workspace rep
109109

110110
- `~/.openclaw/openclaw.json` (config)
111111
- `~/.openclaw/state/openclaw.sqlite` (shared workspace setup state and attestations)
112-
- `~/.openclaw/agents/<agentId>/agent/openclaw-agent.sqlite` (model auth profiles, routing state, and other agent-scoped durability)
112+
- `~/.openclaw/agents/<agentId>/agent/openclaw-agent.sqlite` (model auth profiles, routing state, standing intents, and other agent-scoped durability)
113113
- `~/.openclaw/agents/<agentId>/agent/openclaw-agent.sqlite` (session rows, transcripts, and per-agent runtime state)
114114
- `~/.openclaw/agents/<agentId>/agent/codex-home/` (per-agent Codex runtime account, config, skills, plugins, and native thread state)
115115
- `~/.openclaw/credentials/` (channel/provider state plus legacy OAuth import data)

‎docs/concepts/dreaming.md‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ read_when:
1111
Dreaming is the background memory consolidation system in `memory-core`. It moves strong short-term signals into durable memory while keeping the process explainable and reviewable.
1212

1313
<Note>
14-
Dreaming is **opt-in** and disabled by default.
14+
Dreaming is enabled by default. Set
15+
`plugins.entries.memory-core.config.dreaming.enabled: false` to disable it.
1516
</Note>
1617

1718
## What dreaming writes
1819

1920
- **Machine state** in `memory/.dreams/` (recall store, phase signals, ingestion checkpoints, locks).
21+
- **Rewrite preimages** in SQLite-backed plugin state before an accepted `MEMORY.md` rewrite.
2022
- **Human-readable output** in `DREAMS.md` (or an existing `dreams.md`) and optional phase report files under `memory/dreaming/<phase>/YYYY-MM-DD.md`.
2123

2224
Long-term promotion still writes only to `MEMORY.md`.
25+
Each newly promoted entry carries trailing recall metadata derived from the
26+
candidate: up to three concept tags in `<!-- trigger: phrase one, phrase two -->`
27+
and a bounded `<!-- importance: N -->` value from 1 to 10. Consolidation keeps
28+
existing annotated entries byte-for-byte unless it explicitly merges or
29+
supersedes them.
2330

2431
## Phase model
2532

@@ -50,15 +57,44 @@ Dreaming runs three cooperative phases per sweep, in order: light -> REM -> deep
5057
<Accordion title="Deep phase">
5158
- Ranks candidates with weighted scoring and threshold gates (`minScore`, `minRecallCount`, `minUniqueQueries` must all pass).
5259
- Rehydrates snippets from live daily files before writing, so stale/deleted snippets are skipped.
53-
- Appends promoted entries to `MEMORY.md`.
60+
- Passes gated owner and agent-derived candidates to a consolidation subagent with the current `MEMORY.md`.
61+
- Rewrites `MEMORY.md` only when the result preserves enough prior entries, includes candidate source references, and fits the bootstrap budget.
62+
- Falls back to the previous append-only promotion path when the model is unavailable or the rewrite fails validation.
5463
- Writes a `## Deep Sleep` summary into `DREAMS.md` and optionally `memory/dreaming/deep/YYYY-MM-DD.md`.
5564

5665
</Accordion>
5766
</AccordionGroup>
5867

5968
## Session transcript ingestion
6069

61-
Dreaming can ingest redacted session transcripts into the dreaming corpus. When available, transcripts feed the light phase alongside daily memory signals and recall traces. Personal and sensitive content is redacted before ingestion.
70+
Dreaming can ingest redacted session transcripts into the dreaming corpus. Only interactive sessions are eligible. Cron, heartbeat, subagent, and unknown sessions stay out of durable candidate ingestion. Personal and sensitive content is redacted before ingestion, and runtime-marked recalled context is removed so recalled snippets cannot be learned again as new memory.
71+
72+
## Consolidation safety
73+
74+
The deterministic score, recall-count, and query-diversity thresholds remain
75+
the candidate gate. Consolidation runs only after those gates pass.
76+
77+
Before building the consolidation prompt, `memory-core` removes candidates
78+
whose indexed provenance is `untrusted` or `system`. This is a structural
79+
taint gate, not a score penalty. Eligible candidates include their origin,
80+
session kind, observation time, optional supersession key, and daily-note
81+
source reference.
82+
83+
An accepted rewrite must:
84+
85+
- preserve prior entries within `phases.deep.maxPriorEntryLossFraction`
86+
- include every promoted candidate's `Source: path#Lx-Ly` reference
87+
- stay within the `MEMORY.md` bootstrap-safe file budget
88+
- parse as the expected structured response
89+
90+
Before the file changes, the previous `MEMORY.md` is stored in SQLite-backed
91+
plugin state. `DREAMS.md` receives added, merged, and superseded counts plus
92+
short diff-style highlights. This makes each rewrite reviewable without
93+
turning the Dream Diary into a promotion source.
94+
95+
Background consolidation is informed by sleep-time compute
96+
(arXiv:2504.13171). The provenance and reflection boundary follows the durable
97+
memory framing in the Generative Agents research.
6298

6399
## Dream Diary
64100

@@ -196,9 +232,12 @@ When enabled, `memory-core` auto-manages one cron job for a full dreaming sweep,
196232

197233
All settings live under `plugins.entries.memory-core.config.dreaming`.
198234

199-
<ParamField path="enabled" type="boolean" default="false">
235+
<ParamField path="enabled" type="boolean" default="true">
200236
Enable or disable the dreaming sweep.
201237
</ParamField>
238+
<ParamField path="phases.deep.maxPriorEntryLossFraction" type="number" default="0.25">
239+
Reject a consolidation rewrite when it removes more than this fraction of prior entries.
240+
</ParamField>
202241
<ParamField path="frequency" type="string" default="0 3 * * *">
203242
Cron cadence for the full dreaming sweep.
204243
</ParamField>

0 commit comments

Comments
 (0)