Package: agency-swarm
🐝 Agency SwarmOverviewAgency Swarm started as a desire and effort of Arsenii Shatokhin (aka VRSEN) to fully automate his AI Agency with AI. By building this framework, we aim to simplify the agent creation process and enable anyone to create collaborative swarm of agents (Agencies), each with distinct roles and capabilities. By thinking about automation in terms of real world entities, such as agencies and specialized agent roles, we make it a lot more intuitive for both the agents and the users.Key FeaturesCustomizable Agent Roles: Define roles like CEO, virtual assistant, developer, etc., and customize their functionalities withAssistants API.Full Control Over Prompts: Avoid conflicts and restrictions of pre-defined prompts, allowing full customization.Tool Creation: Tools within Agency Swarm are created usingInstructor, which provides a convenient interface and automatic type validation.Efficient Communication: Agents communicate through a specially designed "send message" tool based on their own descriptions.State Management: Agency Swarm efficiently manages the state of your assistants on OpenAI, maintaining it in a specialsettings.jsonfile.Deployable in Production: Agency Swarm is designed to be reliable and easily deployable in production environments.Installationpipinstallagency-swarmGetting StartedSet Your OpenAI Key:fromagency_swarmimportset_openai_keyset_openai_key("YOUR_API_KEY")Create Tools:
Define your custom tools withInstructor:fromagency_swarm.toolsimportBaseToolfrompydanticimportFieldclassMyCustomTool(BaseTool):"""A brief description of what the custom tool does.The docstring should clearly explain the tool's purpose and functionality."""# Define the fields with descriptions using Pydantic Fieldexample_field:str=Field(...,description="Description of the example field, explaining its purpose and usage.")# Additional fields as required# ...defrun(self):"""The implementation of the run method, where the tool's main functionality is executed.This method should utilize the fields defined above to perform its task.Doc string description is not required for this method."""# Your custom tool logic goes heredo_something(self.example_field)# Return the result of the tool's operationreturn"Result of MyCustomTool operation"or convert from OpenAPI schemas:# using local filewithopen("schemas/your_schema.json")asf:ToolFactory.from_openapi_schema(f.read(),)# using requestsToolFactory.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.fromagency_swarmimportAgentceo=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.mdfiles_folder="./files",# files to be uploaded to OpenAIschemas_folder="./schemas",# OpenAPI schemas to be converted into toolstools=[MyCustomTool,LangchainTool])Import from existing agents (will be deprecated in future versions):fromagency_swarm.agents.browsingimportBrowsingAgentbrowsing_agent=BrowsingAgent()browsing_agent.instructions+="\n\nYou can add additional instructions here."Define Agency Communication Flows:
Establish how your agents will communicate with each other.fromagency_swarmimportAgencyagency=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 agentsIn 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.",yield_messages=False)CLIGenesis AgencyThegenesiscommand starts the genesis agency in your terminal to help you create new agencies and agents.Command Syntax:agency-swarmgenesis[--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.Creating Agent Templates LocallyThis CLI command simplifies the process of creating a structured environment for each agent.Command Syntax:agency-swarmcreate-agent-template--name"AgentName"--description"Agent Description"[--path"/path/to/directory"][--use_txt]Folder StructureWhen you run thecreate-agent-templatecommand, 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 agentThis structure ensures that each agent has its dedicated space with all necessary files to start working on its specific tasks. Thetools.pycan be customized to include tools and functionalities specific to the agent's role.Future EnhancementsCreation of agencies that can autonomously create other agencies.Asynchronous communication and task handling.Inter-agency communication for a self-expanding system.ContributingFor details on how to contribute you agents and tools to Agency Swarm, please refer to theContributing Guide.LicenseAgency Swarm is open-source and licensed underMIT.Need Help?If you require assistance in creating custom agents for your business, feel free to reach out through my website:vrsen.aior schedule a consultation athttps://calendly.com/vrsen/ai-project-consultation