Skip to main content

Overview

CrewAI lets you build multi-agent systems where agents collaborate on tasks. ACN tools give your crew access to real-world services — data, communications, payments, and more.

Define ACN Tools

import os
import requests
from crewai.tools import tool

ACN_BASE_URL = "https://api.acn.exchange"
ACN_API_KEY = os.environ["ACN_API_KEY"]

@tool("ACN Discover")
def acn_discover(query: str) -> str:
    """Search the ACN marketplace for services matching a natural language query.
    Returns ranked results with pricing and quality metrics."""
    response = requests.post(
        f"{ACN_BASE_URL}/v1/discover",
        json={"query": query}
    )
    return str(response.json())

@tool("ACN Execute")
def acn_execute(provider_id: str, endpoint_slug: str, payload: str) -> str:
    """Execute a service on ACN. Use provider_id and endpoint_slug from
    discovery results. Payload is a JSON string matching the endpoint schema."""
    import json
    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 str(response.json())

@tool("ACN Balance")
def acn_balance() -> str:
    """Check current ACN balance in USDC."""
    response = requests.get(
        f"{ACN_BASE_URL}/v1/wallet/balance",
        headers={"Authorization": f"Bearer {ACN_API_KEY}"}
    )
    return str(response.json())

Create a Crew

from crewai import Agent, Task, Crew

researcher = Agent(
    role="Research Analyst",
    goal="Find accurate, real-time data using ACN services",
    backstory="You are a research analyst who uses ACN to access "
              "real-time data services. Always check costs before executing.",
    tools=[acn_discover, acn_execute, acn_balance],
    verbose=True
)

writer = Agent(
    role="Content Writer",
    goal="Write clear, concise reports based on research data",
    backstory="You write reports based on data provided by the research team.",
    verbose=True
)

research_task = Task(
    description="Get the current prices of Bitcoin, Ethereum, and Solana in USD",
    expected_output="A dictionary of cryptocurrency prices",
    agent=researcher
)

report_task = Task(
    description="Write a brief market summary based on the price data",
    expected_output="A 3-paragraph market summary",
    agent=writer
)

crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, report_task],
    verbose=True
)

result = crew.kickoff()

Tips

  • Give the researcher agent all three ACN tools (discover, execute, balance)
  • Other agents in the crew typically don’t need direct ACN access — they work with the data returned by the researcher
  • Use acn_balance in the agent’s backstory instructions to encourage cost-awareness