agentskit.js
Memory

createVirtualizedMemory

Hot-window + cold retriever. Keep recent messages; retrieve old ones on demand.

import { createInMemoryMemory, createVirtualizedMemory } from '@agentskit/core'

const backing = createInMemoryMemory()
const memory = createVirtualizedMemory(backing, {
  maxActive: 50,
  maxRetrieved: 5,
  retriever: async ({ hot, cold, maxRetrieved }) => {
    // return up to maxRetrieved older messages to splice back in
    return cold.slice(-maxRetrieved)
  },
})

createVirtualizedMemory ships in @agentskit/core, not @agentskit/memory. The first argument is the backing ChatMemory.

#Options

OptionDefaultPurpose
maxActive50Recent messages always loaded
retrieverβ€”( { hot, cold, maxRetrieved } ) => Message[] β€” optional cold lookup
maxRetrieved10Cap on retrieved cold messages

#When to use

Long-running sessions where most context is stale but some old turns matter. Cheaper than always-on full history.

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.