@coinbase/agentkit-vercel-ai-sdk

Coinbase Agentkit Extension - Vercel AI SDK

This package is an extension used to easily plug AgentKit into AI SDK by Vercel.

For a single command to install all necessary dependencies, run:

npm install @coinbase/agentkit-vercel-ai-sdk @coinbase/agentkit ai @ai-sdk/openai

To break it down, this package is:

npm install @coinbase/agentkit-vercel-ai-sdk

This package is used alongside AgentKit and AI SDK, so these will need to be installed as well.

npm install @coinbase/agentkit ai

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.

npm install @ai-sdk/openai

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.

import { getVercelAITools } from "@coinbase/agentkit-vercel-ai-sdk";
import { AgentKit } from "@coinbase/agentkit";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

// Get your Coinbase Developer Platform API key from the Portal: https://portal.cdp.coinbase.com/
// Or, check out one of the other supported wallet providers: https://github.com/coinbase/agentkit/tree/main/typescript/agentkit
const agentKit = await AgentKit.from({
cdpApiKeyName: process.env.CDP_API_KEY_NAME,
cdpApiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
});

const tools = await getVercelAITools(agentKit);

// There are multiple methods to generate text with AI SDK.
// See here for more information: https://sdk.vercel.ai/docs/ai-sdk-core/generating-text
const { text } = await generateText({
model: openai("gpt-4o-mini"), // Make sure to have OPENAI_API_KEY set in your environment variables
system: "You are an onchain AI assistant with access to a wallet.",
prompt: "Print wallet details",
tools,
// Allow multi-step tool usage
// See: https://sdk.vercel.ai/docs/foundations/agents#multi-step-tool-usage
maxSteps: 10,
});

console.log(text);

For a full example, see the AgentKit AI SDK Chatbot Example.

We welcome contributions of all kinds! Please see our Contributing Guide for detailed setup instructions and contribution guidelines.