agentskit.js
Memory

createAutoSummarizingMemory

Fold oldest messages into a running summary. Token-budget-friendly.

import { createAutoSummarizingMemory } from '@agentskit/core/auto-summarize'
import { createInMemoryMemory } from '@agentskit/core'
import { createRuntime } from '@agentskit/runtime'

const summaryRuntime = createRuntime({
  adapter,
  systemPrompt: 'Summarize the following chat transcript in 3 bullet points.',
  maxTokens: 512,
})

const memory = createAutoSummarizingMemory(createInMemoryMemory(), {
  maxTokens: 8_000,
  keepRecent: 6,
  summarizer: async (msgs) => {
    const src = msgs.map(m => `${m.role}: ${m.content}`).join('\n')
    const result = await summaryRuntime.run(src)
    return {
      id: crypto.randomUUID(),
      role: 'system',
      content: result.content,
      status: 'complete',
      createdAt: new Date(),
    }
  },
})

createAutoSummarizingMemory is not exported from @agentskit/memory. Import it from @agentskit/core/auto-summarize and pass a backing ChatMemory as the first argument.

#Options

OptionDefaultPurpose
maxTokensrequiredBudget trigger
summarizerrequired(messages) => Message β€” your compaction prompt
keepRecent4Messages always kept verbatim at the tail

Explore nearby

✎ Edit this page on GitHubΒ·Found a problem? Open an issue β†’Β·How to contribute β†’

On this page

Ask the docs
Ask anything about AgentsKit. Answers come from the docs corpus and cite their sources.