VRSEN/agency-swarm

Reliable Multi-Agent Orchestration Framework

Agency Swarm is a Python framework for building applications that use multiple AI agents working together as a team. It's built on top of OpenAI's Agents SDK and adds an orchestration layer that lets you define agents with specific roles (like a CEO or a developer), give them custom tools, and control how they communicate with each other.

Core idea: Model AI automation like a real company. You define roles, assign tools and instructions to each role, and set up directional communication flows (e.g., "the CEO agent can initiate chats with the developer agent").

Key features:

  • Custom agent roles — Define agents with distinct names, descriptions, instructions, and tools (e.g., CEO, Virtual Assistant, Developer).
  • Full control over instructions — You write each agent's guiding prompts yourself.
  • Type-safe tools — Tools are defined with Pydantic models so arguments are automatically validated. Three ways to create them: a @function_tool decorator, a BaseTool class, or converting OpenAPI schemas via ToolFactory.
  • Orchestrated communication — Agents talk through a built-in send_message tool, and you control who can initiate conversations with whom using communication_flows (the > operator means "can initiate chat with").
  • State persistence — You can provide load_threads_callback and save_threads_callback functions to save/restore conversation history across sessions (e.g., to a database or file).
  • Production-ready focus — Designed for reliability and real-world deployment.

Installation & compatibility:

  • Install with pip install -U agency-swarm.
  • Requires Python 3.12+.
  • Works on macOS, Linux, and Windows.
  • Model backends: OpenAI's Responses API (default model is gpt-6-luna), or via LiteLLM for Anthropic (Claude), Google (Gemini), Grok (xAI), Azure OpenAI, and OpenRouter.

How you use it (5 steps):

  1. Set your OpenAI key — Put OPENAI_API_KEY=your_key in a .env file or export it in your shell.
  2. Create tools — Write Python functions decorated with @function_tool, or subclass BaseTool, or import tools from OpenAPI schemas.
  3. Define agent roles — Instantiate Agent objects with name, description, instructions (can be a file), folders for files/schemas, tools, and model settings.
  4. Define communication flows — Create an Agency object, list your agents, and specify directional flows like ceo > dev (CEO can initiate chat with Developer). You can also add a shared instructions file (e.g., agency_manifesto.md).
  5. Run it — Three ways: agency.copilot_demo() (web UI), agency.tui() (terminal), or await agency.get_response(...) (programmatic, async). A sync version get_response_sync also exists.

Project structure: A recommended folder layout has an optional shared manifesto file and one folder per agent containing files/, schemas/, tools/, the agent definition file, an __init__.py, and an instructions.md. A CLI command (agency-swarm create-agent-template) generates this structure for you.

Extras: The README links to docs on observability, a CLI workflow, and a starter template. It's MIT-licensed and open-source. The author also offers a paid "Agents-as-a-Service" subscription for businesses wanting custom agent swarms.

Note: There's a migration guide for users coming from the older v0.x version, and a separate v2 beta migration note.

Related

  • Project
  • Project
  • Project
  • Project
  • Project