@cognee/cognee-openclaw 2026.3.0 → 2026.3.2

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/README.md CHANGED
@@ -1,13 +1,32 @@
1
1
  # @cognee/cognee-openclaw
2
2
 
3
- OpenClaw plugin that adds Cognee-backed memory with automatic recall and indexing.
3
+ OpenClaw plugin that adds Cognee-backed memory with **multi-scope support** (company/user/agent), session tracking, and automatic recall.
4
4
 
5
5
  ## Features
6
6
 
7
- - **Auto-recall**: Before each agent run, searches Cognee for relevant memories and injects them as context
8
- - **Auto-index**: On startup and after each agent run, syncs memory markdown files to Cognee (add new, update changed, delete removed, skip unchanged)
9
- - **CLI commands**: `openclaw cognee index` to manually sync, `openclaw cognee status` to check state
10
- - **Configurable**: Search type, max results, score filtering, token limits, and more
7
+ - **Multi-scope memory**: Separate datasets for company-wide knowledge, per-user preferences, and per-agent context
8
+ - **Scope-aware routing**: Memory files are automatically routed to the correct dataset based on directory structure
9
+ - **Multi-scope recall**: Before each agent run, searches across all configured scopes and injects labeled context
10
+ - **Session tracking**: Multi-turn conversation context via Cognee's session system
11
+ - **14 search types**: From simple semantic search (CHUNKS) to chain-of-thought graph reasoning (GRAPH_COMPLETION_COT) to auto-selection (FEELING_LUCKY)
12
+ - **Health check**: Verifies Cognee API connectivity before operations
13
+ - **Auto-index**: Syncs memory markdown files to Cognee (add new, update changed, delete removed, skip unchanged)
14
+ - **Memify support**: Optional graph enrichment after cognify for better entity consolidation
15
+ - **One-command setup**: `openclaw cognee setup` configures Cognee as the sole memory provider
16
+ - **CLI commands**: `openclaw cognee setup`, `openclaw cognee index`, `openclaw cognee status`, `openclaw cognee health`, `openclaw cognee scopes`
17
+
18
+ ## Security: Recommended Plugin Allowlist
19
+
20
+ OpenClaw will auto-load any plugin it discovers if `plugins.allow` is not set. To restrict which plugins can load, add an explicit allowlist to your `~/.openclaw/openclaw.json`:
21
+
22
+ ```yaml
23
+ plugins:
24
+ allow:
25
+ - cognee-openclaw
26
+ - cognee-openclaw-skills
27
+ ```
28
+
29
+ Without this, any plugin found in your environment could be loaded automatically.
11
30
 
12
31
  ## Installation
13
32
 
@@ -23,12 +42,27 @@ openclaw plugins install -l .
23
42
  Or once published:
24
43
 
25
44
  ```bash
26
- openclaw plugins install @cognee/cognee-openclaw
45
+ # Pin to an exact version to avoid unintended updates (supply-chain best practice)
46
+ openclaw plugins install @cognee/cognee-openclaw@2026.3.0
27
47
  ```
28
48
 
29
- ## Configuration
49
+ ## Quick Start
50
+
51
+ After installing, run the setup command to configure Cognee as the memory provider:
30
52
 
31
- Enable the plugin in your OpenClaw config (`~/.openclaw/config.yaml` or project config):
53
+ ```bash
54
+ # Cognee only (replaces built-in memory)
55
+ openclaw cognee setup
56
+
57
+ # Or keep built-in memory alongside Cognee
58
+ openclaw cognee setup --hybrid
59
+ ```
60
+
61
+ **Default mode** disables built-in memory providers — all recall comes from Cognee.
62
+
63
+ **Hybrid mode** keeps `memory-core` enabled — the agent uses both Cognee recall and built-in memory search.
64
+
65
+ Then optionally configure the Cognee connection in `~/.openclaw/openclaw.json`:
32
66
 
33
67
  ```yaml
34
68
  plugins:
@@ -39,64 +73,197 @@ plugins:
39
73
  baseUrl: "http://localhost:8000"
40
74
  apiKey: "${COGNEE_API_KEY}"
41
75
  datasetName: "my-project"
42
- searchType: "GRAPH_COMPLETION"
43
- deleteMode: "hard"
44
- maxResults: 6
45
- autoRecall: true
46
- autoIndex: true
47
76
  ```
48
77
 
