← Back to Plugins
Tools

Borgmind

mputiyon1985 By mputiyon1985 👁 50 views ▲ 0 votes

Multi-agent shared knowledge base plugin for OpenClaw fleet

GitHub

Install

npm install
```

Configuration Example

{
  "bootstrap": {
    "plugins": {
      "borgmind": {
        "enabled": true,
        "config": {
          "soulId": "pepper",
          "tursoUrl": "libsql://borgmind-mputiyon1985-mputiyon1985.aws-us-east-1.turso.io",
          "tursoToken": "<your-primary-token>",
          "tokens": {
            "pepper": "<pepper-token>",
            "jarvis": "<jarvis-token>",
            "tony": "<tony-token>",
            "rhodey": "<rhodey-token>"
          },
          "agentNames": {
            "main": "Pepper",
            "rocket": "Rocket",
            "groot": "Groot",
            "nebula": "Nebula",
            "rhodey": "Rhodey"
          }
        }
      }
    }
  }
}

README

# BorgMind Plugin โ€” OpenClaw Gateway Plugin

Shared multi-agent persistent memory, knowledge graph, and inter-agent messaging built on Turso/libSQL.

**Version:** 1.0.0  
**License:** MIT

## Features

โœ… **Shared Memory** โ€” Any agent can read/write persistent memory entries  
โœ… **Auto-Source-Tagging** โ€” Every write is tagged with the writing agent's name  
โœ… **Conflict Resolution** โ€” Cross-agent overwrites are fully audited in `memory_log` table  
โœ… **Force-Sync Reads** โ€” `borgmind.recall(..., {fresh:true})` flushes the embedded replica before reading  
โœ… **Knowledge Graph** โ€” BFS-traversable shared knowledge (subjectโ†’predicateโ†’object triples)  
โœ… **Inter-Agent Messaging** โ€” Send/receive messages via shared `comms` table  
โœ… **Tiered Storage** โ€” hot/warm/cold tiers with TTL support  
โœ… **Tier Promotion** โ€” Automatic promotion/demotion via libSQL (not cron)  

## Installation

```bash
cd ~/.openclaw/extensions/borgmind-plugin
npm install
```

## Configuration

> โš ๏ธ **Security:** Do NOT commit `openclaw.json` with plaintext tokens. Use env-var placeholders like `${BORGMIND_TOKEN_PEPPER}`. The plugin resolves `${VAR_NAME}` syntax against `process.env` at startup.

Add to your `openclaw.json` plugins section:

```json
{
  "bootstrap": {
    "plugins": {
      "borgmind": {
        "enabled": true,
        "config": {
          "soulId": "pepper",
          "tursoUrl": "libsql://borgmind-mputiyon1985-mputiyon1985.aws-us-east-1.turso.io",
          "tursoToken": "<your-primary-token>",
          "tokens": {
            "pepper": "<pepper-token>",
            "jarvis": "<jarvis-token>",
            "tony": "<tony-token>",
            "rhodey": "<rhodey-token>"
          },
          "agentNames": {
            "main": "Pepper",
            "rocket": "Rocket",
            "groot": "Groot",
            "nebula": "Nebula",
            "rhodey": "Rhodey"
          }
        }
      }
    }
  }
}
```

### Field Reference

| Field | Required | Description |
|---|---|---|
| `soulId` | No | Default soul ID if agentId not provided (default: `pepper`) |
| `tursoUrl` | Yes | Full `libsql://` URL to the Turso database |
| `tursoToken` | Yes | Primary/Pepper auth token (used as fallback for unknown agents) |
| `tokens` | No | Per-agent auth tokens override `tursoToken` |
| `agentNames` | No | Maps session agent IDs โ†’ display/source names |
| `enabled` | No | Set `false` to disable the plugin without removing config |

## Registered Tools

