This is a Next.js project bootstrapped with create-onchain-agent.
It integrates AgentKit with Google Generative AI to provide intelligent AI-driven interactions with on-chain capabilities using the Gemini 2.5 Flash model.
- AI-Powered Agent: Uses Google's Gemini 2.5 Flash LLM for intelligent decision-making
- On-Chain Capabilities: Interact with blockchain networks via AgentKit
- Smart Wallet Management: Integrated CDP Smart Wallet support
- Real-Time Chat Interface: Interactive web UI for agent communication
- Function Response Serialization: Handles proper JSON serialization of tool responses for LLM compatibility
- Node.js 18+
- npm or yarn
- Google Generative AI API key (Get one here)
- Coinbase Developer Platform (CDP) credentials
- Install dependencies:
npm install- Configure your environment variables by copying the template:
cp .env.local .env.local- Add your credentials to
.env.local:
# Required: Google Generative AI
GOOGLE_GENERATIVE_AI_API_KEY=your_api_key_here
# Required: Coinbase Developer Platform
CDP_API_KEY_ID=your_key_id
CDP_API_KEY_SECRET=your_key_secret
CDP_WALLET_SECRET=your_wallet_secret
# Optional: Network configuration
NETWORK_ID=base-sepolia- Run the development server:
npm run dev- Open http://localhost:3000 in your browser
app/
├── api/agent/
│ ├── route.ts # Main API endpoint for agent interactions
│ ├── create-agent.ts # Agent initialization and LLM configuration
│ └── prepare-agentkit.ts # AgentKit and wallet provider setup
├── hooks/
│ └── useAgent.ts # React hook for agent communication
├── types/
│ └── api.ts # TypeScript type definitions
└── page.tsx # Main chat interface
You can customize your agent's behavior and capabilities:
Edit /api/agent/create-agent.ts to use a different Google Generative AI model or adjust model parameters like temperature and max tokens.
Edit /api/agent/prepare-agentkit.ts to change the blockchain network, wallet type, or network settings.
The agent comes with the following action providers enabled:
walletActionProvider()- Basic wallet operationswethActionProvider()- WETH token interactionserc20ActionProvider()- ERC-20 token operationscdpApiActionProvider()- CDP API actionscdpSmartWalletActionProvider()- Smart wallet operationspythActionProvider()- Python oracle datax402ActionProvider()- Payment operations
You can modify these in the AgentKit.from() configuration.
This project includes a custom wrapper for agent tools that ensures all responses are properly serialized as JSON objects before being sent to the Google Generative AI API. This prevents validation errors when tools return formatted string responses.
The wrapper automatically:
- Converts formatted string responses to structured JSON objects
- Parses nested sections (like wallet network details) into proper object hierarchies
- Provides fallback handling for unparseable responses
See /api/agent/route.ts for the implementation.
Make sure GOOGLE_GENERATIVE_AI_API_KEY is set in your .env.local file and the development server has been restarted.
Ensure all three CDP credentials are configured:
CDP_API_KEY_IDCDP_API_KEY_SECRETCDP_WALLET_SECRET
This is a warning about native module compilation. It's not critical - the application will fall back to pure JavaScript. You can try running npm run rebuild to compile native modules for your environment.
Before deploying to production:
- Build the project:
npm run build- Start the production server:
npm start- Ensure all environment variables are properly set in your production environment
- Use environment-specific secrets management for sensitive credentials
- Explore the AgentKit Documentation
- Review Google Generative AI API docs
- Learn more about Coinbase Developer Platform
- Customize the chat UI in
/app/page.tsx
- AgentKit GitHub
- Google Generative AI
- Coinbase Developer Platform
- Next.js Documentation
- Tailwind CSS Documentation
Interested in contributing to AgentKit? Follow the contribution guide:
- AgentKit Contribution Guide
- Join the discussion on Discord
This project is part of the AgentKit ecosystem. See the AgentKit repository for license information.