49
- Set your API key in the environment:
78
+ ## Multi-Scope Memory
50
79
 
51
- ```bash
52
- export COGNEE_API_KEY="your-key-here"
80
+ For production use, enable multi-scope mode by setting any scope-specific dataset name:
81
+
82
+ ```yaml
83
+ plugins:
84
+ entries:
85
+ cognee-openclaw:
86
+ enabled: true
87
+ config:
88
+ baseUrl: "http://localhost:8000"
89
+ apiKey: "${COGNEE_API_KEY}"
90
+
91
+ # Multi-scope datasets
92
+ companyDataset: "acme-shared"
93
+ userDatasetPrefix: "acme-user"
94
+ agentDatasetPrefix: "acme-agent"
95
+ userId: "${OPENCLAW_USER_ID}"
96
+ agentId: "code-assistant"
97
+
98
+ # Search all scopes during recall (in priority order)
99
+ recallScopes:
100
+ - agent
101
+ - user
102
+ - company
103
+
104
+ # Default scope for files not matching any route
105
+ defaultWriteScope: "agent"
106
+ ```
107
+
108
+ ### Memory Scope Hierarchy
109
+
110
+ | Scope | Dataset | Purpose | Example Files |
111
+ |-------|---------|---------|---------------|
112
+ | **Company** | `acme-shared` | Shared knowledge across all users/agents | `memory/company/policies.md`, `memory/company/domain-glossary.md` |
113
+ | **User** | `acme-user-alice` | Per-user preferences, feedback, corrections | `memory/user/preferences.md`, `memory/user/feedback.md` |
114
+ | **Agent** | `acme-agent-code-assistant` | Per-agent learned behaviors, tool outputs | `memory/tools.md`, `MEMORY.md` |
115
+
116
+ ### Scope Routing
117
+
118
+ Files are routed to scopes based on their path. Default routing rules:
119
+
120
+ ```
121
+ memory/company/** -> company scope
122
+ memory/user/** -> user scope
123
+ memory/** -> agent scope (catch-all)
124
+ MEMORY.md -> agent scope
125
+ ```
126
+
127
+ Custom routing via config:
128
+
129
+ ```yaml
130
+ scopeRouting:
131
+ - pattern: "memory/shared/**"
132
+ scope: company
133
+ - pattern: "memory/personal/**"
134
+ scope: user
135
+ - pattern: "memory/**"
136
+ scope: agent
53
137
  ```
54
138
 
139
+ ### Multi-Scope Recall
140
+
141
+ During recall, the plugin searches each scope independently and injects labeled results:
142
+
143
+ ```xml
144
+ <cognee_memories>
145
+ <agent_memory>[agent-specific results]</agent_memory>
146
+ <user_memory>[user preference results]</user_memory>
147
+ <company_memory>[shared knowledge results]</company_memory>
148
+ </cognee_memories>
149
+ ```
150
+
151
+ This lets the agent distinguish between personal context, shared knowledge, and its own learned patterns.
152
+
55
153
  ## Configuration Options
56
154
 
155
+ ### Connection
156
+
57
157
  | Option | Type | Default | Description |
58
158
  |--------|------|---------|-------------|
59
159
  | `baseUrl` | string | `http://localhost:8000` | Cognee API base URL |
60
160
  | `apiKey` | string | `$COGNEE_API_KEY` | API key for authentication |
61
- | `datasetName` | string | `openclaw` | Dataset name for storing memories |
62
- | `searchType` | string | `GRAPH_COMPLETION` | Search mode: `GRAPH_COMPLETION`, `CHUNKS`, `SUMMARIES` |
63
- | `maxResults` | number | `6` | Max memories to inject per recall |
64
- | `minScore` | number | `0` | Minimum relevance score filter |
65
- | `maxTokens` | number | `512` | Token cap for recall context |
161
+
162
+ ### Memory Scopes
163
+
164
+ | Option | Type | Default | Description |
165
+ |--------|------|---------|-------------|
166
+ | `companyDataset` | string | — | Dataset for company-wide memory. Setting this enables multi-scope mode |
167
+ | `userDatasetPrefix` | string | — | Prefix for user datasets (becomes `{prefix}-{userId}`) |
168
+ | `agentDatasetPrefix` | string | — | Prefix for agent datasets (becomes `{prefix}-{agentId}`) |
169
+ | `userId` | string | `$OPENCLAW_USER_ID` | User identifier for user-scoped memory |
170
+ | `agentId` | string | `default` | Agent identifier for agent-scoped memory |
171
+ | `recallScopes` | string[] | `["agent","user","company"]` | Scopes to search during recall, in priority order |
172
+ | `defaultWriteScope` | string | `agent` | Default scope for files not matching any route |
173
+ | `scopeRouting` | object[] | (see above) | Path-to-scope routing rules |
174
+
175
+ ### Sessions
176
+
177
+ | Option | Type | Default | Description |
178
+ |--------|------|---------|-------------|
179
+ | `enableSessions` | boolean | `true` | Enable session-based conversation tracking |
180
+ | `persistSessionsAfterEnd` | boolean | `true` | Persist session Q&A into the knowledge graph |
181
+
182
+ ### Search
183
+
184
+ | Option | Type | Default | Description |
185
+ |--------|------|---------|-------------|
186
+ | `searchType` | string | `GRAPH_COMPLETION` | Search strategy (see below) |
187
+ | `maxResults` | number | `3` | Max memories to inject per scope |
188
+ | `minScore` | number | `0.3` | Minimum relevance score filter |
189
+ | `maxTokens` | number | `512` | Token cap for recall context per scope |
190
+ | `searchPrompt` | string | `""` | System prompt to guide search |
191
+
192
+ ### Search Types
193
+
194
+ | Type | Description |
195
+ |------|-------------|
196
+ | `GRAPH_COMPLETION` | **Default** — graph traversal + LLM reasoning |
197
+ | `CHUNKS` | Semantic vector search, returns raw stored text (no generation) |
198
+ | `FEELING_LUCKY` | Auto-selects a strategy per query (may pick generative modes) |
199
+ | `GRAPH_COMPLETION_COT` | Chain-of-thought reasoning over graph (iterative) |
200
+ | `GRAPH_COMPLETION_CONTEXT_EXTENSION` | Extended context retrieval (multiple rounds) |
201
+ | `GRAPH_SUMMARY_COMPLETION` | Graph with pre-computed summaries |
202
+ | `RAG_COMPLETION` | Traditional RAG with document chunks |
203
+ | `TRIPLET_COMPLETION` | Subject-predicate-object search |
204
+ | `CHUNKS` | Pure semantic vector search |
205
+ | `CHUNKS_LEXICAL` | Keyword/lexical search |
206
+ | `SUMMARIES` | Pre-computed hierarchical summaries |
207
+ | `TEMPORAL` | Time-aware graph search |
208
+ | `NATURAL_LANGUAGE` | Natural language to graph query |
209
+ | `CYPHER` | Direct graph database queries |
210
+ | `CODING_RULES` | Code-specific rule search |
211
+
212
+ ### Automation
213
+
214
+ | Option | Type | Default | Description |
215
+ |--------|------|---------|-------------|
66
216
  | `autoRecall` | boolean | `true` | Inject memories before agent runs |
67
217
  | `autoIndex` | boolean | `true` | Sync memory files on startup and after agent runs |
68
218
  | `autoCognify` | boolean | `true` | Run cognify after new memories are added |
69
- | `deleteMode` | string | `soft` | Delete mode: `soft` removes raw data only, `hard` also removes degree-one graph nodes |
70
- | `searchPrompt` | string | `""` | System prompt sent to Cognee to guide search query processing |
71
- | `requestTimeoutMs` | number | `60000` | HTTP timeout for Cognee requests |
72
- | `ingestionTimeoutMs` | number | `300000` | HTTP timeout for add/update (ingestion) requests, which are typically slower |
219
+ | `autoMemify` | boolean | `false` | Run memify (graph enrichment) after cognify |
220
+ | `deleteMode` | string | `soft` | `soft` removes raw data, `hard` also removes graph nodes |
73
221
 
74
- ## How It Works
222
+ ### Timeouts
75
223
 
76
- 1. **On startup**: Scans `memory/` directory for markdown files and syncs to Cognee (add new, update changed, delete removed, skip unchanged)
77
- 2. **Before agent start**: Searches Cognee for memories relevant to the prompt and prepends as `<cognee_memories>` context
78
- 3. **After agent end**: Re-scans memory files and syncs any changes the agent made (including deletions)
79
- 4. **State tracking**:
80
- - `~/.openclaw/memory/cognee/datasets.json` — dataset ID mapping
81
- - `~/.openclaw/memory/cognee/sync-index.json` — per-file hash and Cognee data IDs
224
+ | Option | Type | Default | Description |
225
+ |--------|------|---------|-------------|
226
+ | `requestTimeoutMs` | number | `60000` | HTTP timeout for Cognee requests |
227
+ | `ingestionTimeoutMs` | number | `300000` | HTTP timeout for add/update requests |
82
228
 
83
- Memory files detected at: `MEMORY.md` and `memory/**/*.md` (recursive)
229
+ Note: Files are stored in Cognee using sanitized relative paths as filenames (e.g., `MEMORY.md.txt` for `MEMORY.md`, `memory.tools.md.txt` for `memory/tools.md`) for easy identification and to avoid path separator issues.
84
230
 
85
231
  ## CLI Commands
86
232
 
87
233
  ```bash
