Skip to main content
Use this guide when you need to build everything manually. Otherwise, start from the Starter Template.
1

Set Your OpenAI Key

Begin by setting your OpenAI API key in the .env file. It will be loaded automatically on agency initialization.
2

Create Project Structure

When you run the create-agent-template command, it creates the following folder structure for your agent:
Agent Folder Structure:
This structure ensures that each agent has its dedicated space with all necessary files to start working on its specific tasks.Agency Folder Structure:The full structure of the project will look like this:
3

Create Tools

You have 2 ways of defining custom tools:my_custom_tool.py:
my_custom_tool_class.py:
BaseTool classes support async def run(...), which is preferred for I/O-bound tools.See Custom Tools for full patterns.
4

Define Agent Roles

Adjust the parameters and instructions for each agent.developer.py:
model and reasoning are both set explicitly in this configuration.
instructions.md:
5

Create Agency

Import your agents and initialize the Agency class.agency.py:
The first positional argument is the entry point agent that users interact with directly. Communication flows are defined separately.
In Agency Swarm, communication flows are directional. For instance, in the example above: ceo > developer, the CEO can initiate a chat with the Developer, and the Developer can respond in this chat. However, the Developer cannot initiate a chat with the CEO.
See Communication Flows for multi-agent setups.
6

Run Demo

There are multiple ways to run the demo. Add one of the following to your agency.py file:Backend Version (Async):
Terminal Version:
The first run downloads the matching terminal UI automatically.
Web Interface:
Backend Version (Sync):

Next Steps