Skip to content

Commit 98b8c8c

Browse files
feat(memory-wiki): isolate vaults per agent (#103349)
* feat(memory-wiki): isolate per-agent vaults Refs #63829. Co-authored-by: SunnyShu <[email protected]> * fix(memory-wiki): scope agent status metadata Refs #103088 and #103196. Co-authored-by: SunnyShu <[email protected]> --------- Co-authored-by: SunnyShu <[email protected]>
1 parent 6fd9c1d commit 98b8c8c

48 files changed

Lines changed: 2699 additions & 228 deletions

Some content is hidden

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

‎docs/cli/wiki.md‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,33 @@ openclaw wiki obsidian command workspace:quick-switcher
4747
openclaw wiki obsidian daily
4848
```
4949

50+
## Agent selection
51+
52+
When `plugins.entries.memory-wiki.config.vault.scope` is `agent`, select the
53+
vault with the top-level `--agent <id>` option:
54+
55+
```bash
56+
openclaw wiki --agent support status
57+
openclaw wiki --agent support search "refund policy"
58+
openclaw wiki --agent marketing ingest ./campaign-notes.md
59+
```
60+
61+
In a setup with multiple configured agents, `--agent` is required for CLI
62+
operations so a command cannot read or write an arbitrary default vault. If
63+
only one agent is configured, that agent remains the default. Unknown agent ids
64+
fail before the vault operation starts. The option does not change the selected
65+
path when `vault.scope` is `global`.
66+
67+
Gateway clients follow the same rule: pass `agentId` on vault-backed `wiki.*`
68+
requests in an agent-scoped multi-agent setup. A missing or unknown id is an
69+
error. Agent turns, wiki tools, memory corpus supplements, and compiled prompt
70+
digests already carry the active runtime agent context.
71+
5072
## Commands
5173

5274
### `wiki status`
5375

54-
Show vault mode, health, and Obsidian CLI availability. Use this first to check whether the vault is initialized, bridge mode is healthy, or Obsidian integration is available.
76+
Show vault mode and scope, resolved agent, health, and Obsidian CLI availability. Use this first to check whether the intended vault is initialized, bridge mode is healthy, or Obsidian integration is available.
5577

5678
When bridge mode is active and configured to read memory artifacts, this command queries the running Gateway so it sees the same active memory plugin context as agent/runtime memory.
5779

@@ -198,6 +220,11 @@ Roll back a previously applied ChatGPT import run, removing pages it created and
198220

199221
Obsidian helper commands for vaults running in Obsidian-friendly mode: `status`, `search`, `open`, `command`, `daily`. These require the official `obsidian` CLI on `PATH` when `obsidian.useOfficialCli` is enabled.
200222

223+
Configuration validation rejects `obsidian.useOfficialCli: true` when
224+
`vault.scope` is `agent` because `obsidian.vaultName` is one global setting,
225+
not a per-agent mapping. Obsidian-friendly Markdown rendering remains
226+
available.
227+
201228
## Practical usage guidance
202229

203230
- Use `wiki search` + `wiki get` when provenance and page identity matter.
@@ -212,6 +239,8 @@ Obsidian helper commands for vaults running in Obsidian-friendly mode: `status`,
212239
`openclaw wiki` behavior is shaped by:
213240

214241
- `plugins.entries.memory-wiki.config.vaultMode`
242+
- `plugins.entries.memory-wiki.config.vault.scope`
243+
- `plugins.entries.memory-wiki.config.vault.path`
215244
- `plugins.entries.memory-wiki.config.search.backend`
216245
- `plugins.entries.memory-wiki.config.search.corpus`
217246
- `plugins.entries.memory-wiki.config.bridge.*`

‎docs/concepts/context-engine.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ A plugin can register a context engine using the plugin API:
122122

123123
```ts
124124
import { buildMemorySystemPromptAddition } from "openclaw/plugin-sdk/core";
125+
import { resolveSessionAgentId } from "openclaw/plugin-sdk/memory-host-core";
125126

126127
export default function register(api) {
127128
api.registerContextEngine("my-engine", (ctx) => ({
@@ -136,14 +137,23 @@ export default function register(api) {
136137
return { ingested: true };
137138
},
138139

139-
async assemble({ sessionId, messages, tokenBudget, availableTools, citationsMode }) {
140+
async assemble({
141+
sessionId,
142+
sessionKey,
143+
messages,
144+
tokenBudget,
145+
availableTools,
146+
citationsMode,
147+
}) {
140148
// Return messages that fit the budget
141149
return {
142150
messages: buildContext(messages, tokenBudget),
143151
estimatedTokens: countTokens(messages),
144152
systemPromptAddition: buildMemorySystemPromptAddition({
145153
availableTools: availableTools ?? new Set(),
146154
citationsMode,
155+
agentId: resolveSessionAgentId({ config: ctx.config, sessionKey }),
156+
agentSessionKey: sessionKey,
147157
}),
148158
};
149159
},

‎docs/concepts/multi-agent.md‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
summary: "Multi-agent routing: isolated agents, channel accounts, and bindings"
2+
summary: "Multi-agent routing: agent boundaries, channel accounts, and bindings"
33
title: "Multi-agent routing"
44
sidebarTitle: "Multi-agent routing"
5-
read_when: "You want multiple isolated agents (workspaces + auth) in one gateway process."
5+
read_when: "You want multiple agents with separate workspaces, auth, and sessions in one Gateway process."
66
status: active
77
---
88

9-
Run multiple _isolated_ agents in one Gateway process, each with its own workspace, state directory (`agentDir`), and session store, plus multiple channel accounts (e.g. two WhatsApp numbers). Inbound messages route to the right agent through **bindings**.
9+
Run multiple agents in one Gateway process, each with its own workspace, state directory (`agentDir`), and session store, plus multiple channel accounts (e.g. two WhatsApp numbers). Inbound messages route to the right agent through **bindings**.
1010

1111
An **agent** is the full per-persona scope: workspace files, auth profiles, model registry, and session store. A **binding** maps a channel account (a Slack workspace, a WhatsApp number, etc.) to one of those agents.
1212

@@ -34,6 +34,11 @@ Never reuse `agentDir` across agents — it causes auth/session state collisions
3434

3535
Skills load from each agent workspace plus shared roots such as `~/.openclaw/skills`, then filter by the effective agent skill allowlist. Use `agents.defaults.skills` for a shared baseline and `agents.list[].skills` for a per-agent replacement (explicit entries replace the default, they do not merge). See [Skills: per-agent vs shared](/tools/skills#per-agent-vs-shared-skills) and [Skills: agent allowlists](/tools/skills#agent-allowlists).
3636

37+
Plugin-owned storage follows that plugin's configuration; adding a second agent
38+
does not automatically split every global plugin store. For example, configure
39+
[Memory Wiki per-agent vaults](/concepts/multi-agent#per-agent-memory-wiki-vaults)
40+
when personas must not share compiled wiki knowledge.
41+
3742
<Note>
3843
**Workspace note:** each agent's workspace is the **default cwd**, not a hard sandbox. Relative paths resolve inside the workspace, but absolute paths can reach other host locations unless sandboxing is enabled. See [Sandboxing](/gateway/sandboxing).
3944
</Note>
@@ -114,13 +119,44 @@ openclaw agents list --bindings
114119

115120
## Multiple agents, multiple personas
116121

117-
Each configured `agentId` is a fully isolated persona:
122+
Each configured `agentId` is a distinct persona boundary for core agent state:
118123

119124
- Different accounts per channel (per `accountId`).
120125
- Different personalities (per-agent `AGENTS.md`/`SOUL.md`).
121-
- Separate auth and sessions, with no cross-talk unless explicitly enabled.
126+
- Separate auth and sessions, with cross-agent access enabled only through explicit features or plugin configuration.
127+
128+
This lets multiple people share one Gateway while keeping core agent state separate.
129+
130+
## Per-agent Memory Wiki vaults
131+
132+
Memory Wiki uses one global vault by default. To keep a support agent's
133+
compiled knowledge separate from a marketing agent's, set
134+
`plugins.entries.memory-wiki.config.vault.scope` to `agent`:
135+
136+
```json5
137+
{
138+
plugins: {
139+
entries: {
140+
"memory-wiki": {
141+
enabled: true,
142+
config: {
143+
vault: {
144+
scope: "agent",
145+
path: "~/.openclaw/wiki",
146+
},
147+
},
148+
},
149+
},
150+
},
151+
}
152+
```
122153

123-
This lets multiple people share one Gateway while keeping their agent state isolated.
154+
The configured path is the parent directory. OpenClaw appends the normalized
155+
agent id, producing paths such as `~/.openclaw/wiki/support` and
156+
`~/.openclaw/wiki/marketing`. Agent-scoped CLI and Gateway operations require
157+
an explicit agent when multiple agents are configured. See
158+
[Memory Wiki per-agent vaults](/plugins/memory-wiki#per-agent-vaults) for bridge
159+
filtering, migration, and trust-boundary details.
124160

125161
## Cross-agent QMD memory search
126162

‎docs/docs_map.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
20892089
- Headings:
20902090
- H1: openclaw wiki
20912091
- H2: Common commands
2092+
- H2: Agent selection
20922093
- H2: Commands
20932094
- H3: wiki status
20942095
- H3: wiki doctor
@@ -2640,6 +2641,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
26402641
- H2: Agent helper
26412642
- H2: Quick start
26422643
- H2: Multiple agents, multiple personas
2644+
- H2: Per-agent Memory Wiki vaults
26432645
- H2: Cross-agent QMD memory search
26442646
- H2: One WhatsApp number, multiple people (DM split)
26452647
- H2: Routing rules
@@ -5664,6 +5666,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
56645666
- H2: Agent tools
56655667
- H2: Prompt and context behavior
56665668
- H2: Configuration
5669+
- H3: Per-agent vaults
56675670
- H3: Example: QMD + bridge mode
56685671
- H2: CLI
56695672
- H2: Obsidian support

‎docs/plugins/architecture-internals.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,20 +1063,23 @@ pipeline rather than just add memory search or hooks.
10631063

10641064
```ts
10651065
import { buildMemorySystemPromptAddition } from "openclaw/plugin-sdk/core";
1066+
import { resolveSessionAgentId } from "openclaw/plugin-sdk/memory-host-core";
10661067

10671068
export default function (api) {
10681069
api.registerContextEngine("lossless-claw", (ctx) => ({
10691070
info: { id: "lossless-claw", name: "Lossless Claw", ownsCompaction: true },
10701071
async ingest() {
10711072
return { ingested: true };
10721073
},
1073-
async assemble({ messages, availableTools, citationsMode }) {
1074+
async assemble({ messages, sessionKey, availableTools, citationsMode }) {
10741075
return {
10751076
messages,
10761077
estimatedTokens: 0,
10771078
systemPromptAddition: buildMemorySystemPromptAddition({
10781079
availableTools: availableTools ?? new Set(),
10791080
citationsMode,
1081+
agentId: resolveSessionAgentId({ config: ctx.config, sessionKey }),
1082+
agentSessionKey: sessionKey,
10801083
}),
10811084
};
10821085
},
@@ -1108,6 +1111,7 @@ import {
11081111
buildMemorySystemPromptAddition,
11091112
delegateCompactionToRuntime,
11101113
} from "openclaw/plugin-sdk/core";
1114+
import { resolveSessionAgentId } from "openclaw/plugin-sdk/memory-host-core";
11111115

11121116
export default function (api) {
11131117
api.registerContextEngine("my-memory-engine", (ctx) => ({
@@ -1119,13 +1123,15 @@ export default function (api) {
11191123
async ingest() {
11201124
return { ingested: true };
11211125
},
1122-
async assemble({ messages, availableTools, citationsMode }) {
1126+
async assemble({ messages, sessionKey, availableTools, citationsMode }) {
11231127
return {
11241128
messages,
11251129
estimatedTokens: 0,
11261130
systemPromptAddition: buildMemorySystemPromptAddition({
11271131
availableTools: availableTools ?? new Set(),
11281132
citationsMode,
1133+
agentId: resolveSessionAgentId({ config: ctx.config, sessionKey }),
1134+
agentSessionKey: sessionKey,
11291135
}),
11301136
};
11311137
},

0 commit comments

Comments
 (0)