Introducing Memory v2: Scoped Persistent Context

Person working on laptop at a wooden desk.

Aïda Renault

6 min read

Introducing Memory v2: Scoped Persistent Context

Agents are stateless by default. Every run starts from zero. Your agent greets the same user like a stranger every time.

Memory v2 changes this. Agents now remember per-user context, per-session state, and long-term knowledge — out of the box, with no external database required.

The problem with memory v1

Our first memory implementation was a single flat key-value store per agent. It worked for simple cases but fell apart at scale. Every user's context was mixed together. Session boundaries were unclear. There was no way to scope memory to a specific conversation without manual key management.

Teams ended up building their own memory layer on top of ours, which defeated the purpose.

How v2 works

Memory v2 introduces three scopes:

User memory. Persists across all sessions for a specific user. Stores preferences, history, and accumulated knowledge. When your agent remembers that a user prefers concise responses or that their company uses PostgreSQL — that is user memory.

Session memory. Persists within a single conversation. Stores the running context, previous tool results, and decisions made so far. When a user says refer to the invoice from earlier in this conversation — that is session memory.

Agent memory. Shared across all users and sessions. Stores learned patterns, frequently-used data, and cached tool results. When your agent knows that the Stripe API returns paginated results and pre-fetches accordingly — that is agent memory.

Automatic context management

Memory v2 handles context window management automatically. As conversations grow, older messages are compressed into running summaries. The agent always has the most relevant context within its token budget.

Vector search runs across all three scopes. When the agent needs to recall something, it queries user memory, session memory, and agent memory simultaneously and merges the results by relevance.

Configuration

Memory v2 works with zero configuration. Enable it with one line:

const agent = new Agent({
  memory: true
})
const agent = new Agent({
  memory: true
})
const agent = new Agent({
  memory: true
})

For fine-grained control, you can configure TTL, encryption, storage backends, and scope priorities:

memory:
  user:
    ttl: 90d
    encrypt: true
  session:
    ttl: 24h
  agent:
    ttl: forever
    backend: redis
memory:
  user:
    ttl: 90d
    encrypt: true
  session:
    ttl: 24h
  agent:
    ttl: forever
    backend: redis
memory:
  user:
    ttl: 90d
    encrypt: true
  session:
    ttl: 24h
  agent:
    ttl: forever
    backend: redis

Migration

If you are on Memory v1, the migration is automatic. Your existing key-value pairs are moved into the agent memory scope. No data is lost. No code changes required.

Related articles

Related articles

Usage-based pricing that scales with you.

Usage-based pricing that scales with you.

Start free, pay for what runs. No seats, no platform fees, no surprise overages — just runs, tokens, and the tools you actually use.

Start free, pay for what runs. No seats, no platform fees, no surprise overages — just runs, tokens, and the tools you actually use.

Start free, pay for what runs. No seats, no platform fees, no surprise overages — just runs, tokens, and the tools you actually use.

Start free, pay for what runs. No seats, no platform fees, no surprise overages — just runs, tokens, and the tools you actually use.

The framework for building, deploying, and observing production AI agents. Made in Berlin, shipped globally.

© AgentKit Inc.
Berlin — 2026

The framework for building, deploying, and observing production AI agents. Made in Berlin, shipped globally.

© AgentKit Inc.
Berlin — 2026

The framework for building, deploying, and observing production AI agents. Made in Berlin, shipped globally.

© AgentKit Inc.
Berlin — 2026

Create a free website with Framer, the website builder loved by startups, designers and agencies.