Overview
AutoGen enables multi-agent conversations with function calling. ACN tools integrate as callable functions that agents can invoke during conversations.Define ACN Functions
import os
import json
import requests
from typing import Annotated
ACN_BASE_URL = "https://api.acn.exchange"
ACN_API_KEY = os.environ["ACN_API_KEY"]
def acn_discover(
query: Annotated[str, "Natural language description of the service you need"]
) -> str:
"""Search ACN marketplace for services."""
response = requests.post(
f"{ACN_BASE_URL}/v1/discover",
json={"query": query}
)
return json.dumps(response.json(), indent=2)
def acn_execute(
provider_id: Annotated[str, "Provider ID from discovery results"],
endpoint_slug: Annotated[str, "Endpoint slug from discovery results"],
payload: Annotated[str, "JSON string of the request payload"]
) -> str:
"""Execute a service on ACN."""
response = requests.post(
f"{ACN_BASE_URL}/v1/execute/{provider_id}/{endpoint_slug}",
headers={"Authorization": f"Bearer {ACN_API_KEY}"},
json=json.loads(payload)
)
return json.dumps(response.json(), indent=2)
Register with Agents
from autogen import ConversableAgent
assistant = ConversableAgent(
name="acn_assistant",
system_message="You are an assistant with access to ACN services. "
"Use acn_discover to find services, then acn_execute to use them.",
llm_config={"config_list": [{"model": "claude-sonnet-4-20250514"}]}
)
user_proxy = ConversableAgent(
name="user_proxy",
human_input_mode="NEVER",
is_termination_msg=lambda msg: "TERMINATE" in msg.get("content", "")
)
# Register functions for the assistant to call
assistant.register_for_llm(name="acn_discover", description="Search ACN for services")(acn_discover)
assistant.register_for_llm(name="acn_execute", description="Execute an ACN service")(acn_execute)
# Register function execution with the proxy
user_proxy.register_for_execution(name="acn_discover")(acn_discover)
user_proxy.register_for_execution(name="acn_execute")(acn_execute)
# Start conversation
user_proxy.initiate_chat(
assistant,
message="Find the current price of Ethereum and summarize it."
)
Multi-Agent Setup
researcher = ConversableAgent(
name="researcher",
system_message="You research data using ACN services. "
"Always use acn_discover first, then acn_execute.",
llm_config=llm_config
)
analyst = ConversableAgent(
name="analyst",
system_message="You analyze data provided by the researcher and provide insights.",
llm_config=llm_config
)
# Register ACN tools only with the researcher
researcher.register_for_llm(name="acn_discover", description="Search ACN")(acn_discover)
researcher.register_for_llm(name="acn_execute", description="Execute ACN service")(acn_execute)