WindowedConversationSummarizer

Default summarizer for chat history

Overview

Summarizes conversations after a fixed number of messages to keep the context window bounded.

Type Definition

import type { SummarizationOptions, SummarizerInput, SummaryUpdate } from 'peam/server';

export declare class WindowedConversationSummarizer {
  constructor(options: SummarizationOptions);
  summarize(input: SummarizerInput): Promise<SummaryUpdate | null>;
}

Usage

Create a summarizer and pass it to the chat runtime with createChat:

import { createChat, WindowedConversationSummarizer } from 'peam/server';
import { openai } from '@ai-sdk/openai';

const summarizer = new WindowedConversationSummarizer({
  model: openai('gpt-4o'),
  maxMessages: 12,
});

export const POST = createChat({
  summarizer,
}).handler;

You can also pass summarization options directly and let createChat construct it:

import { createChat } from 'peam/server';
import { openai } from '@ai-sdk/openai';

export const POST = createChat({
  summarization: {
    model: openai('gpt-4o'),
    maxMessages: 12,
  },
}).handler;

Notes

  • Uses maxMessages with a default of 10.
  • Used automatically by DefaultChatRuntime unless summarization is set to false.

On this page

GitHubEdit this page on GitHub