oG-Memory Context Engine - OpenClaw Plugin
OpenClaw context-engine plugin backed by oG-Memory. It connects OpenClaw lifecycle calls to the oG-Memory HTTP API, injects layered memory context before model inference, persists new memories after each turn, and supports oG-Memory-owned compact takeover.
Prerequisites
- Node.js >= 18
- OpenClaw installed and running
- An oG-Memory HTTP service reachable from the OpenClaw gateway, or local-mode prerequisites for starting AGFS + ContextEngine from this plugin
Install
cd openclaw_context_engine_plugin
openclaw plugins install -l .
Configure
Set the context engine slot in ~/.openclaw/openclaw.json.
Remote Mode
Use remote when oG-Memory is already running.
{
"plugins": {
"slots": {
"contextEngine": "og-memory-context-engine"
},
"entries": {
"og-memory-context-engine": {
"enabled": true,
"config": {
"mode": "remote",
"memoryApiBaseUrl": "http://127.0.0.1:8090",
"prefetchEnabled": true,
"prefetchTopK": 5,
"compactTakeoverEnabled": true,
"summaryMaxChars": 4000,
"shortTermIndexMode": "sync"
}
}
}
}
}
Local Mode
Use local when the OpenClaw gateway should start AGFS and ContextEngine.
{
"plugins": {
"slots": {
"contextEngine": "og-memory-context-engine"
},
"entries": {
"og-memory-context-engine": {
"enabled": true,
"config": {
"mode": "local",
"projectRoot": "/path/to/oG-Memory",
"agfsServerDir": "/path/to/oG-Memory/agfs",
"agfsDataDir": "/path/to/ogmem-data",
"contextEnginePort": 8090,
"llmProvider": "openai",
"llmApiKey": "sk-...",
"llmBaseUrl": "https://api.openai.com/v1",
"llmModel": "gpt-4o-mini"
}
}
}
}
}
Restart OpenClaw after changing the config.
openclaw restart
How It Works
OpenClaw gateway
|
| lifecycle call
v
openclaw_context_engine_plugin/index.js
|
| HTTP
v
oG-Memory /api/v1/{prefetch,compose,after_turn,prepare_compaction,compact,dispose}
Main lifecycle behavior:
| OpenClaw method | oG-Memory calls | Behavior |
|---|---|---|
assemble() |
optional /prefetch, then /compose |
Stages quick retrieval hits, then returns layered messages for Profile, Archive History, Session State, and Working Set. |
afterTurn() |
/after_turn |
Sends completed turn messages for incremental extraction and persistence. |
compact() |
/prepare_compaction, then /compact when takeover is enabled |
Runs pre-compaction extraction, validates a one-time prepare token, commits/archive synchronously, and returns a compact summary. |
dispose() |
/dispose |
Releases session resources and lets oG-Memory persist session state. |
compactTakeoverEnabled=false keeps OpenClaw responsible for final compact generation, but the plugin still calls prepare_compaction so oG-Memory can extract the delta before OpenClaw compacts the local transcript.
Project Structure
openclaw_context_engine_plugin/
├── index.js # Plugin entry, config resolver, HTTP bridge, lifecycle handlers
├── compaction-boundary.js # Persists OpenClaw compaction boundary entries during takeover
├── process.js # Local-mode health checks, port probing, process helpers
├── compact.test.js # Node tests for config, prefetch, and compact takeover behavior
├── openclaw.plugin.json # Plugin manifest and config schema
├── package.json
├── ENV.md # Environment variable reference
└── README.md
Verify
openclaw doctor
node openclaw_context_engine_plugin/compact.test.js
For a remote service, also verify oG-Memory directly:
curl http://127.0.0.1:8090/api/v1/health
Gateway logs should show [og-memory] lines for compose, after_turn, and compact control flow.
Switching Back
To revert to the built-in context engine:
{
"plugins": {
"slots": {
"contextEngine": "legacy"
}
}
}
Then restart the gateway.