Crux
GuidesCompaction

Summarize messages

One-shot stateless summarization of a message array. Pure function, no state.

summarizeMessages() is a pure function: pass in messages, get back a summary string and stats. No store, no eviction, no policy: useful when you have a bounded batch of messages and want one summary right now.

What problem does this solve?

Sometimes you don't want a stateful, automatic compaction pipeline. You have a finished conversation, a closed thread, or a one-off batch, and you need a summary you can store, log, or feed to another prompt. summarizeMessages() is the smallest unit that does that.

When should I use it?

  • You have a bounded batch of messages and want one summary
  • You're processing a finished conversation (e.g. for archival or a digest email)
  • You want to manually compact at a moment of your choosing: no auto-eviction

When should I NOT use it?

Quick start

summarize.ts
import { summarizeMessages } from "@use-crux/core/compaction";
import { generateTextFn } from "@use-crux/ai";

const result = await summarizeMessages({
  messages: conversationHistory,
  generate: generateTextFn,
  model: cheapModel,
  maxTokens: 500,
  focus: ["decisions", "action-items"],
});

result.summary; // string
result.tokensBefore; // original token count
result.tokensAfter; // summary token count
result.ratio; // compression ratio (e.g. 0.15 = 85% reduction)

Steering with focus

The focus parameter is an array of topic keywords. The summarizer prioritizes information related to those topics:

focus: ["decisions", "action-items"]; // project conversations
focus: ["user-preferences", "questions"]; // support conversations
focus: ["blockers", "risks"]; // status updates

Common values: decisions, action-items, questions, agreements, blockers, risks, user-preferences, open-questions.

You can also pass a system override to the summarizer for full control:

await summarizeMessages({
  messages,
  generate: generateTextFn,
  model: cheapModel,
  system:
    "You are summarizing a customer support conversation. Preserve customer concerns verbatim.",
});

Where to next

On this page