Vercel AI SDK AgentKit Extension
Introduction to Vercel AI SDK
Vercel AI SDK is a library for building AI-powered applications with React and JavaScript/TypeScript. It provides a set of tools and utilities that make it easy to build applications that use AI models, including:
- Streaming responses from AI models
- Managing AI model state
- Building chat interfaces
- Handling tool usage by AI models
This extension allows you to easily integrate AgentKit’s onchain capabilities with Vercel AI SDK, enabling you to build web applications with AI agents that can interact with blockchain networks and a crypto wallet.
Why Use Vercel AI SDK with AgentKit
Vercel AI SDK is particularly well-suited for building web applications with AI capabilities. When combined with AgentKit, it enables you to:
- Build web-based AI agents: Create web applications with AI agents that can interact onchain
- Stream AI responses: Provide a better user experience with streaming responses from AI models
- Leverage React components: Use Vercel AI SDK’s React components to build chat interfaces
- Deploy on Vercel: Easily deploy your application on Vercel’s platform
Installation
For a single command to install all necessary dependencies, run:
To break it down, this package is:
This package is used alongside AgentKit and AI SDK, so these will need to be installed as well.
Finally, install the model provider you want to use. For example, to use OpenAI, install the @ai-sdk/openai
package. See here for a list of supported model providers.
Basic Usage
The main export of this package is the getVercelAITools
function. This function takes an AgentKit instance and returns an object containing the tools for the AgentKit agent. This object can then be passed to AI SDK.
Here’s a snippet of code that shows how to use the getVercelAITools
function to get the tools for the AgentKit agent.
chatbot.ts
For a full example, see the AgentKit AI SDK Chatbot Example.
Using Different Model Providers
Vercel AI SDK supports multiple model providers. Here’s how to use different providers:
Troubleshooting
Common Issues
Tool Execution Errors
If you encounter errors during tool execution, check the following:
- Ensure your CDP API keys are correctly set in environment variables
- Verify that the network you’re using is supported by the action provider
- Check that you have sufficient funds for any transactions
Model Provider Issues
If you’re having issues with the model provider:
- Ensure you have the correct API key set for your model provider
- Check that you’re using a model that supports tool usage
- Verify that you’ve installed the correct model provider package
Debugging Tips
- Set
debug: true
in the options forgetVercelAITools
to see more detailed logs - Use the
maxSteps
parameter to limit the number of tool calls the model can make - Check the network tab in your browser’s developer tools to see the requests being made