This tutorial builds a working multi-agent workflow from scratch using only the CLI — no Python required until the final optional step. By the end you’ll have a reusable agent library, a YAML pipeline, and a one-command way to run it.You’ll build: a research → write → review pipeline that takes a topic and produces a polished briefing.Time: 15–20 minutes.Prerequisites: Python 3.10+, one provider API key (OpenAI or Anthropic).
The most ergonomic way to define a reusable agent is a markdown file with YAML frontmatter. Create three files inside an agents/ folder:agents/researcher.md
---name: Researcherdescription: Researches a topic thoroughly with citationsmodel_name: gpt-4otemperature: 0.2---You are a senior research analyst. Given a topic, produce a detailedresearch summary with these sections:1. **Context** — Why this topic matters right now (1 paragraph)2. **Key facts** — 5–7 bullet points with concrete numbers, dates, and named sources3. **Open questions** — What remains uncertain or contested4. **Citations** — Inline source attributions for every factual claimBe specific. Prefer numbers over adjectives.
agents/writer.md
---name: Writerdescription: Turns research into a concise polished briefingmodel_name: claude-opus-4-7temperature: 0.5---You are a writer for an executive briefing newsletter. Given researchnotes, produce a 400-word briefing with this structure:- **Lede** — One sentence that captures the entire story- **Body** — Three short paragraphs covering context, evidence, and stakes- **Takeaway** — One actionable sentence for a decision-makerUse plain language. Cut every word that doesn't earn its place.
agents/reviewer.md
---name: Reviewerdescription: Critiques the writing for accuracy, clarity, and concisionmodel_name: gpt-4otemperature: 0.1---You are a senior editor. Given a draft briefing and the source research,produce a critique with:1. **Accuracy issues** — Claims the draft makes that aren't supported by the research2. **Clarity issues** — Sentences a busy executive would skip3. **Specific rewrites** — Suggested replacement language for the weakest two paragraphs4. **Verdict** — "Ship", "Revise", or "Restart"
Confirm they load:
swarms load-markdown --markdown-path ./agents/
You should see a table listing all three agents with their models and descriptions.
Before chaining, sanity-check one agent in isolation:
swarms agent \ --name "Researcher" \ --description "Researches a topic thoroughly" \ --system-prompt "You are a senior research analyst. Produce a detailed summary with citations." \ --task "What's the current state of mRNA vaccine development for cancer?" \ --model-name "gpt-4o" \ --streaming-on
--streaming-on shows tokens arriving in real time so you can tell whether the agent is on track without waiting for the full response.
agents: - name: Researcher model_name: gpt-4o temperature: 0.2 system_prompt: | You are a senior research analyst. Given a topic, produce a detailed research summary with context, key facts (with citations), and open questions. - name: Writer model_name: claude-opus-4-7 temperature: 0.5 system_prompt: | You are a writer for an executive briefing newsletter. Turn the research notes into a 400-word briefing with a lede, three-paragraph body, and one-sentence takeaway. - name: Reviewer model_name: gpt-4o temperature: 0.1 system_prompt: | You are a senior editor. Given a draft briefing and the source research, return: accuracy issues, clarity issues, specific rewrites for the weakest paragraphs, and a verdict of Ship/Revise/Restart.swarm: type: SequentialWorkflow task: | Topic: How are large language models being used in drug discovery in 2026?
Run it:
swarms run-agents --yaml-file pipeline.yaml
Each agent receives the previous one’s output as context. The Researcher’s notes flow into the Writer’s brief, which flows into the Reviewer’s critique. Total cost on gpt-4o + claude-opus-4-7 will be a few cents.
The same agents can run as a Concurrent Workflow (all three see the same task in parallel) or as a Mixture of Agents (workers + aggregator). Try Concurrent for a different angle:
# pipeline-concurrent.yamlagents: - name: Optimist model_name: gpt-4o system_prompt: Argue the strongest case for the topic - name: Pessimist model_name: claude-opus-4-7 system_prompt: Argue the strongest case against the topic - name: Realist model_name: gpt-4o system_prompt: Provide a balanced analysis of the topicswarm: type: ConcurrentWorkflow task: | Should our R&D team adopt LLMs as a daily tool for protein design?
When you don’t know which architecture fits, let the CLI design one:
swarms autoswarm \ --task "Produce a competitive analysis of CRISPR-based cancer therapies in 2026" \ --model "gpt-4o" \ --no-run \ -o ./generated_swarm.py
--no-run writes the generated Python file without executing it, so you can inspect it first. Open generated_swarm.py — it’s plain swarms Python code you can edit, version-control, or rerun manually.To run it immediately, drop --no-run:
swarms autoswarm \ --task "Produce a competitive analysis of CRISPR-based cancer therapies in 2026" \ --model "gpt-4o"
For research-grade depth, heavy-swarm decomposes the task into specialist questions and runs each through a worker for multiple loops:
swarms heavy-swarm \ --task "What are the second-order economic effects of AI coding assistants on the software labor market over the next five years?" \ --loops-per-agent 3 \ --worker-model-name "claude-opus-4-7" \ --question-agent-model-name "gpt-4o" \ --verbose
This costs more (3 loops × N workers × 1 question-generator) but produces noticeably deeper output than a single LLM call. Use sparingly.
For long-running tasks (autonomous research, ongoing chat with memory), persist state to disk:
swarms agent \ --name "ProjectAssistant" \ --description "Remembers context across days" \ --system-prompt "You are a project assistant. Remember every fact I tell you." \ --task "My project is called Helios. The team has 4 engineers." \ --autosave \ --saved-state-path ./helios.json
The next time you run the same command pointing at ./helios.json, the agent picks up exactly where it left off — including everything you told it.