Caricamento in corso...
Caricamento in corso...
Last synced: Today, 22:00
Technical reference for the OpenClaw framework. Real-time synchronization with the official documentation engine.
Use this file to discover all available pages before exploring further.
A context engine controls how OpenClaw builds model context for each run: which messages to include, how to summarize older history, and how to manage context across subagent boundaries.
OpenClaw ships with a built-in
legacytext<Tabs> <Tab title="From npm"> ```bash} openclaw plugins install @martian-engineering/lossless-claw ``` </Tab> <Tab title="From a local path"> ```bash} openclaw plugins install -l ./my-context-engine ``` </Tab> </Tabs>
textRestart the gateway after installing and configuring.
Every time OpenClaw runs a model prompt, the context engine participates at four lifecycle points:
For the bundled non-ACP Codex harness, OpenClaw applies the same lifecycle by projecting assembled context into Codex developer instructions and the current turn prompt. Codex still owns its native thread history and native compactor.
OpenClaw calls two optional subagent lifecycle hooks:
The
assemblesystemPromptAdditionThe built-in
legacyThe legacy engine does not register tools or provide a
systemPromptAdditionWhen no
plugins.slots.contextEngine"legacy"A plugin can register a context engine using the plugin API:
tsimport { buildMemorySystemPromptAddition } from "openclaw/plugin-sdk/core"; export default function register(api) { api.registerContextEngine("my-engine", (ctx) => ({ info: { id: "my-engine", name: "My Context Engine", ownsCompaction: true, }, async ingest({ sessionId, message, isHeartbeat }) { // Store the message in your data store return { ingested: true }; }, async assemble({ sessionId, messages, tokenBudget, availableTools, citationsMode }) { // Return messages that fit the budget return { messages: buildContext(messages, tokenBudget), estimatedTokens: countTokens(messages), systemPromptAddition: buildMemorySystemPromptAddition({ availableTools: availableTools ?? new Set(), citationsMode, }), }; }, async compact({ sessionId, force }) { // Summarize older context return { ok: true, compacted: true }; }, })); }
The factory
ctxconfigagentDirworkspaceDirThen enable it in config:
json5{ plugins: { slots: { contextEngine: "my-engine", }, entries: { "my-engine": { enabled: true, }, }, }, }
Required members:
| Member | Kind | Purpose |
|---|---|---|
text info | Property | Engine id, name, version, and whether it owns compaction |
text ingest(params) | Method | Store a single message |
text assemble(params) | Method | Build context for a model run (returns text AssembleResult |
text compact(params) | Method | Summarize/reduce context |
assembleAssembleResultcompactCompactResultresult.sessionIdresult.sessionFileOptional members:
| Member | Kind | Purpose |
|---|---|---|
text bootstrap(params) | Method | Initialize engine state for a session. Called once when the engine first sees a session (e.g., import history). |
text ingestBatch(params) | Method | Ingest a completed turn as a batch. Called after a run completes, with all messages from that turn at once. |
text afterTurn(params) | Method | Post-run lifecycle work (persist state, trigger background compaction). |
text prepareSubagentSpawn(params) | Method | Set up shared state for a child session before it starts. |
text onSubagentEnded(params) | Method | Clean up after a subagent ends. |
text dispose() | Method | Release resources. Called during gateway shutdown or plugin reload — not per-session. |
ownsCompactionThat means there are two valid plugin patterns:
A no-op
compact()/compactjson5{ plugins: { slots: { // Select the active context engine. Default: "legacy". // Set to a plugin id to use a plugin engine. contextEngine: "legacy", }, }, }
openclaw doctorplugins.slots.contextEngine"legacy"openclaw plugins install -l ./my-engine© 2024 TaskFlow Mirror
Powered by TaskFlow Sync Engine