From revskills
Multi-agent shared memory patterns for AI agent coordination. Use when building shared fact logs, collaborative scratchpads, memory reconciliation, or coordinating discoveries between concurrent agents. Covers append-only fact tables, Yjs CRDT scratchpads, LLM-powered reconciliation, and session-scoped memory sharing.
How this skill is triggered — by the user, by Claude, or both
Slash command
/revskills:multi-agent-memoryThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Three layers, each building on the previous:
Three layers, each building on the previous:
Layer 1: Shared Fact Log — append-only discoveries, real-time sync
Layer 2: Yjs CRDT Scratchpad — collaborative working document
Layer 3: Reconciliation — LLM-powered canonical fact extraction
All layers scope by session_id (coordination session). Only agents in the same session share memory.
Append-only table of agent discoveries. No CRDT, no merge — pure append.
CREATE TABLE shared_facts (
id TEXT PRIMARY KEY,
session_id TEXT NOT NULL,
agent_id TEXT NOT NULL,
content TEXT NOT NULL,
fact_type TEXT NOT NULL CHECK (fact_type IN (
'discovery', 'bug', 'decision', 'warning', 'question', 'answer'
)),
confidence REAL NOT NULL DEFAULT 1.0,
tags JSONB NOT NULL DEFAULT '[]',
source_ref JSONB,
superseded_by TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
Write path: agent publishes via REST API -> DB insert -> Electric syncs to subscribers.
// Publishing a fact
await fetch('/api/sync/shared-facts', {
method: 'POST',
body: JSON.stringify({
session_id: 'coord-abc123',
agent_id: 'claude-1',
content: 'auth module has race condition in session refresh',
fact_type: 'bug',
confidence: 0.9,
tags: ['auth', 'concurrency'],
source_ref: { file: 'src/auth/session.ts', line: 42 },
}),
});
Read path (React): subscribe via Electric shape.
function useSharedFacts(sessionId: string) {
const { data, isLoading } = useShape({
url: `${proxyBaseUrl}/api/shapes/shared-facts`,
params: { session_id: sessionId },
});
return { facts: data, isLoading };
}
Read path (CLI agents): poll via daemon RPC or direct API call.
Multiple agents concurrently edit a shared document. Browser agents use WebSocket Yjs collab. CLI agents submit structured patches applied server-side.
| Type | Description | Example |
|---|---|---|
set_key | Set root-level key to string | Title, status |
append_section | Append to Y.Text section | Add findings |
append_item | Push to Y.Array section | Add list item |
replace_section | Replace section entirely | Rewrite plan |
await fetch('/api/sync/yjs-document-patches', {
method: 'POST',
body: JSON.stringify({
document_id: 'scratchpad-task-42',
agent_id: 'claude-2',
patch_type: 'append_item',
path: 'findings',
content: 'Database index missing on user_id column',
}),
});
Server-side: loads Y.Doc state, applies patch, saves updated state. Electric fans out.
import * as Y from 'yjs';
function applyPatch(doc: Y.Doc, patchType: string, path: string, content: string) {
const root = doc.getMap('root');
switch (patchType) {
case 'set_key':
root.set(path, content);
break;
case 'append_section': {
let section = root.get(path);
if (!(section instanceof Y.Text)) {
section = new Y.Text();
root.set(path, section);
}
section.insert(section.length, content);
break;
}
case 'append_item': {
let arr = root.get(path);
if (!(arr instanceof Y.Array)) {
arr = new Y.Array();
root.set(path, arr);
}
arr.push([content]);
break;
}
case 'replace_section': {
const text = new Y.Text();
text.insert(0, content);
root.set(path, text);
break;
}
}
}
Periodic or on-demand LLM pass that reads the fact log, resolves contradictions, deduplicates, and produces canonical memories.
ALTER TABLE agent_memories ADD COLUMN scope TEXT DEFAULT 'private';
-- Values: 'private' (single agent), 'shared' (session-wide), 'reconciled' (LLM-verified)
ALTER TABLE agent_memories ADD COLUMN session_scope TEXT;
ALTER TABLE agent_memories ADD COLUMN source_facts JSONB DEFAULT '[]';
ALTER TABLE agent_memories ADD COLUMN reconciled_at TIMESTAMPTZ;
superseded_by IS NULL)scope = 'reconciled' memories with source_facts referencessuperseded_by the new reconciled memoryNormalize content, deduplicate by exact match, keep highest confidence per group.
| Action | Browser Agent | CLI Agent |
|---|---|---|
| Read facts | Electric shape (real-time) | API poll or daemon RPC |
| Write facts | REST POST | Daemon RPC -> REST POST |
| Edit scratchpad | WebSocket Yjs (live) | Structured patches |
| Read scratchpad | Yjs doc state | API -> decoded JSON |
| Trigger reconciliation | REST POST | Daemon RPC -> REST POST |
All memory is scoped by coordination session ID. When agents start a shared task:
coord-{taskId})npx claudepluginhub revealuistudio/revskills --plugin revskillsGuides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.