import requests
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
X711_KEY = "x711_your_key_here" # free: curl -X POST https://x711.io/api/onboard -d '{"name":"autogen-agent"}'
def x711_web_search(query: str) -> str:
"""Search the live web for current information."""
return str(requests.post(
"https://x711.io/api/refuel",
headers={"X-API-Key": X711_KEY},
json={"tool": "web_search", "query": query},
timeout=15,
).json())
def x711_price_feed(assets: list) -> str:
"""Get live prices for crypto or stock symbols."""
return str(requests.post(
"https://x711.io/api/refuel",
headers={"X-API-Key": X711_KEY},
json={"tool": "price_feed", "assets": assets},
timeout=15,
).json())
def x711_hive_read(namespace: str, query: str) -> str:
"""Read collective agent memory for a topic."""
return str(requests.post(
"https://x711.io/api/refuel",
headers={"X-API-Key": X711_KEY},
json={"tool": "hive_read", "namespace": namespace, "query": query},
timeout=15,
).json())
llm_config = {
"config_list": [{"model": "gpt-4o-mini", "api_key": "YOUR_OAI_KEY"}],
"functions": [
{"name": "x711_web_search", "description": "Search the live web", "parameters": {"type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]}},
{"name": "x711_price_feed", "description": "Live prices", "parameters": {"type": "object", "properties": {"assets": {"type": "array", "items": {"type": "string"}}}, "required": ["assets"]}},
{"name": "x711_hive_read", "description": "Collective agent memory", "parameters": {"type": "object", "properties": {"namespace": {"type": "string"}, "query": {"type": "string"}}, "required": ["namespace", "query"]}},
],
}
assistant = AssistantAgent("researcher", llm_config=llm_config)
user_proxy = UserProxyAgent(
"executor",
human_input_mode="NEVER",
function_map={
"x711_web_search": x711_web_search,
"x711_price_feed": x711_price_feed,
"x711_hive_read": x711_hive_read,
},
)
user_proxy.initiate_chat(
assistant,
message="What is the current ETH price and top Base chain DeFi news today?",
)