mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 03:04:28 +00:00
Remove duplicate Custom Compaction example, reference main docs
This commit is contained in:
parent
705ba5d4f2
commit
43add86ebf
1 changed files with 2 additions and 28 deletions
|
|
@ -713,35 +713,9 @@ export default function (pi: HookAPI) {
|
||||||
|
|
||||||
### Custom Compaction
|
### Custom Compaction
|
||||||
|
|
||||||
Use a cheaper model for summarization, or implement your own compaction strategy.
|
Use a different model for summarization, or implement your own compaction strategy.
|
||||||
|
|
||||||
```typescript
|
See [examples/hooks/custom-compaction.ts](../examples/hooks/custom-compaction.ts) and the [Custom Compaction](#custom-compaction) section above for details.
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
|
||||||
import type { CompactionEntry } from "@mariozechner/pi-coding-agent";
|
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
|
||||||
pi.on("session", async (event, ctx) => {
|
|
||||||
if (event.reason !== "before_compact") return;
|
|
||||||
|
|
||||||
// Example: Use a simpler summarization approach
|
|
||||||
const messages = event.messagesToSummarize;
|
|
||||||
const summary = messages
|
|
||||||
.filter((m) => m.role === "user")
|
|
||||||
.map((m) => `- ${typeof m.content === "string" ? m.content.slice(0, 100) : "[complex]"}`)
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
const compactionEntry: CompactionEntry = {
|
|
||||||
type: "compaction",
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
summary: `User requests:\n${summary}`,
|
|
||||||
firstKeptEntryIndex: event.cutPoint.firstKeptEntryIndex,
|
|
||||||
tokensBefore: event.tokensBefore,
|
|
||||||
};
|
|
||||||
|
|
||||||
return { compactionEntry };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Mode Behavior
|
## Mode Behavior
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue