Run This Ai
EN DE

Agency Swarm Quick Start: Deploying Multi-Agent Workflows

A practical quick start guide to Agency Swarm: install, define agents, add custom tools, and run multi-agent workflows in Python.

Agency Swarm

Getting Started with Agency Swarm

Agency Swarm makes it easy to build multi-agent AI systems in Python. This quick start guide walks you through installation, creating your first swarm, defining agents with custom tools, and running multi-agent workflows.

Installation

Install Agency Swarm via pip:

pip install agency-swarm

You will also need an OpenAI API key (or any OpenAI-compatible provider) set as an environment variable:

export OPENAI_API_KEY="your-api-key-here"
Agency Swarm Framework

Creating Your First Swarm

Define a simple swarm with two agents: a researcher and a writer. The researcher gathers information and the writer produces content.

from agency_swarm import Agent, Agency

# Define agents
researcher = Agent(
    name="Researcher",
    description="Expert researcher that finds and summarizes information",
    instructions="You are a thorough researcher. Find relevant information and present it clearly.",
    model="gpt-4"
)

writer = Agent(
    name="Writer",
    description="Expert writer that creates polished content from research",
    instructions="You create engaging, well-structured content based on research findings.",
    model="gpt-4"
)

# Create agency with communication channels
agency = Agency(
    agents=[researcher, writer],
    communication_flows=[
        (researcher, writer),  # researcher can send tasks to writer
    ]
)

Adding Custom Tools

Tools are Python functions decorated with Agency Swarm annotations:

from agency_swarm.tools import BaseTool
from pydantic import Field

class WebSearchTool(BaseTool):
    """Search the web for information on a topic."""
    query: str = Field(..., description="Search query")
    
    def run(self):
        # Your web search implementation here
        return f"Search results for: {self.query}"

# Assign tool to agent
researcher = Agent(
    name="Researcher",
    tools=[WebSearchTool],
    ...
)

Running the Swarm

Start the interactive agent interface or run programmatically:

# Interactive demo mode
agency.demo_loop()

# Or run a specific task
result = agency.get_completion(
    "Research the latest advances in AI agents and write a summary",
    recipient_agent=researcher
)

Best Practices

  • Keep agent roles focused — each agent should excel at one type of task
  • Define clear communication flows — avoid circular delegation patterns
  • Use descriptive instructions — be explicit about what each agent should do
  • Start simple — add agents gradually as your workflow complexity grows

Conclusion

Agency Swarm makes multi-agent AI development accessible. With its intuitive API, custom tool system, and flexible architecture, you can build anything from simple two-agent collaborations to complex swarms of dozens of specialized agents working together autonomously.

#ai-agents #swarm #tutorial #python #quickstart