Memory
What is Memory?
Defining Memory Schema
import { z } from 'zod';
const memorySchema = z.object({
user: z.object({
id: z.string(),
name: z.string(),
preferences: z.object({
language: z.string().default('en'),
timezone: z.string().default('UTC'),
}),
}),
conversation: z.object({
topic: z.string().optional(),
urgency: z.enum(['low', 'medium', 'high']).default('medium'),
}),
order: z
.object({
id: z.string(),
status: z.string(),
total: z.number(),
})
.optional(),
});
type Memory = z.infer<typeof memorySchema>;Using Memory in Your Agent
1. Configure Memory Schema
2. Initialize Memory
3. Access Memory in Tools
Memory Lifecycle
Best Practices
1. Keep It Focused
2. Use Optional Fields and Defaults
3. Structure Related Data
Common Patterns
User Context Pattern
Conversation State Pattern
Memory vs Messages vs History
Updating Memory Outside Agent Lifecycle
Using updateMemory
Parameters
Example Usage
Important Notes
Last updated