Overview
Satori provides first-class integration with the Vercel AI SDK through the@usesatori/tools package. This guide covers everything from basic setup to advanced patterns.
Installation
Basic Integration
Step 1: Create Memory Tools
ThememoryTools() function creates AI SDK-compatible tools that the LLM can use to manage memories:
Step 2: Pre-fetch Memory Context
Fetch relevant memories before calling the LLM:Step 3: Stream with Memory
UsestreamText() with memory tools and context:
Complete API Route Example
Here’s a full Next.js API route with memory:app/api/chat/route.ts
Available Tools
ThememoryTools() function provides two tools:
add_item
Saves information to memory. The LLM calls this automatically when it detects important information.The information to save. Should be a complete, self-contained statement.
Optional metadata for categorization:
delete_memory
Removes a specific memory by ID.The UUID of the memory to delete. The LLM can get this from the context.
Advanced Patterns
Pattern 1: Conditional Context Injection
Only inject context when relevant:Pattern 2: Category-Based Memory
Use metadata to organize memories by category:Pattern 3: Streaming with Tool Call Feedback
Show users when memories are being saved:Pattern 4: Multi-Step Reasoning
Allow the LLM to search before responding:Error Handling
Handle errors gracefully in production:Testing
Test your memory integration:Performance Optimization
Cache embeddings for common queries
Cache embeddings for common queries
Parallel context fetching
Parallel context fetching
Limit context size
Limit context size
Next Steps
Direct Client
Use MemoryClient for custom integrations
Next.js Integration
Build a complete Next.js app with memory
API Reference
Explore the complete API
Examples
See complete implementations