Open Swarm is a Python framework for creating, managing, and deploying autonomous agent swarms. It leverages the openai-agents
library for core agent functionality and provides a structured way to build complex, multi-agent workflows using Blueprints.
Open Swarm can be used in two primary ways:
swarm-cli
): Manage, run, and install blueprints directly on your local machine. Ideal for personal use, testing, and creating standalone agent tools. (Recommended installation: PyPI)swarm-api
): Deploy a web server that exposes your blueprints via an OpenAI-compatible REST API. Ideal for integrations, web UIs, and shared access. (Recommended deployment: Docker)--notify
)--image
, -i
)--view
, -v
--config
, -c
--writable-root
, -w
)--no-project-doc
)--full-stdout
)--dangerously-auto-approve-everything
)completion <bash|zsh|fish>
)--full-context
, -f
)openai-agents
SDK.BlueprintBase
subclasses) defining a swarm's structure, agents, coordination logic, and external dependencies (like required environment variables or MCP servers). They act as reusable templates for specific tasks (e.g., code generation, research, data analysis).swarm_config.json
): A central JSON file defining available LLM profiles (API keys, models) and configurations for MCP servers. Typically managed via swarm-cli
in ~/.config/swarm/
.swarm-cli
: A command-line tool for managing blueprints (adding, listing, running, installing) and the swarm_config.json
file. Uses XDG directories for storing blueprints (~/.local/share/swarm/blueprints/
) and configuration (~/.config/swarm/
).swarm-api
: A launcher for the Django/DRF backend that exposes installed blueprints via an OpenAI-compatible REST API (/v1/models
, /v1/chat/completions
).pip install open-swarm
This will install the swarm-cli
and swarm-api
command-line tools to your PATH (typically ~/.local/bin/
for user installs).
swarm-cli --help
or swarm-api --help
to verify installation.Clone the repository and install in editable mode:
git clone https://github.com/matthewhand/open-swarm.git
cd open-swarm
pip install -e .
swarm-cli
and swarm-api
available from your local copy. Changes to the code are immediately reflected.swarm-cli --help
swarm-api --help
If you do not see the commands in your PATH, ensure ~/.local/bin
is in your PATH:
export PATH="$HOME/.local/bin:$PATH"
Open Swarm uses a modern, XDG-compliant config structure:
~/.config/swarm/swarm_config.json
~/.config/swarm/.env
swarm_config.json.example
(in project root)cp ./swarm_config.json ~/.config/swarm/swarm_config.json
cp .env ~/.config/swarm/.env
Your swarm_config.json
can include rich LLM profiles, MCP server definitions, and blueprint metadata. Example:
{
"llm": {
"default": {
"provider": "openai",
"model": "${LITELLM_MODEL}",
"base_url": "${LITELLM_BASE_URL}",
"api_key": "${LITELLM_API_KEY}"
},
...
},
"mcpServers": {
"git": {
"description": "Provides Git operations via Docker.",
"command": "docker",
"args": ["run", "--rm", ...]
},
...
},
"blueprints": {
"defaults": { "max_llm_calls": 10 },
"MyBlueprint": { "llm_profile": "default" }
}
}
${ENV_VAR}
in the config and stored in .env
.swarm-cli
swarm-cli
to add/edit/remove/list:
~/.config/swarm/.env
, not in the JSON.Open Swarm and its blueprints use a variety of environment variables for configuration, security, and integration with external services. Set these in your shell, .env
file, Docker environment, or deployment platform as appropriate.
Variable | Description | Default / Required |
---|---|---|
OPENAI_API_KEY | API key for OpenAI LLMs (used by agents and blueprints) | Required for OpenAI usage |
SWARM_API_KEY | API key for securing API endpoints (swarm-api) | Optional (recommended) |
LITELLM_BASE_URL | Override base URL for LiteLLM/OpenAI-compatible endpoints | Optional |
LITELLM_API_KEY | API key for LiteLLM endpoints | Optional |
SWARM_CONFIG_PATH | Path to the main Swarm config file (swarm_config.json ) | ../swarm_config.json |
BLUEPRINT_DIRECTORY | Directory containing blueprint files | src/swarm/blueprints |
DJANGO_SECRET_KEY | Django secret key (for API mode) | Auto-generated/dev default |
DJANGO_DEBUG | Enable Django debug mode | True |
DJANGO_ALLOWED_HOSTS | Comma-separated allowed hosts for Django API | localhost,127.0.0.1 |
API_AUTH_TOKEN | Token for authenticating API requests | Optional |
DJANGO_LOG_LEVEL | Log level for Django app | INFO |
SWARM_LOG_LEVEL | Log level for Swarm app | DEBUG |
REDIS_HOST | Host for Redis (if used) | localhost |
REDIS_PORT | Port for Redis (if used) | 6379 |
DJANGO_CSRF_TRUSTED_ORIGINS | Comma-separated trusted origins for CSRF protection | http://localhost:8000,... |
ENABLE_ADMIN | Enable admin web interface | false |
ENABLE_API_AUTH | Require API authentication | true |
export OPENAI_API_KEY="sk-..."
export SWARM_API_KEY="..."
export LITELLM_BASE_URL="https://open-litellm.fly.dev/v1"
# ... set other variables as needed
Open Swarm ships with a growing toolbox of agent and blueprint utilities. All features listed below have robust, passing tests unless marked as WIP (Work In Progress).
at
:
at
command).at
jobs:
at
.at
jobs:
cron
:
crontab
).cron
jobs:
crontab
.cron
jobs:
/help
, /agent
, /model
)./help
, /agent
, /model
.from swarm.extensions.blueprint.slash_commands import slash_command_registry
@slash_command_registry.register('/hello')
def hello_command(args):
return f"Hello, {args}!"
from swarm.extensions.task_scheduler_toolbox import schedule_at_job, list_at_jobs, remove_at_job
job_id = schedule_at_job('/path/to/script.sh', run_time='now + 5 minutes')
jobs = list_at_jobs()
remove_at_job(job_id)
Usage: swarm-cli [OPTIONS] COMMAND [ARGS]...
Swarm CLI tool for managing blueprints.
Options:
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it or customize the installation.
--help Show this message and exit.
Commands:
install Install a blueprint by creating a standalone executable using PyInstaller.
launch Launch a previously installed blueprint executable.
list Lists available blueprints (bundled and user-provided) and/or installed executables.
# (No standalone swarm-api binary was found in dist/; see Docker/API section below for usage.)
swarm-cli
Locally (via PyPI)This is the recommended way to use swarm-cli
for managing and running blueprints on your local machine.
Prerequisites:
pip
(Python package installer)Steps:
Install open-swarm
from PyPI:
pip install open-swarm
(Using a virtual environment is recommended: python -m venv .venv && source .venv/bin/activate
)
Initial Configuration (First Run):
swarm-cli
command that requires configuration (like run
or config
), it will automatically create a default swarm_config.json
at ~/.config/swarm/swarm_config.json
if one doesn't exist.OPENAI_API_KEY
) in your shell for the configuration to work. Create a .env
file in your working directory or export them:
export OPENAI_API_KEY="sk-..."
# Add other keys as needed (GROQ_API_KEY, etc.)
swarm-cli config
commands (see USERGUIDE.md
).Add a Blueprint:
my_blueprint.py
). Example blueprints are available in the project repository.swarm-cli
:
# Example: Adding a downloaded blueprint file
swarm-cli add ./path/to/downloaded/blueprint_echocraft.py
# Example: Adding a directory containing a blueprint
swarm-cli add ./my_custom_blueprints/agent_smith --name agent_smith
Run the Blueprint:
swarm-cli run echocraft --instruction "Hello from CLI!"
swarm-cli run echocraft
# Now you can chat with the blueprint interactively
(Optional) Install as Command:
swarm-cli install echocraft
# Now run (ensure ~/.local/share/swarm/bin is in your PATH):
echocraft --instruction "I am a command now!"
swarm-api
Service (via Docker)This section covers deploying the API service using Docker.
This method uses docker-compose.yaml
and is best if you need to customize volumes, environment variables easily, or manage related services (like Redis).
Prerequisites:
Steps:
Clone the Repository: (Needed for docker-compose.yaml
and config files)
git clone https://github.com/matthewhand/open-swarm.git
cd open-swarm
Configure Environment:
cp .env.example .env
and edit .env
with your API keys (e.g., OPENAI_API_KEY
, SWARM_API_KEY
).Prepare Blueprints & Config:
./blueprints
../swarm_config.json
exists and is configured.Configure Overrides (Optional):
cp docker-compose.override.yaml.example docker-compose.override.yaml
.Start the Service:
docker compose up -d
Verify API: (Default port 8000)
curl http://localhost:8000/v1/models
curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "echocraft", ...}'
(Add -H "Authorization: Bearer <key>"
if needed).docker run
(Simpler for Single Container)This method runs the pre-built image directly from Docker Hub. Good for quick tests or simple deployments without cloning the repo. Customization requires careful use of -v
(volume) and -e
(environment) flags.
Prerequisites:
Steps:
Prepare Local Files (If Customizing):
~/my_swarm_blueprints
).swarm_config.json
file locally (e.g., ~/my_swarm_config.json
)..env
file locally (e.g., ~/swarm.env
) with your API keys (OPENAI_API_KEY
, SWARM_API_KEY
, etc.).Run the Container:
docker run -d \
--name open-swarm-api \
-p 8000:8000 \
--env-file ~/swarm.env \
-v ~/my_swarm_blueprints:/app/blueprints:ro \
-v ~/my_swarm_config.json:/app/swarm_config.json:ro \
-v open_swarm_db:/app/db.sqlite3 \
--restart unless-stopped \
mhand79/open-swarm:latest
-d
: Run detached (in background).--name
: Assign a name to the container.-p 8000:8000
: Map host port 8000 to container port 8000 (adjust if needed).--env-file
: Load environment variables from your local file.-v ...:/app/blueprints:ro
: Mount your local blueprints directory (read-only). Required if you want to use custom blueprints.-v ...:/app/swarm_config.json:ro
: Mount your local config file (read-only). Required for custom LLM/MCP settings.-v open_swarm_db:/app/db.sqlite3
: Use a named Docker volume for the database to persist data.--restart unless-stopped
: Automatically restart the container unless manually stopped.mhand79/open-swarm:latest
: The image name on Docker Hub.Verify API: (Same as Docker Compose)
curl http://localhost:8000/v1/models
curl http://localhost:8000/v1/chat/completions ...
(Add -H "Authorization: Bearer <key>"
if needed).swarm-api
(via Docker or manage.py runserver
): Exposes blueprints as an OpenAI-compatible REST API. Ideal for integrations. Requires SWARM_API_KEY
for security in non-local deployments.swarm-cli run
(via PyPI install): Executes managed blueprints locally, either with a single instruction or in interactive chat mode. Good for testing and local tasks.swarm-cli install
(via PyPI install): Creates standalone command-line executables from managed blueprints.uv run python <blueprint_file.py>
is mainly for development and testing individual files.This README provides a high-level overview and quickstart guides. For more detailed information, please refer to:
USERGUIDE.md
): Detailed instructions on using swarm-cli
commands for managing blueprints and configuration locally.DEVELOPMENT.md
): Information for contributors and developers, including architecture details, testing strategies, project layout, API details, and advanced topics.src/swarm/blueprints/README.md
): A list and description of the example blueprints included with the framework, showcasing various features and integration patterns.Contributions are welcome! Please refer to the CONTRIBUTING.md
file (if available) or open an issue/pull request on the repository.
Open Swarm is provided under the MIT License. Refer to the LICENSE file for full details.
This project builds upon concepts and code from the openai-agents
library and potentially other open-source projects. Specific acknowledgements can be found in DEVELOPMENT.md
or individual source files.
{
"mcpServers": {
"git": {
"env": {},
"args": [
"run",
"--rm"
],
"command": "docker"
}
}
}
Seamless access to top MCP servers powering the future of AI integration.