Getting Started with AgentKit on Flow
AgentKit is an ecosystem-agnostic modular developer toolkit that lets you rapidly build, deploy, and iterate on AI agents using pre-configured environments and ready-to-use templates.
In this guide, you'll set up your own custom agent running on Flow's EVM-compatible testnet, powered by Langchain and Anthropic's Claude LLM.
Quickstart - Starting From Scratch
Open your terminal and run:
_10npm create onchain-agent@latest
Follow the interactive setup:
- Type
y
to proceed, then press Enter. - Select your framework: Langchain
- Choose your network: EVM
- Set the custom Chain ID:
545
for Flow Testnet747
for Flow Mainnet
- JSON-RPC endpoint:
_10https://testnet.evm.nodes.onflow.org
Project Setup
Once your scaffold is ready:
_10cd onchain-agent_10npm install
Now open the project in your preferred IDE (e.g. Cursor).
Environment Configuration
- Create a
.env.local
file (or edit the one generated). - Add your API keys (we'll use Anthropic here).
You can also use OpenAI, DeepSeek, or any other supported LLM.
Get Your Anthropic API Key
- Head to Anthropic Console
- Create an account and purchase credits
- Click Create Key, name it, and copy the API key
- Add this to your
.env.local
:
_10ANTHROPIC_API_KEY=your_api_key_here
Wallet Setup with MetaMask
- Add Flow Testnet to MetaMask
- Use the Faucet to fund your wallet
- Get your private key:
- Click the
...
menu in MetaMask > Account Details - Enter your password, copy the private key
- Click the
- Add it to
.env.local
:
_10PRIVATE_KEY=your_private_key_here
Your .env.local
should look something like this:
_10PRIVATE_KEY=..._10ANTHROPIC_API_KEY=...
Now run:
_10mv .env.local .env_10npm run dev
Visit your local server:
_10http://localhost:3000
Configure Your LLM
If your agent doesn't respond yet — no worries! You still need to configure your LLM and client libraries.
Choose a Model
Langchain supports many LLMs (full list here).
For this example, we'll use Anthropic's claude-3-5-haiku-20241022
, a lightweight and affordable model. Alternatively, DeepSeek is highly recommended for budget-friendly usage.
Update create-agent.ts
Change the default model from OpenAI:
_10const llm = new ChatOpenAI({ model: 'gpt-4o-mini' });
To Anthropic:
_10import { ChatAnthropic } from '@langchain/anthropic';_10_10const llm = new ChatAnthropic({ model: 'claude-3-5-haiku-20241022' });
Install the package:
_10npm install @langchain/anthropic
Configure Flow and Viem Wallet
Update the Faucet Provider Logic
Change this:
_10const canUseFaucet = walletProvider.getNetwork().networkId == 'base-sepolia';
To:
_10const canUseFaucet = walletProvider.getNetwork().networkId == 'flow-testnet';
Add Flow Context Message to Agent
This gives your agent context about the Flow testnet:
_16const flowContextMessage = canUseFaucet_16 ? `_16 You are now operating on the Flow blockchain testnet using a Viem wallet. Flow is a fast, decentralized, and_16 developer-friendly blockchain designed for NFTs, games, and apps. _16_16 Key facts about Flow:_16 - Flow uses a proof-of-stake consensus mechanism_16 - The native token is FLOW_16 - Flow has a unique multi-role architecture for high throughput_16 - The testnet is EVM-compatible (works with MetaMask + Viem)_16 - RPC URL: https://testnet.evm.nodes.onflow.org_16 - Chain ID: 545_16_16 Your wallet address is \${await walletProvider.getAddress()}._16`_16 : '';
Then inject it into the agent message modifier:
_16agent = createReactAgent({_16 llm,_16 tools,_16 checkpointSaver: memory,_16 messageModifier: `_16 You are a helpful agent interacting with the Flow blockchain testnet using a Viem wallet._16 Flow testnet supports EVM, so you can use Ethereum-compatible tools._16 \${flowContextMessage}_16_16 Before your first action, check the wallet details. If you see a 5XX error, ask the user to try again later._16 If a task is unsupported, let the user know and point them to CDP SDK + AgentKit at:_16 https://docs.cdp.coinbase.com or https://developers.flow.com._16_16 Be concise, helpful, and avoid repeating tool descriptions unless asked._16 `,_16});
You're Done!
You now have a working AI agent connected to Flow testnet using AgentKit!
You can send faucet tokens to your wallet and start testing smart contract interactions or on-chain workflows.
Starter Project
Want to skip the setup?
This starter includes all necessary config to start building immediately on Flow.
Adding AgentKit to an Existing Project
Already have a project and want to add AgentKit? Follow these steps to integrate it into your existing codebase:
Install the Package
Run this command in your project's root directory:
_10npm install onchain-agent@latest
This will:
- Download and install the latest version of the
onchain-agent
package - Add it to the dependencies section of your
package.json
- Update your
node_modules
folder accordingly
Configure Environment
- Create or update your
.env
file with the necessary API keys:
_10PRIVATE_KEY=your_wallet_private_key_10ANTHROPIC_API_KEY=your_anthropic_api_key_10# Or other LLM API keys
- Configure your RPC endpoints for Flow:
_10FLOW_TESTNET_RPC_URL=https://testnet.evm.nodes.onflow.org_10FLOW_MAINNET_RPC_URL=https://mainnet.evm.nodes.onflow.org
Integrate AgentKit in Your Code
Import and configure AgentKit in your application:
_28// Import AgentKit components_28import { createReactAgent, ChatAnthropic } from 'onchain-agent';_28import { createWalletClient, http, createPublicClient } from 'viem';_28_28// Set up your Flow wallet provider_28const walletClient = createWalletClient({_28 transport: http('https://testnet.evm.nodes.onflow.org'),_28 chain: {_28 id: 545, // Flow Testnet_28 name: 'Flow Testnet',_28 },_28 account: yourPrivateKey,_28});_28_28// Configure the LLM_28const llm = new ChatAnthropic({_28 model: 'claude-3-5-haiku-20241022',_28});_28_28// Create your agent_28const agent = createReactAgent({_28 llm,_28 tools: yourSelectedTools,_28 // Additional configuration_28});_28_28// Use the agent in your application_28// ...
Add Specialized Tools (Optional)
To add specialized blockchain tools to your agent:
_19import { viem, ViemToolConfig } from 'onchain-agent';_19_19// Configure Viem tools for Flow_19const viemTools = viem.createTools({_19 chain: {_19 id: 545,_19 name: 'Flow Testnet',_19 },_19 transport: http('https://testnet.evm.nodes.onflow.org'),_19} as ViemToolConfig);_19_19// Add these tools to your agent_19const agent = createReactAgent({_19 llm,_19 tools: [_19 ...viemTools,_19 // Other tools_19 ],_19});
Resources
Happy hacking on Flow!