← Back to Plugins
Voice

Memory Cdc

marcdshark By marcdshark 👁 5 views ▲ 0 votes

An OpenClaw plugin that turns agent memory into an event stream. When one agent learns something, every other agent that cares finds out automatically.

GitHub

Install

npm install
pnpm

Configuration Example

// Hub machine
{ "mode": "hub", "port": 4222 }

// Leaf machine
{ "mode": "leaf", "hub": "nats://hub.tailscale:4222" }

README

# openclaw-memory-cdc

An OpenClaw plugin that turns agent memory into an event stream. When one agent learns something, every other agent that cares finds out automatically. No polling, no cron jobs, no external databases. Just NATS and hooks.

## How It Works

```
Agent A learns something β†’ writes to memory β†’ plugin diffs the change
  β†’ publishes to NATS β†’ Agent B gets a message β†’ plugin injects sync
  β†’ Agent B sees the update in its daily log
```

Two publishing triggers:
- **`session:compact:after`** β€” high-signal: fires after the agent distills its most important learnings
- **`message:sent`** β€” lightweight: fires on explicit "remember this" writes (mtime check, usually a no-op)

One subscribing trigger:
- **`message:received`** β€” drains pending events into today's daily log before the agent processes anything

Agents self-configure their subscriptions via the `MEMORY_CDC` skill. No human configuration needed.

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 OpenClaw Gateway                  β”‚
β”‚                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚Agent A β”‚   β”‚Agent B β”‚   β”‚Agent C β”‚          β”‚
β”‚  β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜          β”‚
β”‚      β”‚            β”‚            β”‚                β”‚
β”‚  β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚         Memory CDC Plugin          β”‚         β”‚
β”‚  β”‚  Hooks   Tools   Publisher   Sub   β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                     β”‚                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚        Embedded NATS Server        β”‚         β”‚
β”‚  β”‚   PubSub ◄──► JetStream           β”‚         β”‚
β”‚  β”‚   Stream: SWARM_MEMORY             β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

For multi-machine setups, NATS leaf nodes transparently bridge events across machines with zero code changes.

## Prerequisites

- Node.js >= 18
- OpenClaw Gateway

## Installation

```bash
openclaw plugins install clawhub:openclaw-memory-cdc
openclaw config set plugins.entries.openclaw-memory-cdc.enabled true
openclaw gateway restart
```

Optional remote config:
```json
// Hub machine
{ "mode": "hub", "port": 4222 }

// Leaf machine
{ "mode": "leaf", "hub": "nats://hub.tailscale:4222" }
```

## Project Structure

```
β”œβ”€β”€ openclaw.plugin.json     # Plugin manifest
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts             # Plugin entry (definePluginEntry)
β”‚   β”œβ”€β”€ config.ts            # Config types
β”‚   β”œβ”€β”€ nats/                # NATS server, client, JetStream
β”‚   β”œβ”€β”€ publisher/           # Differ, formatter, batcher
β”‚   β”œβ”€β”€ subscriber/          # Drain, dedup, injector
β”‚   └── tools/               # 5 agent-facing CDC tools
β”œβ”€β”€ tests/                   # Vitest tests (mirrors src/)
β”œβ”€β”€ skills/
β”‚   └── MEMORY_CDC/          # Agent self-configuration skill
└── docs/
    β”œβ”€β”€ specs/               # Module design specs
    └── concepts/            # Cross-cutting concepts
```

## Development

```bash
pnpm install
pnpm build             # TypeScript compilation
pnpm test              # Run Vitest
pnpm test:coverage     # Coverage report
pnpm lint              # ESLint
pnpm format            # Prettier
```

## Documentation

Design specs and architectural concepts live in `docs/`:

- `docs/specs/` β€” one file per source module (nats, publisher, subscriber, tools, config)
- `docs/concepts/` β€” cross-cutting topics (topology, data flow, self-config, safety)

## License

ISC
voice

Comments

Sign in to leave a comment

Loading comments...