This release is a pre-release and may not be stable for production use.
🐝 Agency Swarm
Overview
The Agency Swarm Framework is an advanced system for building multi-agent applications. It leverages and extends the foundational capabilities of the OpenAI Agents SDK, providing specialized features for creating, orchestrating, and managing collaborative swarms of AI agents.
By default, Agency Swarm is built on the OpenAI Responses API to handle complex, multi-turn interactions, with examples/chat_completion_provider.py being the only exception that uses the Chat Completions API.
Observability tracking via Langfuse and AgentOps is demonstrated in examples/observability_demo.py.
See examples/README.md for a full list of runnable demos.
Agency Swarm enhances the underlying SDK by introducing:
- True agent collaboration with flexible, user-defined communication flows (orchestrator-workers pattern with async execution support).
- An
Agencythat uses anagency_chartto define complex communication flows and interaction patterns between agents. - Flexible conversation persistence: Manage conversation history by providing
load_threads_callbackandsave_threads_callbackfunctions to theAgency, enabling threads to be loaded from and saved to external storage (e.g., a database). This allows conversations to continue across sessions, which is essential for production environments. - A specialized
send_messagetool automatically configured for agents, enabling them to communicate based on the definedagency_chart. agency_swarm.Agentwhich extends the base SDKAgentwith built-in file handling and sub-agent registration capabilities.
This framework continues the original vision of Arsenii Shatokhin (aka VRSEN) to simplify the creation of sophisticated AI agencies by thinking about automation in terms of real-world organizational structures.
Migrating from v0.x? Please see our Migration Guide for details on adapting your project to this new SDK-based version.
Key Features
- Customizable Agent Roles: Define distinct agent roles (e.g., CEO, Developer) with tailored instructions, tools, and capabilities within the Agency Swarm framework, leveraging the underlying OpenAI Agents SDK.
- Full Control Over Agent Instructions: Maintain complete control over each agent's guiding prompts (instructions) for precise behavior customization.
- Type-Safe Tools: Develop robust tools using Pydantic models for automatic argument validation, compatible with the OpenAI Agents SDK's
FunctionToolformat. - Orchestrated Agent Communication: Agents communicate via a dedicated
send_messagetool, with interactions governed by anagency_chartthat defines allowed communication pathways within theAgency. - Flexible State Persistence: Manage conversation history by providing
load_threads_callbackandsave_threads_callbackfunctions to theAgency. This allows for loading and saving conversation threads to external storage, enabling persistence across sessions. - Robust Multi-Agent Orchestration: Build complex and reliable agent workflows by leveraging the OpenAI Agents SDK foundation, enhanced by Agency Swarm's structured orchestration layer.
Installation
Stable Version (v0.x)
pip install -U agency-swarm
Beta Version (v1.x - OpenAI Agents SDK Based)
pip install -U "agency-swarm>=1.0.0-beta"
Note: The v1.x beta represents a major architectural change built on the OpenAI Agents SDK. While feature-complete and functional, it's marked as beta for wider testing before becoming the default version. See our Migration Guide for details on migrating from v0.x to v1.x.
Getting Started
-
Set Your OpenAI Key:
from agency_swarm import set_openai_key set_openai_key("YOUR_API_KEY")
-
Create Tools: Define your custom tools by extending the
BaseToolclass:from agency_swarm.tools import BaseTool from pydantic import Field class MyCustomTool(BaseTool): """ A brief description of what the custom tool does. The docstring should clearly explain the tool's purpose and functionality. It will be used by the agent to determine when to use this tool. """ # Define the fields with descriptions using Pydantic Field example_field: str = Field( ..., description="Description of the example field, explaining its purpose and usage for the Agent." ) # Additional fields as required # ... def run(self): """ The implementation of the run method, where the tool's main functionality is executed. """ # Your custom tool logic goes here do_something(self.example_field) # Return the result of the tool's operation return "Result of MyCustomTool operation"
or convert from OpenAPI schemas:
from agency_swarm.tools import ToolFactory # using local file with open("schemas/your_schema.json") as f: tools = ToolFactory.from_openapi_schema( f.read(), ) # using requests tools = ToolFactory.from_openapi_schema( requests.get("https://api.example.com/openapi.json").json(), )
-
Define Agent Roles: Start by defining the roles of your agents. For example, a CEO agent for managing tasks and a developer agent for executing tasks.
from agency_swarm import Agent ceo = Agent( name="CEO", description="Responsible for client communication, task planning and management.", instructions="You must converse with other agents to ensure complete task execution.", # can be a file like ./instructions.md files_folder="./files", # files to be uploaded to OpenAI schemas_folder="./schemas", # OpenAPI schemas to be converted into tools tools=[MyCustomTool], temperature=0.3, # temperature for the agent max_prompt_tokens=25000, # max tokens in conversation history )
Import from existing agents:
agency-swarm import-agent --name "Devid" --destination "./"
This will import Devid (Software Developer) Agent locally, including all source code files, so you have full control over your system. Currently, available agents are:
Devid,BrowsingAgent. -
Define Agency Communication Flows: Establish how your agents will communicate with each other.
from agency_swarm import Agency # if importing from local files from Developer import Developer from VirtualAssistant import VirtualAssistant dev = Developer() va = VirtualAssistant() agency = Agency([ ceo, # CEO will be the entry point for communication with the user [ceo, dev], # CEO can initiate communication with Developer [ceo, va], # CEO can initiate communication with Virtual Assistant [dev, va] # Developer can initiate communication with Virtual Assistant ], shared_instructions='agency_manifesto.md', # shared instructions for all agents temperature=0.3, # default temperature for all agents max_prompt_tokens=25000 # default max tokens in conversation history )
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 (dev), and the developer can respond in this chat. However, the developer cannot initiate a chat with the CEO. The developer can initiate a chat with the virtual assistant (va) and assign new tasks.
-
Run Demo: Run the demo to see your agents in action!
Web interface:
agency.demo_gradio(height=900)
Terminal version:
agency.run_demo()
Backend version:
completion_output = agency.get_completion("Please create a new website for our client.")
CLI
Genesis Agency
The genesis command starts the genesis agency in your terminal to help you create new agencies and agents.
Command Syntax:
agency-swarm genesis [--openai_key "YOUR_API_KEY"]
Make sure to include:
- Your mission and goals.
- The agents you want to involve and their communication flows.
- Which tools or APIs each agent should have access to, if any.
Importing Existing Agents
This CLI command allows you to import existing agents from local files into your agency.
Command Syntax:
agency-swarm import-agent --name "AgentName" --destination "/path/to/directory"
To check available agents, simply run this command without any arguments.
Creating Agent Templates Locally
This CLI command simplifies the process of creating a structured environment for each agent.
Command Syntax:
agency-swarm create-agent-template --name "AgentName" --description "Agent Description" [--path "/path/to/directory"] [--use_txt]
Folder Structure
When you run the create-agent-template command, it creates the following folder structure for your agent:
/your-specified-path/
│
├── agency_manifesto.md or .txt # Agency's guiding principles (created if not exists)
└── AgentName/ # Directory for the specific agent
├── files/ # Directory for files that will be uploaded to openai
├── schemas/ # Directory for OpenAPI schemas to be converted into tools
├── tools/ # Directory for tools to be imported by default.
├── AgentName.py # The main agent class file
├── __init__.py # Initializes the agent folder as a Python package
├── instructions.md or .txt # Instruction document for the agent
└── tools.py # Custom tools specific to the agent's role.
This structure ensures that each agent has its dedicated space with all necessary files to start working on its specific tasks. The tools.py can be customized to include tools and functionalities specific to the agent's role.
Future Enhancements
- Creation of agencies that can autonomously create other agencies.
- Asynchronous communication and task handling.
- Inter-agency communication for a self-expanding system.
Contributing
For details on how to contribute you agents and tools to Agency Swarm, please refer to the Contributing Guide.
License
Agency Swarm is open-source and licensed under MIT.
Need Help?
If you need help creating custom agent swarms for your business, check out our Agents-as-a-Service subscription, or schedule a consultation with me at https://calendly.com/vrsen/ai-project-consultation
Metadata
Release files for agency-swarm 1.0.0b5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agency_swarm-1.0.0b5.tar.gz | 21.5 MB | Without provenance | Details for agency_swarm-1.0.0b5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agency_swarm-1.0.0b5-py3-none-any.whl | Python 3 | none | any | Details for agency_swarm-1.0.0b5-py3-none-any.whl |
Total release size: 21.6 MB
Release files / agency_swarm-1.0.0b5.tar.gz
| Download URL | agency_swarm-1.0.0b5.tar.gz |
|---|---|
| Size | 21.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77372f017482f9ef7522b25b8c12e966a70b832d7d31356b41b848674cee92fb
|
|
BLAKE2b-256 checksum How to use checksums |
9b624b8008c76ba0387e4b00d273d999f7fb0140f3fbe53109d007c5de25e0c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / agency_swarm-1.0.0b5-py3-none-any.whl
| Download URL | agency_swarm-1.0.0b5-py3-none-any.whl |
|---|---|
| Size | 105.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfeca610734ab501f052b610fca3d038be6e0adab68332280ed2c7fd0604f217
|
|
BLAKE2b-256 checksum How to use checksums |
b2911476e32373ae5928fd29a52c28ce2b4cda5867ebc6153e30448342a4aea6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for agency-swarm 1.0.0b5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.