234
+ # Configure Cognee as the memory provider (run once after install)
235
+ openclaw cognee setup # Cognee only
236
+ openclaw cognee setup --hybrid # Cognee + built-in memory
237
+
88
238
  # Manually sync memory files to Cognee
89
239
  openclaw cognee index
90
240
 
91
- # Check sync status (indexed files, pending changes)
241
+ # Check sync status (files indexed, dataset info, per-scope breakdown)
92
242
  openclaw cognee status
243
+
244
+ # Verify Cognee API connectivity
245
+ openclaw cognee health
246
+
247
+ # Show memory scope routing for current workspace files
248
+ openclaw cognee scopes
93
249
  ```
94
250
 
251
+ ## How It Works
252
+
253
+ 1. **On startup**: Health check, then scan `memory/` directory and sync files to scope-specific Cognee datasets
254
+ 2. **Before agent start**: Search each configured scope in parallel, merge results with scope labels, inject as `<cognee_memories>` context
255
+ 3. **After agent end**: Re-scan memory files and sync any changes (including deletions) to the correct scope datasets
256
+ 4. **State tracking**:
257
+ - `~/.openclaw/memory/cognee/datasets.json` — dataset ID mapping
258
+ - `~/.openclaw/memory/cognee/scoped-sync-indexes.json` — per-scope file hashes and data IDs
259
+ - `~/.openclaw/memory/cognee/sync-index.json` — legacy single-scope index
260
+
261
+ Memory files detected at: `MEMORY.md` and `memory/**/*.md` (recursive)
262
+
95
263
  ## Development
96
264
 
97
265
  ```bash
