From Scratch
Quick start guide to building an Agency from scratch.
Set Your OpenAI Key
Begin by setting your OpenAI API key.
Alternatively, you can set the API key in the .env
file.
Create Project Structure
Use the create-agent-template
command to create the recommended directory structure for each agent.
Command Syntax:
Agent Folder Structure:
When you run the create-agent-template command, it creates the following folder structure for your agent:
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 Tools
Define your custom tools by extending the BaseTool
class and implementing the run
method.
MyCustomTool.py:
Define Agent Roles
Adjust the parameters and instructions for each agent.
Developer.py:
Tools will be imported automatically from the tools
folder.
instructions.md:
Create Agency
Import your agents and initialize the Agency class.
agency.py:
Any agents that are listed in the same list (e.g., [[ceo, developer]]
) can communicate with each other. The top-level list ([ceo]
) defines agents that can communicate with the user.
In Agency Swarm, communication flows are directional, meaning they are established from left to right in the agency_chart
definition. For instance, in the example above, the CEO can initiate a chat with the Developer (developer
), and the Developer can respond in this chat. However, the Developer cannot initiate a chat with the CEO.
Run Demo
There are three ways to run the demo. Add one of the following lines to your agency.py
file:
Web Interface:
Terminal Version:
Backend Version:
Next Steps
- Learn the core concepts of Tools, Agents, and Agencies.
- Watch the Deployment Tutorial.