Agency in Agency Swarm is a collection of agents that can collaborate with one another.

Benefits of Using an Agency

Utilizing an Agency consisting of multiple agents offers several benefits:

Fewer Hallucinations

Agents within an agency can supervise each other, reducing mistakes and handling unexpected scenarios more effectively.

Complex Tasks

Adding more agents allows for longer sequences of actions, enabling the completion of more complex tasks before delivering results to the user.

Scalability

Agencies allow you to scale your solutions seamlessly by adding more agents, as the complexity of your system grows.

Start with a minimal number of agents. Fine-tune them to ensure they function correctly before adding more. Introducing too many agents initially can make debugging and understanding interactions challenging.

Agency Parameters

Overview of parameters in Agency class:

NameParameterDescription
Agency Chartagency_chartA list that defines the hierarchy and interaction patterns between agents. It specifies:
1. Individual agents that can interact with users
2. Agent pairs that can communicate with each other

Example: [agent1, [agent1, agent2]]
- agent1 has user interaction permissions
- agent1 can communicate with agent2
Shared Instructions (optional)shared_instructionsPath to a file containing instructions shared across all agents. Can be a relative path from the agency’s folder or an absolute path. Default: empty string
Shared Files (optional)shared_filesPath to a folder or list of folders containing files accessible by all agents. These files are added to each agent’s files folder. Default: None
Async Mode (optional)async_modeSpecifies the asynchronous processing mode. Options:
- "threading": All sub-agents run in separate threads
- "tools_threading": All tools run in separate threads, but agents do not
Default: None
Settings Path (optional)settings_pathPath to the JSON settings file for the agency. If file doesn’t exist, it will be created. Default: "./settings.json"
Settings Callbacks (optional)settings_callbacksDictionary containing functions to load and save settings. Must include both "load" and "save" functions. Both functions must be defined. Default: None
Threads Callbacks (optional)threads_callbacksDictionary containing functions to load and save threads. Must include both "load" and "save" functions. Both functions must be defined. Default: None
Temperature (optional)temperatureControls response randomness (0.0 to 1.0). Agent-specific values override this. Lower values make responses more focused and deterministic. Default: 0.3
Top P (optional)top_pAlternative to temperature for controlling response randomness (0.0 to 1.0). Agent-specific values override this. Default: 1.0
Max Prompt Tokens (optional)max_prompt_tokensMaximum tokens allowed in the prompt for each agent. Agent-specific values override this. Default: None
Max Completion Tokens (optional)max_completion_tokensMaximum tokens allowed in the completion for each agent. Agent-specific values override this. Default: None
Truncation Strategy (optional)truncation_strategyDictionary configuring how to handle token limits. Agent-specific values override this. See OpenAI documentation for details. Default: None

Example

Quick example of how to create an agency with 3 agents:

from agency_swarm import Agency
from .ceo import CEO
from .developer import Developer
from .virtual_assistant import VirtualAssistant

ceo = CEO()
dev = Developer()
va = VirtualAssistant()

agency = Agency([
    ceo, dev  # CEO and Developer 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
])

Next Steps

Make sure to learn more about Communication Flows, Agency Parameters, and Running an Agency.