Skip to main content

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

The memoryTools() 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

Use streamText() with memory tools and context:

Complete API Route Example

Here’s a full Next.js API route with memory:
app/api/chat/route.ts
Set maxSteps: 5 to allow the LLM to make multiple tool calls in a single response (e.g., search and then save).

Available Tools

The memoryTools() function provides two tools:

add_item

Saves information to memory. The LLM calls this automatically when it detects important information.
memory
string
required
The information to save. Should be a complete, self-contained statement.
metadata
object
Optional metadata for categorization:

delete_memory

Removes a specific memory by ID.
memoryId
string
required
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:
This pattern is less reliable than pre-fetching context. The LLM may not always call search_memory when needed.

Error Handling

Handle errors gracefully in production:

Testing

Test your memory integration:

Performance Optimization

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