Update custom-compaction example to use serializeConversation

Also fix docs to show convertToLlm is needed first.
This commit is contained in:
Mario Zechner 2025-12-31 13:24:23 +01:00
parent 75269add96
commit 027d39aa33
2 changed files with 14 additions and 9 deletions

View file

@ -303,13 +303,15 @@ pi.on("session_before_compact", async (event, ctx) => {
To generate a summary with your own model, convert messages to text using `serializeConversation`:
```typescript
import { serializeConversation } from "@mariozechner/pi-coding-agent";
import { convertToLlm, serializeConversation } from "@mariozechner/pi-coding-agent";
pi.on("session_before_compact", async (event, ctx) => {
const { preparation } = event;
// Convert messages to readable text format
const conversationText = serializeConversation(preparation.messagesToSummarize);
// Convert AgentMessage[] to Message[], then serialize to text
const conversationText = serializeConversation(
convertToLlm(preparation.messagesToSummarize)
);
// Returns:
// [User]: message text
// [Assistant thinking]: thinking content