AgentiPy provides seamless integration with the OmniAgent framework, allowing you to create AI agents that can interact with the Solana blockchain through natural language interfaces. This integration enables developers to build sophisticated AI-driven blockchain applications with conversational capabilities, real-time event streaming, and robust memory management.
🚀 Quick Start
import asynciofrom mcpomni_connect.omni_agent import OmniAgentfrom mcpomni_connect.memory_store.memory_router import MemoryRouterfrom mcpomni_connect.events.event_router import EventRouterfrom mcpomni_connect.agents.tools.local_tools_registry import ToolRegistryfrom agentipy.agent import SolanaAgentKitfrom agentipy.tools.get_balance import BalanceFetcherfrom agentipy.tools.transfer import TokenTransferManagerfrom dotenv import load_dotenvfrom typing import Optionalimport osload_dotenv()# Initialize Solana agentsolana_agent =SolanaAgentKit(private_key=os.getenv("SOLANA_PRIVATE_KEY"),rpc_url="https://api.mainnet-beta.solana.com")# Create tool registryasyncdefcreate_tool_registry()-> ToolRegistry:"""Create a tool registry with Solana operations.""" tool_registry =ToolRegistry()@tool_registry.register_tool("get_balance_solana")asyncdefget_balance(address: Optional[str]=None)->str:"""Get the balance of a Solana address."""try: balance_sol =await BalanceFetcher.get_balance( solana_agent,token_address=address)return{"status":"success","data": balance_sol}exceptExceptionas e:return{"status":"error","message":str(e)}@tool_registry.register_tool("transfer_solana")asyncdeftransfer_solana(address:str,amount:float)->str:"""Transfer SOL to a Solana address."""try: sig =await TokenTransferManager.transfer( solana_agent,to=address,amount=amount)return{"status":"success","message":"SOL transferred successfully","signature": sig}exceptExceptionas e:return{"status":"error","message":str(e)}return tool_registry# Initialize memory and event systemsmemory_store =MemoryRouter(memory_store_type="in_memory")event_router =EventRouter(event_store_type="in_memory")# Create the OmniAgentasyncdefcreate_agent(): tool_registry =awaitcreate_tool_registry() agent =OmniAgent(name="solana_agent",system_instruction="""You are a Solana agent with the ability to check balances and transfer SOL.CRITICAL RULES:- Always check balance before transfers using get_balance_solana- Verify sufficient funds before calling transfer_solana- Only use available tools in the registry""",model_config={"provider":"openai","model":"gpt-4.1","temperature":0.7,"max_context_length":50000,},local_tools=tool_registry,agent_config={"max_steps":15,"tool_call_timeout":60,"request_limit":1000,"memory_config":{"mode":"token_budget","value":10000},},memory_store=memory_store,event_router=event_router,debug=True,)return agent# Run the agentasyncdefmain(): agent =awaitcreate_agent()# Check balance response =await agent.run("What's my SOL balance?",session_id="session_001")print(response)# Transfer SOL response =await agent.run("Transfer 0.5 SOL to <address>",session_id="session_001")print(response)asyncio.run(main())
🛠️ Key Components
1
Tool Registry
The ToolRegistry is the foundation of your agent's capabilities. It manages all the tools (functions) that your AI agent can execute.
Key Features:
Automatic function registration
Type hints for parameter validation
Docstrings used by AI for tool selection
Async/await support
2
OmniAgent Configuration
The OmniAgent is the core component that orchestrates AI reasoning, tool execution, and memory management.
Configuration Options:
Parameter
Description
Default
name
Agent identifier
Required
system_instruction
AI behavior guidelines
Required
model_config
LLM configuration
Required
local_tools
Tool registry
None
agent_config
Execution settings
{}
memory_store
Conversation memory
None
event_router
Event tracking
None
debug
Enable debug logging
False
3
Memory Management
The memory system maintains conversation context across interactions:
Memory Modes:
token_budget: Maintains last N tokens of conversation
sliding_window: Keeps last N messages
4
Event Streaming
Events provide real-time visibility into agent operations:
tool_registry = ToolRegistry()
@tool_registry.register_tool("tool_name")
async def tool_function(param: str) -> dict:
"""Tool description that the AI will use to understand when to call this."""
# Your implementation
return {"status": "success", "data": result}
agent = OmniAgent(
name="agent_name",
system_instruction="Detailed instructions for the AI...",
model_config={
"provider": "openai", # or "anthropic", "google"
"model": "gpt-4.1",
"temperature": 0.7,
"max_context_length": 50000,
},
local_tools=tool_registry,
agent_config={
"max_steps": 15, # Maximum reasoning steps
"tool_call_timeout": 60, # Timeout per tool call
"request_limit": 1000, # Rate limiting
"memory_config": {
"mode": "token_budget", # or "sliding_window"
"value": 10000
},
},
memory_store=memory_store,
event_router=event_router,
debug=True,
)
event_router = EventRouter(event_store_type="in_memory")
# Stream events from a session
async for event in agent.stream_events(session_id):
print(f"Event: {event.type}")
print(f"Data: {event.data}")
@tool_registry.register_tool("get_balance_solana")
async def get_balance(address: Optional[str] = None) -> dict:
"""
Get the balance of a Solana address.
If no address is provided, returns the agent's wallet balance.
Args:
address: Optional Solana address to check
Returns:
Dictionary with status and balance data
"""
balance = await BalanceFetcher.get_balance(
solana_agent,
token_address=address
)
return {"status": "success", "data": balance}
@tool_registry.register_tool("transfer_solana")
async def transfer_solana(address: str, amount: float) -> dict:
"""
Transfer SOL to a Solana address.
Args:
address: Destination Solana address
amount: Amount of SOL to transfer
Returns:
Dictionary with status and transaction signature
"""
signature = await TokenTransferManager.transfer(
solana_agent,
to=address,
amount=amount
)
return {
"status": "success",
"signature": signature
}
system_instruction = """
CRITICAL: Before ANY SOL transfer:
1. Call get_balance_solana to check current balance
2. Compare balance with requested transfer amount
3. Only proceed if balance >= transfer amount
4. Inform user if insufficient funds
"""
from dotenv import load_dotenv
import os
load_dotenv()
private_key = os.getenv("SOLANA_PRIVATE_KEY")
# Same session maintains conversation context
response1 = await agent.run("Check my balance", session_id="user_123")
response2 = await agent.run("Transfer 0.5 SOL to <address>", session_id="user_123")
# Natural language interactions
"What's my current SOL balance?"
"Send 0.5 SOL to ABC123..."
"How much SOL do I have left after that transfer?"
# Conditional transfers based on balance
"If my balance is above 10 SOL, transfer 5 SOL to the treasury address"
# Different sessions for different users
await agent.run(message, session_id=f"user_{user_id}")
agent = OmniAgent(
# ... other config
debug=True
)
async def run(
self,
message: str,
session_id: Optional[str] = None
) -> dict:
"""
Process a user message and return the agent's response.
Args:
message: User input message
session_id: Optional session identifier for context
Returns:
Dictionary containing agent response and metadata
"""
async def stream_events(
self,
session_id: str
) -> AsyncIterator[Event]:
"""
Stream events from a specific session.
Args:
session_id: Session identifier
Yields:
Event objects with type and data
"""