You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Require [sqlite-sync](https://github.com/sqliteai/sqlite-sync) to be loaded before use.
406
+
407
+
#### `memory_enable_sync([context TEXT, ...])`
408
+
409
+
Enables CRDT-based synchronization for `dbmem_content` via sqlite-sync. Uses the CLS algorithm with block-level LWW on the `value` column for fine-grained conflict resolution.
410
+
411
+
**Parameters:** Zero or more TEXT context names. If no arguments are given, all memory is synced. If one or more context names are provided, only rows matching those contexts are synced.
412
+
413
+
**Returns:** INTEGER - 1 on success
414
+
415
+
**Notes:**
416
+
- Requires sqlite-sync to be loaded; returns an error otherwise
417
+
- Idempotent: safe to call multiple times — each call is a full reconfiguration
418
+
- With no arguments, any previously-set context filter is cleared (sync all)
419
+
- With arguments, sets a row-level filter: only the specified contexts are replicated
420
+
- Block-level LWW on `value` enables line-level conflict resolution for text content
Copy file name to clipboardExpand all lines: README.md
+47-3Lines changed: 47 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -164,11 +164,55 @@ Every sync operation is wrapped in a SQLite SAVEPOINT transaction. If anything f
164
164
165
165
This makes all sync functions safe to call repeatedly - for example, on a cron schedule or at agent startup - with minimal overhead.
166
166
167
-
## AI Agents Offline Syncing
167
+
## Agent Memory Sync
168
168
169
-
Thanks to sqlite-sync, agents can share knowledge. Each markdown file added to the database is intelligently parsed and subdivided into chunks, and a [block-based LWW CRDT algorithm](https://github.com/sqliteai/sqlite-sync?tab=readme-ov-file#block-level-lww) keeps everything in sync. All memory, or just a specific memory context, can be kept in sync between agents.
169
+
Multiple agents can share and merge knowledge without any coordination. Each agent works independently with its own local SQLite database, syncing through a shared [SQLiteCloud](https://sqlitecloud.io/) managed database when connectivity is available.
170
170
171
-
Memory syncing will be exposed in version 0.9.0.
171
+
Enable sync on a database connection before ingesting content:
172
+
173
+
```sql
174
+
-- Load the sqlite-sync extension
175
+
SELECT load_extension('./cloudsync');
176
+
177
+
-- Enable CRDT sync (optionally scoped to a specific context)
178
+
SELECT memory_enable_sync(); -- sync all memory
179
+
SELECT memory_enable_sync('project-x'); -- sync only the 'project-x' context
-- Ingest content normally — CRDT tracks every write
186
+
SELECT memory_add_text('Agent A findings...', 'research');
187
+
188
+
-- Push local changes and pull remote ones (call twice for full bidirectional exchange)
189
+
SELECT cloudsync_network_sync(500, 3);
190
+
SELECT cloudsync_network_sync(500, 3);
191
+
192
+
-- Generate embeddings for any content received from other agents
193
+
SELECT memory_reindex();
194
+
```
195
+
196
+
Each piece of text added to the database is parsed into chunks and tracked by a [block-level LWW CRDT algorithm](https://github.com/sqliteai/sqlite-sync?tab=readme-ov-file#block-level-lww), which merges line-level changes from concurrent agents without conflicts. Only the `dbmem_content` table is synced — embeddings are always generated locally after receiving new content.
197
+
198
+
### Why This Matters for AI Systems
199
+
200
+
The combination of local-first memory and CRDT sync enables agent architectures that are not possible with centralized databases:
201
+
202
+
-**No single point of failure** — each agent has a complete, queryable copy of shared memory
203
+
-**Offline-capable** — agents ingest and search without network access; sync catches up when connectivity returns
204
+
-**Selective sharing** — `memory_enable_sync('context')` limits sync to a named context, so agents can keep private memory separate from shared memory
205
+
-**Scales to many agents** — agents running on different nodes accumulate knowledge in parallel and merge into a single consistent corpus without coordination
206
+
207
+
### Working Example
208
+
209
+
[`test/sync/`](test/sync/) contains a full integration test that walks through the entire flow:
210
+
211
+
- Agent A indexes knowledge about the James Webb Space Telescope
212
+
- Agent B indexes knowledge about the Great Barrier Reef
213
+
- After sync, **both agents can answer questions about both topics** — knowledge each agent never directly indexed
214
+
215
+
See [`test/sync/README.md`](test/sync/README.md) for setup instructions, SQLiteCloud account configuration, and how to run the test.
0 commit comments