Skip to main content
AgentKit integrates with LangChain, giving your LangChain agent a set of onchain tools it can call to interact with Base. This page covers the setup for both TypeScript and Python.

Prerequisites

  • Node 18+ (TypeScript) or Python 3.10+ (Python)
  • A CDP API key
  • An OpenAI API key (or any LangChain-compatible LLM)

Quickstart

1

Install dependencies

Terminal
npm install @coinbase/agentkit-langchain @coinbase/agentkit @langchain/langgraph @langchain/openai
2

Clone the example

Terminal
git clone https://github.com/coinbase/agentkit.git
cd agentkit/typescript
npm install && npm run build
cd examples/langchain-cdp-chatbot
3

Configure environment variables

Terminal
cp .env.local .env
.env
CDP_API_KEY_NAME=your_cdp_key_name
CDP_API_KEY_PRIVATE_KEY=your_cdp_private_key
OPENAI_API_KEY=your_openai_key
NETWORK_ID=base-sepolia
4

Run the agent

Terminal
npm run start

How it works

AgentKit provides a set of LangChain-compatible tools. You pass them to a LangChain agent executor, which decides which tools to call based on the user’s prompt.
chatbot.ts
import { AgentKit } from "@coinbase/agentkit";
import { getLangChainTools } from "@coinbase/agentkit-langchain";
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

// Initialize AgentKit — reads CDP_API_KEY_NAME and CDP_API_KEY_PRIVATE_KEY from env
const agentKit = await AgentKit.from({
  cdpApiKeyName: process.env.CDP_API_KEY_NAME,
  cdpApiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
});

// Get AgentKit tools as LangChain tools
const tools = await getLangChainTools(agentKit);

// Create a LangChain agent
const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
const agent = createReactAgent({ llm, tools });

// Run the agent
const result = await agent.invoke({
  messages: [{ role: "user", content: "What is my wallet address?" }],
});

console.log(result.messages.at(-1)?.content);

Adding custom tools

Combine AgentKit tools with your own LangChain tools:
import { tool } from "@langchain/core/tools";
import { z } from "zod";

const myTool = tool(
  async ({ query }) => {
    return `Result for: ${query}`;
  },
  {
    name: "my_custom_tool",
    description: "Does something custom",
    schema: z.object({ query: z.string() }),
  }
);

const allTools = [...(await getLangChainTools(agentKit)), myTool];
const agent = createReactAgent({ llm, tools: allTools });

Run on Replit

Fork a pre-configured template to start without local setup:
Replit templates store wallet data in wallet_data.txt. This file contains your wallet’s private key and should not be used in production. See CDP docs on securing wallets.

Next steps

Wallet setup

Configure a production-ready CDP wallet for your LangChain agent.

x402 payments

Add per-request stablecoin payments to your agent.