git, curl, or gh, you already know how to use the Swarms CLI. This tutorial walks through every command in order, from a clean install to running a four-agent debate on a real task. By the end you’ll be productive without ever leaving the terminal.
We’ll cover:
- Installing and verifying the CLI
- Scaffolding a project with
swarms init - Talking to a single agent with
swarms chat - Running one-shot tasks with
swarms agent - Discovering models with the new
swarms modelscommand - Auto-generating swarms with
swarms autoswarm - Running deep multi-agent analyses with
swarms heavy-swarmandswarms llm-council - Loading whole teams from YAML and markdown files
- Power-user tricks: streaming, autosave, MCP servers, environment scoping
- The rotating
swarms tipsengine and how to use it - Recovering from errors — the CLI’s built-in classifier and typo-corrector
1. Install and Verify
The CLI ships with the main package. One line installs both:swarms with no command prints the banner and then a usage error, because a command is required.)
⚡ Pro tip, 🪄 Hint, etc.) rotate on every invocation. They are not noise — they surface real CLI capabilities you might have missed.
2. Scaffold a Project: swarms init
init is the interactive wizard. It walks you through:
- Picking a project directory
- Picking a
WORKSPACE_DIR(where agents read and write files) - Adding API keys for the providers you pick from a numbered list (and, optionally, a
SWARMS_API_KEY) - Writing a
.envfile - Validating the result
.env in the project directory. When it finishes you’ll have:
<project_dir>/.env— your API keys<project_dir>/workspace/— the workspace directory
setup-check passes, suggesting your real first command (usually swarms chat).
To verify the environment at any time:
.env and WORKSPACE_DIR exist. The checks are local — no provider is contacted, so an invalid key still passes.
3. Your First Conversation: swarms chat
The fastest way to talk to a model:
gpt-5.1 (change it with --model-name) with autonomous looping enabled (max_loops="auto") and drops you into an interactive REPL. Responses print once each is complete — swarms chat does not enable streaming or autosave by default. Type exit, quit, bye, or q, or press Enter on an empty line, to leave the session.
Customize the persona:
--task flag seeds the first message; from there the conversation is interactive.
4. One-Shot Agents: swarms agent
When you don’t want a REPL — say, in a shell script or CI job — use swarms agent:
Combine
--streaming-on --verbose to watch the model think token by token.
5. Discover Models: swarms models
Before you change --model-name, you need to know what to put there. The CLI ships a model-discovery command backed by the LiteLLM registry, so the list stays current as providers ship new models.
List every model, grouped by provider:
difflib fuzzy matches):
--info command suggests the closest matches.
6. Auto-Generate a Swarm: swarms autoswarm
Don’t know which architecture fits your task? Let the CLI design one:
--no-run to inspect the file before running:
7. Heavy Analysis: swarms heavy-swarm
For research-grade depth, heavy-swarm decomposes the task into specialist questions, dispatches them to multiple worker agents in parallel, then synthesizes a final answer:
8. Multi-Model Debate: swarms llm-council
llm-council runs the same task across four council members — gpt-5.1, gemini-2.5-flash, anthropic/claude-sonnet-4-5, and xai/grok-4-1-fast-reasoning — which then review and rank each other’s anonymized answers. You need OpenAI, Google, Anthropic, and xAI keys for the default council. It’s the right shape when you want disagreement surfaced — adversarial verification, due-diligence reviews, or “is this consensus actually consensus?” questions:
9. Load a Team from a File
For repeatable workflows, define agents in a YAML or markdown file and load them with one command. YAML —agents.yaml:
.md file with YAML frontmatter:
Unsupported file type, so load one file at a time. Markdown files are still a good format for a library of reusable agents — each file is self-describing and easy to share via git.
10. The tips Engine
The CLI ships with 83 categorized tips covering every command and flag. The banner rotates one per invocation, but you can also pull them on demand:
commands, agents, swarms, models, pro, trivia, env, community. Use swarms tips --all to dump every tip in every category — useful as a cheat-sheet to print and pin next to your terminal.
The prefix labels (⚡ Pro tip:, 💡 Did you know:, 🪄 Hint:, 🔥 Hot tip:, and four others) are randomized per render. It’s intentional — varied prefixes catch your eye when a tip is genuinely useful.
11. Power-User Tricks
A few patterns that pay off in real use: Pass a file’s contents as the task: the CLI does not read stdin, so expand the file in your shell:swarms loads the nearest .env, searching upward from the current directory, so each project directory can carry its own keys. Variables already exported in your shell win over the file.
Long autonomous loops inside tmux: detach with Ctrl-b d and the agent keeps running; reattach later to see the result.
Watch a model think:
--saved-state-path is a write target only — nothing in the CLI loads it back on a later run, so pointing a new invocation at the same path does not resume the earlier session. A relative path is written inside the agent’s workspace directory, $WORKSPACE_DIR/agents/<agent-name>-<id>/.
Cap context for long sessions:
12. Errors and Recovery
When something goes wrong, the CLI doesn’t just dump a stack trace. It classifies the error and prints targeted recovery hints:- A
401 Unauthorizedfrom a provider → “Runswarms initorswarms get-api-key” - A
model_not_founderror → “Find a valid model withswarms models --search <name>” - A missing
WORKSPACE_DIR→ “Runswarms initto scaffold one” - A
429 RateLimit→ “Slow down, use a smaller--model-name, or retry in a minute” - A network timeout → “Run
swarms setup-check --verboseto validate connectivity” - A
ModuleNotFoundError→ “Tryswarms upgradeorpip install -U swarms”
difflib.get_close_matches against the command list, so corrections work even for two-character typos.
13. Where to Go Next
You now have everything you need for daily use. A few directions to grow into:- Build a reusable agent library — Use markdown frontmatter to define agents once and load them from any project with
swarms load-markdown. - Compose pipelines as YAML —
swarms run-agents --yaml-filelets you commit the entire workflow to git. - Wire MCP tools — Any tool exposed via an MCP server (filesystem, web search, database) becomes available to any agent through
--mcp-url. - Read the API reference — When you’re ready to leave the CLI for Python code, most
swarms agentflags map to an Agent class parameter documented in the API Reference.
swarms init, then alternate between swarms chat for ideation and swarms agent --task '...' for one-shot work. Everything else — autoswarm, llm-council, YAML loading — composes from the same primitives once you’re comfortable with the basics.
Related
Commands Reference
Every command, every flag, with examples
Configuration
YAML, markdown, and environment configuration
Quickstart Tutorial
A hands-on multi-agent workflow you can build right now
API Reference
Map every CLI flag back to its Python API counterpart