SGA-MCTS Atoms

Plan-time atom retrieval for OpenClaw. Distill Inspector-approved sessions into reusable atomic experience. Pure Node, native SQLite via better-sqlite3.

Install

openclaw plugins install clawhub:openclaw-sga-mcts-atoms

SGA-MCTS Atoms

Plan-time atom retrieval for OpenClaw multi-agent crews. When Inspector signs off on a session above the configured score threshold, the plugin extracts atomic units of experience and stores them in a local SQLite database. Captain queries the store via retrieve_atoms during plan decomposition for new tasks, biasing decomposition toward strategies that previously worked.

Pure Node: no Python, native SQLite via better-sqlite3 (ships prebuilt arm64 binaries, no compile step on Pi 5). Bag-of-tokens Jaccard scoring keeps retrieval predictable, dependency-free, and zero-cost.

Install

Via OpenClaw plugins CLI:

openclaw plugins install clawhub:openclaw-sga-mcts-atoms

No --dangerously-force-unsafe-install flag required as of v2.0.0. The plugin scans cleanly: no child_process, no shell-out.

Configure in OpenClaw

{
  "plugins": {
    "entries": {
      "sga-mcts-atoms": {
        "enabled": true,
        "config": {
          "dbPath": "/home/USER/.openclaw/sga_mcts/atoms.db",
          "minSessionScore": 0.7,
          "topK": 5
        }
      }
    }
  }
}

Restart the gateway: systemctl --user restart openclaw-gateway.

Surfaces

WhereWhat
Hook agent_endIf event.inspector.score >= minSessionScore, read atoms from ~/.openclaw/sessions/<sessionId>.json and insert deduped rows into the atom DB
Tool retrieve_atoms({query, k})Captain calls this during plan decomposition; returns top-k atoms by Jaccard token overlap with the query
Tool extract_atoms({session_id})Manual extraction for back-fill

Atom store schema

CREATE TABLE atoms (
  id      INTEGER PRIMARY KEY,
  session TEXT    NOT NULL,
  text    TEXT    NOT NULL UNIQUE,
  score   REAL    NOT NULL DEFAULT 0,
  created TEXT    NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_atoms_session ON atoms(session);

text carries a UNIQUE constraint, so duplicate atoms across sessions collapse naturally on insert.

Performance

  • Extraction on agent_end: ~5ms per session on a Pi 5 (in-process SQLite, transactional insert)
  • retrieve_atoms: ~10ms over 1000 atoms with Jaccard scoring; scales linearly, fine up to ~50k rows
  • Storage: ~200 bytes per atom; 10k atoms ≈ 2MB SQLite file
  • No network, no embeddings, no external services

Changelog

2.0.0

  • Removed Python extractor and retriever scripts. All logic now in Node via better-sqlite3.
  • No more child_process. Plugin scans cleanly without --dangerously-force-unsafe-install.
  • Manifest no longer declares python3 runtime.
  • Bag-of-tokens scoring upgraded from match-count to proper Jaccard similarity.

License

MIT. Source: https://github.com/msbel5/openclaw-sga-mcts-atoms