Skip to main content

Agent Memory

Memory enables agents to remember past interactions and maintain conversation context. This guide shows how to configure memory for your agents.

Default Behavior

Agents automatically use in-memory storage by default, storing conversations in application memory:

import { Agent } from "@voltagent/core";
import { openai } from "@ai-sdk/openai";

const agent = new Agent({
name: "Assistant",
instructions: "You are a helpful assistant",
model: openai("gpt-4o"),
// Memory is automatically enabled with in-memory storage
});

Using Memory

To maintain conversation context, provide userId and conversationId:

// First message
const response1 = await agent.generateText("My name is Sarah", {
userId: "user-123",
conversationId: "chat-001",
});

// Follow-up message - agent remembers the name
const response2 = await agent.generateText("What's my name?", {
userId: "user-123",
conversationId: "chat-001", // Same conversation ID
});
console.log(response2.text); // "Your name is Sarah"

Persistent Storage

For conversations that survive application restarts, configure Memory with a persistent adapter such as LibSQL:

import { Agent, Memory } from "@voltagent/core";
import { LibSQLMemoryAdapter } from "@voltagent/libsql"; // npm install @voltagent/libsql
import { openai } from "@ai-sdk/openai";

const agent = new Agent({
name: "Persistent Assistant",
instructions: "You are a helpful assistant",
model: openai("gpt-4o"),
memory: new Memory({
storage: new LibSQLMemoryAdapter({ url: "file:./.voltagent/memory.db" }),
}),
});

Disabling Memory

For stateless agents that don't need conversation history:

const agent = new Agent({
name: "Stateless Assistant",
instructions: "You provide one-off responses",
model: openai("gpt-4o"),
memory: false, // Disable memory completely
});

Available Memory Providers

Learn More

For detailed information about memory configuration, providers, and advanced usage:

Table of Contents