Use this guide when you need to build everything manually. Otherwise, start from the Starter Template.
Set Your OpenAI Key
Begin by setting your OpenAI API key in the
.env file. It will be loaded automatically on agency initialization.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:
Create the folder with the CLI
Create the folder with the CLI
Create Tools
You have 2 ways of defining custom tools:my_custom_tool.py:
BaseTool classes support
Preferred: BaseTool class version
Preferred: BaseTool class version
my_custom_tool_class.py:
async def run(...), which is preferred for I/O-bound tools.See Custom Tools for full patterns.Define Agent Roles
Adjust the parameters and instructions for each agent.developer.py:
instructions.md:
model and reasoning are both set explicitly in this configuration.Alternative: load tools/files/schemas from folders
Alternative: load tools/files/schemas from folders
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.See Communication Flows for multi-agent setups.
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.Next Steps
- Learn the core concepts: Tools Overview, Agents Overview, and Agencies Overview.
- Run your first end-to-end flow with Running an Agency.
- Deploy your project with Deployment to Production.