Google ADK
Integrating Google ADK with Agentipy
This guide demonstrates how to integrate Google's Agent Development Kit (ADK) with Agentipy to create intelligent agents that can interact with blockchain networks.
Prerequisites
Python 3.9+
A Solana wallet private key
Google API key
Setup
Install required packages
pip install agentipy google-adk python-dotenv
Create an environment file
Create a .env
file in your project root with the following variables:
PRIVATE_KEY=your_solana_private_key
GOOGLE_GENAI_USE_VERTEXAI=FALSE
GOOGLE_API_KEY=your_google_api_key
Folder Structure
.
├── agent/
│ ├── __init__.py # Agent configuration definitions
│ └── agent.py # Task configuration definitions
└── .env
Basic Structure
The integration follows these key steps:
Create your AgentiPy kit for the specific blockchain
Define domain-specific tools/functions
Create a Google LlmAgent and provide your tools
Set the LlmAgent as your root agent
Example: Solana Balance Checker
from agentipy.agent import SolanaAgentKit
from agentipy.tools.get_balance import BalanceFetcher
import os
from dotenv import load_dotenv
from google.adk.agents import LlmAgent
from google.adk.agents import Agent
from typing import Optional
# Load environment variables
load_dotenv()
# Initialize Solana agent kit
agent = SolanaAgentKit(
private_key=os.getenv("PRIVATE_KEY"),
rpc_url="https://api.mainnet-beta.solana.com" # Mainnet RPC endpoint
)
# Define a tool/function for your agent
async def get_balance(token_address: Optional[str] = None) -> str:
"""Get the current balance of the wallet.
Args:
token_address (Optional[str]): The token address to get the balance of.
Returns:
str: The balance of the wallet.
"""
try:
balance = await BalanceFetcher.get_balance(agent, token_address)
return f"Current balance: {balance}"
except Exception as e:
return f"Error getting balance: {str(e)}"
# Create a Google LlmAgent with your tool
check_balance = LlmAgent(
name="Check_Balance",
description="Check the balance of the wallet for a specific token or SOL",
tools=[get_balance],
model="gemini-2.0-flash",
)
# Set as root agent
root_agent = check_balance
Running Your Agent
Create a file named main.py
to run your agent:
To ensure proper execution, utilize either adk web
or adk run
commands. Confirm execution from the root folder
// adk run or adk web
Extending Your Agent
You can add more tools to your agent by:
Creating additional functions that use the AgentiPy kit
Adding these functions to your LlmAgent's tools list
Example of adding a token transfer tool:
async def transfer_token(recipient: str, amount: float, token_address: Optional[str] = None) -> str:
"""Transfer tokens to another wallet.
Args:
recipient (str): The recipient's wallet address.
amount (float): The amount to transfer.
token_address (Optional[str]): The token address to transfer. Default is SOL.
Returns:
str: The transaction result.
"""
try:
# Implement transfer logic using AgentiPy
return f"Transferred {amount} to {recipient}"
except Exception as e:
return f"Error transferring tokens: {str(e)}"
# Update your agent with multiple tools
wallet_agent = LlmAgent(
name="Wallet_Agent",
description="Manage wallet balance and transfers",
tools=[get_balance, transfer_token],
model="gemini-2.0-flash",
)
Best Practices
Error Handling: Always include proper error handling in your tool functions
Documentation: Provide clear docstrings for all tools
Environment Variables: Keep sensitive information in environment variables
Modular Design: Create specific agents for different functionalities
Testing: Test your agents with various inputs before deployment
Resources
Last updated