feat: expose context-engine compaction delegate helper (#49061)

* ContextEngine: add runtime compaction delegate helper

* plugin-sdk: expose compaction delegate through compat

* docs: clarify delegated plugin compaction

* docs: use scoped compaction delegate import
This commit is contained in:
Josh Lehman
2026-03-17 22:54:18 -07:00
committed by GitHub
parent 937f118d8e
commit 7f0f8dd268
15 changed files with 213 additions and 50 deletions

View File

@@ -1810,6 +1810,36 @@ export default function (api) {
}
```
If your engine does **not** own the compaction algorithm, keep `compact()`
implemented and delegate it explicitly:
```ts
import { delegateCompactionToRuntime } from "openclaw/plugin-sdk/core";
export default function (api) {
api.registerContextEngine("my-memory-engine", () => ({
info: {
id: "my-memory-engine",
name: "My Memory Engine",
ownsCompaction: false,
},
async ingest() {
return { ingested: true };
},
async assemble({ messages }) {
return { messages, estimatedTokens: 0 };
},
async compact(params) {
return await delegateCompactionToRuntime(params);
},
}));
}
```
`ownsCompaction: false` does not automatically fall back to legacy compaction.
If your engine is active, its `compact()` method still handles `/compact` and
overflow recovery.
Then enable it in config:
```json5