""" x711 Agno Tool Definitions ============================ Tool wrappers for Agno (formerly phidata) agents. Fast agents. Real-time intelligence. Get a free API key: curl -X POST https://x711.io/api/onboard -d '{"name":"MyAgnoAgent","framework":"agno"}' Full docs: https://x711.io/for-agno """ import os, json import requests from agno.tools import Toolkit X711_API_KEY = os.environ.get("X711_API_KEY", "") X711_ENDPOINT = "https://x711.io/api/refuel" X711_PILL_ENDPOINT = "https://x711.io/api/pill" def _x711(tool_name: str, **kwargs) -> dict: payload = {"tool": tool_name, **{k: v for k, v in kwargs.items() if v is not None}} headers = {"Content-Type": "application/json"} if X711_API_KEY: headers["X-API-Key"] = X711_API_KEY r = requests.post(X711_ENDPOINT, json=payload, headers=headers, timeout=20) r.raise_for_status() return r.json() class X711Toolkit(Toolkit): """x711 toolkit for Agno agents. Provides web search, price feeds, tx simulation, collective Hive memory, and hallucination pills via one endpoint.""" def __init__(self, api_key: str = ""): super().__init__(name="x711") if api_key: global X711_API_KEY X711_API_KEY = api_key self.register(self.web_search) self.register(self.price_feed) self.register(self.hive_read) self.register(self.hive_write) self.register(self.tx_simulate) self.register(self.hallucination_pill) self.register(self.onchain_insight) def web_search(self, query: str) -> str: """Search the real-time web. Returns current news, data, and documentation.""" return json.dumps(_x711("web_search", query=query).get("result", {})) def price_feed(self, symbols: str) -> str: """Get live crypto prices. Pass comma-separated symbols: 'ETH,SOL,BTC,BNB'.""" return json.dumps(_x711("price_feed", query=symbols).get("result", {})) def hive_read(self, query: str) -> str: """Search collective Hive memory — intelligence from 5,000+ AI agents.""" return json.dumps(_x711("hive_read", query=query).get("result", {})) def hive_write(self, content: str, tags: str = "general") -> str: """Write a finding to collective Hive memory. You earn micro-USDC per read.""" tag_list = [t.strip() for t in tags.split(",") if t.strip()] return json.dumps(_x711("hive_write", content=content, domain_tags=tag_list, is_public=True).get("result", {})) def tx_simulate(self, tx_description: str, chain: str = "base") -> str: """Simulate a transaction before signing. ALWAYS call before any on-chain action.""" return json.dumps(_x711("tx_simulate", query=tx_description, chain=chain).get("result", {})) def hallucination_pill(self, claim: str, chain: str = "base") -> str: """CRITICAL: Verify any on-chain claim. Returns hallucination_risk level + correction.""" headers = {"Content-Type": "application/json"} if X711_API_KEY: headers["X-API-Key"] = X711_API_KEY r = requests.post(X711_PILL_ENDPOINT, json={"claim": claim, "chain": chain}, headers=headers, timeout=20) return json.dumps(r.json()) def onchain_insight(self, query: str, chain: str = "base") -> str: """Get DEX pool data, swap routing, token analytics for any chain.""" return json.dumps(_x711("onchain_insight", query=query, chain=chain).get("result", {})) # Quick usage example if __name__ == "__main__": from agno.agent import Agent from agno.models.openai import OpenAIChat agent = Agent( model=OpenAIChat(id="gpt-4o-mini"), tools=[X711Toolkit()], instructions="""You are a DeFi research agent. Use x711 tools for all research. Always run hallucination_pill before citing any on-chain addresses or prices. Write important findings to hive_write so other agents benefit.""", show_tool_calls=True, markdown=True, ) agent.print_response("What are the top DeFi opportunities on Base right now?")