98
266
  cd integrations/openclaw
99
- # Build once, then link for local development with an OpenClaw project
100
267
  npm install
101
268
  npm run build
102
269
  openclaw plugins install -l .
@@ -110,8 +277,6 @@ npm run dev
110
277
 
111
278
  ## Testing
112
279
 
113
- Run the test suite to verify functionality:
114
-
115
280
  ```bash
116
281
  npm test
117
282
  ```
package/dist/index.d.ts CHANGED
@@ -1,142 +1,8 @@
1
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
- type CogneeSearchType = "GRAPH_COMPLETION" | "CHUNKS" | "SUMMARIES";
3
- type CogneeDeleteMode = "soft" | "hard";
4
- type CogneePluginConfig = {
5
- baseUrl?: string;
6
- apiKey?: string;
7
- username?: string;
8
- password?: string;
9
- datasetName?: string;
10
- searchType?: CogneeSearchType;
11
- searchPrompt?: string;
12
- deleteMode?: CogneeDeleteMode;
13
- maxResults?: number;
14
- minScore?: number;
15
- maxTokens?: number;
16
- autoRecall?: boolean;
17
- autoIndex?: boolean;
18
- autoCognify?: boolean;
19
- requestTimeoutMs?: number;
20
- ingestionTimeoutMs?: number;
21
- };
22
- type CogneeSearchResult = {
23
- id: string;
24
- text: string;
25
- score: number;
26
- metadata?: Record<string, unknown>;
27
- };
28
- type SyncIndex = {
29
- datasetId?: string;
30
- datasetName?: string;
31
- entries: Record<string, {
32
- hash: string;
33
- dataId?: string;
34
- }>;
35
- };
36
- type MemoryFile = {
37
- /** Relative path from workspace root (e.g. "MEMORY.md", "memory/tools.md") */
38
- path: string;
39
- /** Absolute path on disk */
40
- absPath: string;
41
- /** File content */
42
- content: string;
43
- /** SHA-256 hex hash of content */
44
- hash: string;
45
- };
46
- type SyncResult = {
47
- added: number;
48
- updated: number;
49
- skipped: number;
50
- errors: number;
51
- deleted: number;
52
- };
53
- declare class CogneeClient {
54
- private readonly baseUrl;
55
- private readonly apiKey?;
56
- private readonly username?;
57
- private readonly password?;
58
- private readonly timeoutMs;
59
- private readonly ingestionTimeoutMs;
60
- private authToken;
61
- private loginPromise;
62
- constructor(baseUrl: string, apiKey?: string, username?: string, password?: string, timeoutMs?: number, ingestionTimeoutMs?: number);
63
- /**
64
- * Authenticate with Cognee via /api/v1/auth/login.
65
- * Falls back to default local dev credentials when none are configured.
66
- */
67
- login(): Promise<void>;
68
- /**
69
- * Ensure the client is authenticated (login once, reuse token).
70
- */
71
- ensureAuth(): Promise<void>;
72
- private buildHeaders;
73
- private fetchJson;
74
- add(params: {
75
- data: string;
76
- datasetName: string;
77
- datasetId?: string;
78
- }): Promise<{
79
- datasetId: string;
80
- datasetName: string;
81
- dataId?: string;
82
- }>;
83
- update(params: {
84
- dataId: string;
85
- datasetId: string;
86
- data: string;
87
- }): Promise<{
88
- datasetId: string;
89
- datasetName: string;
90
- dataId?: string;
91
- }>;
92
- /**
93
- * Query the dataset's data items and find a matching entry by filename.
94
- * Used as fallback when add/update responses don't include a usable data_id.
95
- */
96
- resolveDataIdFromDataset(datasetId: string, fileName: string): Promise<string | undefined>;
97
- delete(params: {
98
- dataId: string;
99
- datasetId: string;
100
- mode?: CogneeDeleteMode;
101
- }): Promise<{
102
- datasetId: string;
103
- dataId: string;
104
- deleted: boolean;
105
- error?: string;
106
- }>;
107
- cognify(params?: {
108
- datasetIds?: string[];
109
- }): Promise<{
110
- status?: string;
111
- }>;
112
- search(params: {
113
- queryText: string;
114
- searchPrompt: string;
115
- searchType: CogneeSearchType;
116
- datasetIds: string[];
117
- maxTokens: number;
118
- }): Promise<CogneeSearchResult[]>;
119
- /**
120
- * Normalize Cognee search response to consistent format.
121
- * Cognee returns a direct array of strings: ["answer text here"]
122
- * We convert to: [{ id, text, score }]
123
- */
124
- private normalizeSearchResults;
125
- private extractDataId;
126
- }
127
- declare function syncFiles(client: CogneeClient, changedFiles: MemoryFile[], fullFiles: MemoryFile[], syncIndex: SyncIndex, cfg: Required<CogneePluginConfig>, logger: {
128
- info?: (msg: string) => void;
129
- warn?: (msg: string) => void;
130
- }): Promise<SyncResult & {
131
- datasetId?: string;
132
- }>;
133
- declare const memoryCogneePlugin: {
134
- id: string;
135
- name: string;
136
- description: string;
137
- kind: "memory";
138
- register(api: OpenClawPluginApi): void;
139
- };
140
- export default memoryCogneePlugin;
141
- export { CogneeClient, syncFiles };
142
- export type { CogneeDeleteMode, CogneePluginConfig, MemoryFile, SyncIndex, SyncResult };
1
+ export { default } from "./src/plugin.js";
2
+ export { CogneeHttpClient } from "./src/client.js";
3
+ export { syncFiles, syncFilesScoped } from "./src/sync.js";
4
+ export { matchGlob, routeFileToScope, datasetNameForScope, isMultiScopeEnabled } from "./src/scope.js";
5
+ export { resolveConfig } from "./src/config.js";
6
+ export { collectMemoryFiles, hashText } from "./src/files.js";
7
+ export { loadDatasetState, saveDatasetState, loadSyncIndex, saveSyncIndex, loadScopedSyncIndexes, saveScopedSyncIndexes, migrateLegacyIndex, } from "./src/persistence.js";
8
+ export type { CogneeDeleteMode, CogneePluginConfig, CogneeSearchType, CogneeSearchResult, MemoryFile, MemoryScope, ScopeRoute, ScopedSyncIndexes, SyncIndex, SyncResult, } from "./src/types.js";