AI SDK
Using Recall with the AI SDK framework
This guide shows you how to integrate the Recall Agent Toolkit with Vercel's AI SDK to build web applications with Recall-powered agents.
Overview
Vercel's AI SDK is a powerful toolkit for building AI-powered applications, especially in Next.js applications. It provides components and utilities for building user interfaces that interact with AI models.
By integrating Recall Agent Toolkit with the AI SDK, you can:
- Build Next.js and React applications with Recall-powered AI functionality
- Create UI components that interact with Recall storage
- Implement streaming responses for better UX
- Enable tool usage for AI agents directly in your web app
- Handle multi-turn conversations with persistent memory
Installation
Basic integration
Here's how to integrate Recall with the AI SDK in a Next.js application:
And the client-side React component:
This basic example sets up a chat interface that can use Recall for storage via tools.
Function calling
For more advanced implementations, you'll need to handle function calls properly. Here's how to do that:
Memory management
For maintaining conversation context across sessions:
Next.js App Router integration
For a more complete Next.js application with the App Router:
Recall Agent Toolkit setup
A common pattern is to centralize your Recall toolkit setup:
Best practices
When integrating Recall with the AI SDK, follow these best practices:
-
Server-side execution: Always run Recall tools on the server side to protect your private key
-
Error handling: Implement robust error handling for tool calls and API requests
-
Loading states: Show appropriate loading states during tool execution for better UX
-
Streaming responses: Use streaming for better user experience
-
Environment variables: Keep sensitive keys in environment variables
-
Middleware for debugging: Use middleware to log tool calls during development:
-
Route protection: Add authentication to protect your API routes if needed
Troubleshooting
Issue | Possible cause | Solution |
---|---|---|
"Private key not found" | Missing environment variable | Ensure RECALL_PRIVATE_KEY is set in .env.local |
"Cannot read properties of undefined" | Incorrect tool usage | Verify tool parameters match expected schema |
"Error: ECONNREFUSED" | Network issue or API service down | Check internet connection and API status |
Slow responses | Complex tool operations | Implement proper loading states in UI |
"Function not found" | Incorrect tool name | Ensure tool names match exactly |
AI SDK helper components
The AI SDK provides several useful React components and hooks:
useChat
: Main hook for chat functionalityuseCompletion
: Hook for single-turn completionsMessage
: Type for chat messagesStreamingTextResponse
: Class for streaming responses
Here's how to use them effectively:
Advanced Vercel AI SDK features
Vercel's AI SDK offers advanced features for production applications:
-
Rate limiting: Add rate limiting to prevent abuse
-
Caching: Cache responses for similar queries
-
Feedback collection: Add feedback mechanisms to improve your model
Next steps
- Explore the core concepts to better understand the Recall capabilities
- Learn about bucket monitoring to track agent activity
- Check out the MCP integration guide for a different approach
- See the tools reference for detailed documentation of available tools
The Vercel AI SDK is regularly updated with new features. Check the official documentation for the latest updates.