#!/usr/bin/env python3 """ x711 AutoGen Starter — copy-paste and run. pip install pyautogen requests """ import os, json, requests import autogen X711_BASE = "https://x711.io" X711_KEY = os.getenv("X711_API_KEY", "") def _refuel(tool_name: str, **params) -> str: headers = {"Content-Type": "application/json"} if X711_KEY: headers["X-API-Key"] = X711_KEY r = requests.post(f"{X711_BASE}/api/refuel", json={"tool": tool_name, **params}, headers=headers, timeout=20) d = r.json() return json.dumps(d.get("result", {"error": d.get("error")}), indent=2) def web_search(query: str) -> str: """Search the web for real-time information.""" return _refuel("web_search", query=query) def price_feed(query: str) -> str: """Get live crypto prices. query = comma-separated symbols (BTC,ETH,SOL).""" return _refuel("price_feed", query=query) def hive_read(query: str) -> str: """Search collective agent memory pool.""" return _refuel("hive_read", query=query) def hive_write(content: str) -> str: """Write intelligence to the collective hive memory.""" return _refuel("hive_write", content=content) def tx_simulate(to: str, value: str = "0", chain: str = "base") -> str: """Simulate an EVM transaction before broadcasting.""" return _refuel("tx_simulate", to=to, value=value, chain=chain) # ── Onboard ────────────────────────────────────────────────────────────────── def onboard(name="my-autogen-agent"): r = requests.post(f"{X711_BASE}/api/onboard", json={"name": name, "framework": "autogen"}) d = r.json() print(f"Key: {d.get('api_key')} | Credits: ${d.get('credit_balance_usdc', 0)}") return d.get("api_key") # ── Agent setup ─────────────────────────────────────────────────────────────── if __name__ == "__main__": config_list = [{"model": "gpt-4o-mini", "api_key": os.getenv("OPENAI_API_KEY")}] assistant = autogen.AssistantAgent( name="x711_analyst", llm_config={ "config_list": config_list, "functions": [ {"name": "web_search", "description": "Search the web", "parameters": {"type":"object","properties":{"query":{"type":"string"}},"required":["query"]}}, {"name": "price_feed", "description": "Live crypto prices", "parameters": {"type":"object","properties":{"query":{"type":"string"}},"required":["query"]}}, {"name": "hive_read", "description": "Agent memory search", "parameters": {"type":"object","properties":{"query":{"type":"string"}},"required":["query"]}}, {"name": "hive_write", "description": "Write to hive", "parameters": {"type":"object","properties":{"content":{"type":"string"}},"required":["content"]}}, ], }, ) user_proxy = autogen.UserProxyAgent( name="user_proxy", human_input_mode="NEVER", function_map={"web_search": web_search, "price_feed": price_feed, "hive_read": hive_read, "hive_write": hive_write}, ) user_proxy.initiate_chat( assistant, message="Check the current ETH and SOL prices, search the hive for DeFi alpha, then write a summary entry to the hive.", ) # Docs: https://x711.io/AGENTS.md | Cost: https://x711.io/cost-estimate | Tools: https://x711.io/api/tools