| Tool | Description |
|---|---|
| `borgmind.remember` | Write shared memory. Auto-tags source. Returns conflict warning. |
| `borgmind.recall` | Read memory by category+key. `{fresh:true}` force-syncs first. |
| `borgmind.search` | Search across all memory (LIKE match on category/key). |
| `borgmind.know` | Add a knowledge graph triple (subjectโ†’predicateโ†’object). |
| `borgmind.ask` | BFS-traverse the knowledge graph from a starting subject. |
| `borgmind.send` | Send an inter-agent message (stored in shared `comms` category). |
| `borgmind.inbox` | List messages addressed to the current agent. |

### Tool Examples

```
// Write a memory
borgmind.remember({ category: "project.iat", key: "version", value: "2.3.1" })

// Read it
borgmind.recall({ category: "project.iat", key: "version" })

// Read fresh
borgmind.recall({ category: "project.iat", key: "version", options: { fresh: true } })

// Search
borgmind.search({ query: "iat", options: { tier: "hot" } })

// Add knowledge
borgmind.know({ subject: "iat", predicate: "hosted_on", object: "vercel" })

// Traverse
borgmind.ask({ subject: "iat" })

// Send message
borgmind.send({ recipient: "tony", message: "Deploy staging now" })

// Check inbox
borgmind.inbox({ options: { unreadOnly: true } })
```

## Conflict Resolution

When agent A writes `project.x/key` and agent B later writes the same key:
1. Detection: `written_by` in DB โ‰  current agent
2. Audit: `memory_log` records `action='conflict_resolution'` with `old_value` + `new_value`
3. Supersession log is written (old record marked as superseded)
4. Agent B receives a warning: `"Key was previously written by A at [time]. Your write overwrote it."`
5. Last-write-wins (but fully auditable)

## Source Auto-Tagging

Inside tool execute handlers:
```js
const source = options.source ?? resolveSource(agentId, pluginCfg.agentNames);
```

So `borgmind.remember({category:'x', key:'y', value:'z'})` automatically tags `source='Pepper'` when called from Pepper's session, without the agent specifying it.

## Smoke Test

```bash
cd ~/.openclaw/extensions/borgmind-plugin
node test/test-smoke.js
```

The smoke test:
- Imports the BorgMind library directly (bypass the plugin registration)
- Writes a memory as pepper
- Reads it back
- Verifies source auto-tag
- Writes as tony to trigger conflict detection
- Verifies conflict logged in `memory_log`
- Tests knowledge graph traversal
- Tests inter-agent messaging
- Cleans up test rows

## Architecture

```
borgmind-plugin/
โ”œโ”€โ”€ index.js          โ† Plugin entry (definePluginEntry, hooks + 7 tool factories)
โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ borgmind.js   โ† Main API (BorgMind.init, BorgMindInstance class)
โ”‚   โ”œโ”€โ”€ memory.js     โ† write_memory, read_memory, search_memory, inbox
โ”‚   โ”œโ”€โ”€ graph.js      โ† add_relationship, traverse
โ”‚   โ”œโ”€โ”€ souls.js      โ† read_soul, update_soul, upsert_soul
โ”‚   โ”œโ”€โ”€ sync.js       โ† syncReplica (turso embedded replica flush)
โ”‚   โ””โ”€โ”€ db.js         โ† DB factory (initDb, getClient, closeAll)
โ”œโ”€โ”€ schema.sql        โ† Full DB schema (copy from workspace)
โ”œโ”€โ”€ test/
โ”‚   โ””โ”€โ”€ test-smoke.js โ† Independent smoke test
โ”œโ”€โ”€ BUILD-LOG.md      โ† Development log
โ””โ”€โ”€ README.md         โ† This file
```

## Notes

- Uses Turso embedded replicas for low-latency local reads
- Schema is auto-applied on first init (all `CREATE TABLE IF NOT EXISTS`)
- No external sync engine needed โ€” libSQL's embedded replica handles push/pull
- Tokens map: pepper (primary), jarvis, tony, rhodey all share the same DB
- `agent_end` hook triggers sync + close per session
- Tool factories receive `ctx.agentId` and `ctx.sessionKey` for multi-agent isolation
tools

Comments

Sign in to leave a comment

Loading comments...