|
| 1 | +AgentiPy Documentation |
| 2 | +==================== |
| 3 | + |
| 4 | +Overview |
| 5 | +-------- |
| 6 | +AgentiPy is a powerful toolkit for building and deploying Solana blockchain applications with AI capabilities. It provides a comprehensive set of tools for interacting with various Solana protocols, managing wallets, and integrating with AI models. |
| 7 | + |
| 8 | +Quick Start |
| 9 | +---------- |
| 10 | + |
| 11 | +Prerequisites |
| 12 | +------------ |
| 13 | +Before you begin, ensure you have the following prerequisites: |
| 14 | + |
| 15 | +- Python 3.8+: Required for running the toolkit |
| 16 | +- Solana CLI: For Solana-specific actions (e.g., wallet creation) |
| 17 | +- Langchain: For AI integration (pip install langchain) |
| 18 | +- Wallet with Private Keys: Crucial for signing and sending transactions |
| 19 | +- API Keys (Optional): For accessing various blockchain networks or external data sources |
| 20 | + |
| 21 | +Installation |
| 22 | +----------- |
| 23 | +1. Create a Virtual Environment: |
| 24 | + python -m venv venv |
| 25 | + |
| 26 | +2. Activate the Virtual Environment: |
| 27 | + # Linux/macOS: |
| 28 | + source venv/bin/activate |
| 29 | + |
| 30 | + # Windows: |
| 31 | + venv\Scripts\activate |
| 32 | + |
| 33 | +3. Install AgentiPy: |
| 34 | + pip install agentipy |
| 35 | + |
| 36 | +4. Verify Installation: |
| 37 | + import agentipy |
| 38 | + print(agentipy.__version__) # Example output: 2.0.2 |
| 39 | + |
| 40 | +Core Concepts |
| 41 | +------------ |
| 42 | + |
| 43 | +SolanaAgentKit |
| 44 | +------------- |
| 45 | +The SolanaAgentKit is the main entry point for interacting with the Solana blockchain: |
| 46 | + |
| 47 | +from agentipy.agent import SolanaAgentKit |
| 48 | + |
| 49 | +agent = SolanaAgentKit( |
| 50 | + private_key="YOUR_PRIVATE_KEY", |
| 51 | + rpc_url="https://api.mainnet-beta.solana.com" |
| 52 | +) |
| 53 | + |
| 54 | +Supported Protocols |
| 55 | +----------------- |
| 56 | +AgentiPy supports a wide range of Solana protocols: |
| 57 | + |
| 58 | +Protocol Description Key Features |
| 59 | +--------- ----------- ------------- |
| 60 | +Jupiter DEX Aggregator Token swaps, direct routing, stake SOL |
| 61 | +Raydium DEX Buy/sell tokens, provide liquidity |
| 62 | +Metaplex NFT Platform NFT minting, collection deployment |
| 63 | +Helius Data Provider Fetch balances, NFT lists, events |
| 64 | +Drift Perpetual DEX Manage accounts, perp trades |
| 65 | +Orca DEX Manage liquidity pools, positions |
| 66 | +Pyth Network Price Oracle Fetch token prices |
| 67 | +And many more... |
| 68 | + |
| 69 | +Tutorials |
| 70 | +-------- |
| 71 | + |
| 72 | +1. Basic Token Transfer |
| 73 | +---------------------- |
| 74 | +from agentipy.agent import SolanaAgentKit |
| 75 | +from agentipy.tools.transfer import TokenTransferManager |
| 76 | +import asyncio |
| 77 | + |
| 78 | +async def main(): |
| 79 | + agent = SolanaAgentKit( |
| 80 | + private_key="YOUR_PRIVATE_KEY", |
| 81 | + rpc_url="https://api.mainnet-beta.solana.com" |
| 82 | + ) |
| 83 | + |
| 84 | + try: |
| 85 | + transfer_signature = await TokenTransferManager.transfer( |
| 86 | + agent=agent, |
| 87 | + to="RECIPIENT_ADDRESS", |
| 88 | + amount=0.0001 # Amount in SOL |
| 89 | + ) |
| 90 | + print(f"Transfer successful! Signature: {transfer_signature}") |
| 91 | + except Exception as e: |
| 92 | + print(f"Transfer failed: {e}") |
| 93 | + |
| 94 | +if __name__ == "__main__": |
| 95 | + asyncio.run(main()) |
| 96 | + |
| 97 | +2. Checking Balances |
| 98 | +------------------- |
| 99 | +from agentipy.agent import SolanaAgentKit |
| 100 | +from agentipy.tools.get_balance import BalanceFetcher |
| 101 | +import asyncio |
| 102 | + |
| 103 | +async def main(): |
| 104 | + agent = SolanaAgentKit( |
| 105 | + private_key="YOUR_PRIVATE_KEY", |
| 106 | + rpc_url="https://api.mainnet-beta.solana.com" |
| 107 | + ) |
| 108 | + |
| 109 | + try: |
| 110 | + balance = await BalanceFetcher.get_balance(agent) |
| 111 | + print(f"Wallet Balance: {balance:.4f} SOL") |
| 112 | + except Exception as e: |
| 113 | + print(f"Failed to get balance: {e}") |
| 114 | + |
| 115 | +if __name__ == "__main__": |
| 116 | + asyncio.run(main()) |
| 117 | + |
| 118 | +3. Market Data with CoinGecko |
| 119 | +---------------------------- |
| 120 | +from agentipy.agent import SolanaAgentKit |
| 121 | +from agentipy.tools.use_coingecko import CoingeckoManager |
| 122 | +import asyncio |
| 123 | + |
| 124 | +async def main(): |
| 125 | + agent = SolanaAgentKit( |
| 126 | + private_key="", # Not needed for market data |
| 127 | + rpc_url="https://api.mainnet-beta.solana.com" |
| 128 | + ) |
| 129 | + |
| 130 | + try: |
| 131 | + trending = await CoingeckoManager.get_trending_tokens(agent) |
| 132 | + for token in trending['coins']: |
| 133 | + print(f"- {token['item']['symbol']} ({token['item']['name']})") |
| 134 | + except Exception as e: |
| 135 | + print(f"Failed to get trending tokens: {e}") |
| 136 | + |
| 137 | +if __name__ == "__main__": |
| 138 | + asyncio.run(main()) |
| 139 | + |
| 140 | +Advanced Features |
| 141 | +--------------- |
| 142 | + |
| 143 | +1. Langchain Integration |
| 144 | +----------------------- |
| 145 | +AgentiPy can be integrated with Langchain for natural language processing: |
| 146 | + |
| 147 | +from langchain.llms import OpenAI |
| 148 | +from agentipy.agent import SolanaAgentKit |
| 149 | +from agentipy.tools.trade import TradeManager |
| 150 | + |
| 151 | +# Initialize components |
| 152 | +llm = OpenAI(openai_api_key="YOUR_OPENAI_API_KEY") |
| 153 | +agent = SolanaAgentKit( |
| 154 | + private_key="YOUR_PRIVATE_KEY", |
| 155 | + rpc_url="https://api.mainnet-beta.solana.com" |
| 156 | +) |
| 157 | + |
| 158 | +# Process natural language commands |
| 159 | +prompt = "Buy 1 SOL of USDC" |
| 160 | +action = llm(prompt) |
| 161 | + |
| 162 | +# Execute trade |
| 163 | +try: |
| 164 | + TradeManager.trade( |
| 165 | + agent=agent, |
| 166 | + output_mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", |
| 167 | + input_amount=0.1 |
| 168 | + ) |
| 169 | +except Exception as e: |
| 170 | + print(f"Trade failed: {e}") |
| 171 | + |
| 172 | +2. Model Context Protocol (MCP) |
| 173 | +----------------------------- |
| 174 | +AgentiPy includes built-in MCP support for standardized tool invocation: |
| 175 | + |
| 176 | +from agentipy.mcp.all_actions import ALL_ACTIONS |
| 177 | +from agentipy.mcp.mcp_server import start_mcp_server |
| 178 | + |
| 179 | +# Start MCP server |
| 180 | +agent = SolanaAgentKit(private_key="<KEY>", rpc_url="<RPC_URL>") |
| 181 | +start_mcp_server(agent) |
| 182 | + |
| 183 | +Available MCP Actions: |
| 184 | + |
| 185 | +Core Solana Actions: |
| 186 | +- GET_BALANCE: Fetch wallet balances |
| 187 | +- TRANSFER: Transfer tokens |
| 188 | +- DEPLOY_TOKEN: Deploy new tokens |
| 189 | + |
| 190 | +Allora Actions: |
| 191 | +- GET_ALL_TOPICS: List inference topics |
| 192 | +- GET_PRICE_PREDICTION: Get price predictions |
| 193 | +- GET_INFERENCE_BY_TOPIC_ID: Get specific inferences |
| 194 | + |
| 195 | +Jupiter Actions: |
| 196 | +- STAKE_WITH_JUP: Stake for rewards |
| 197 | +- TRADE_WITH_JUP: Execute swaps |
| 198 | + |
| 199 | +3. Claude Desktop Integration |
| 200 | +--------------------------- |
| 201 | +Configure Claude Desktop to use AgentiPy MCP: |
| 202 | + |
| 203 | +{ |
| 204 | + "mcpServers": { |
| 205 | + "agentipy": { |
| 206 | + "command": "./run_mcp.sh", |
| 207 | + "autoApprove": ["GET_BALANCE", "PRICE_PREDICTION"] |
| 208 | + } |
| 209 | + } |
| 210 | +} |
| 211 | + |
| 212 | +Best Practices |
| 213 | +------------- |
| 214 | + |
| 215 | +1. Security |
| 216 | +---------- |
| 217 | +- Never hardcode private keys |
| 218 | +- Use environment variables or secure key management |
| 219 | +- Test with small amounts first |
| 220 | + |
| 221 | +2. Error Handling |
| 222 | +--------------- |
| 223 | +- Always wrap operations in try-except blocks |
| 224 | +- Implement proper error logging |
| 225 | +- Handle rate limits appropriately |
| 226 | + |
| 227 | +3. Performance |
| 228 | +------------ |
| 229 | +- Use async/await for concurrent operations |
| 230 | +- Implement proper caching where appropriate |
| 231 | +- Monitor RPC endpoint usage |
| 232 | + |
| 233 | +Troubleshooting |
| 234 | +-------------- |
| 235 | + |
| 236 | +Common issues and solutions: |
| 237 | + |
| 238 | +1. RPC Connection Issues |
| 239 | +---------------------- |
| 240 | +- Check network connectivity |
| 241 | +- Verify RPC endpoint URL |
| 242 | +- Consider using multiple RPC providers |
| 243 | + |
| 244 | +2. Transaction Failures |
| 245 | +--------------------- |
| 246 | +- Verify sufficient balance |
| 247 | +- Check transaction parameters |
| 248 | +- Monitor network congestion |
| 249 | + |
| 250 | +3. API Rate Limits |
| 251 | +---------------- |
| 252 | +- Implement proper rate limiting |
| 253 | +- Use multiple API keys if needed |
| 254 | +- Cache frequently accessed data |
| 255 | + |
| 256 | +API Reference |
| 257 | +------------ |
| 258 | +For detailed API documentation, visit our API Reference at https://agentipy.fun/ |
| 259 | + |
| 260 | +Contributing |
| 261 | +----------- |
| 262 | +We welcome contributions! Please see our Contributing Guide at https://github.com/niceberginc/agentipy/blob/main/CONTRIBUTING.md |
| 263 | + |
| 264 | +License |
| 265 | +------- |
| 266 | +AgentiPy is licensed under the MIT License. See LICENSE at https://github.com/niceberginc/agentipy/blob/main/LICENSE.md |
0 commit comments