Multi-agent workflows: an RFQ-to-quote team¶
Run it, don't just read it
Every lab runs on your laptop with Ollama. Set up once (INSTALL), then:
git clone https://github.com/JSWOne/ai-learning.git && cd ai-learning
cd multi-agent && python 01_rfq_pipeline.py
Lab files and data: multi-agent/ on GitHub. In VS Code, open the repo folder and use Terminal > Run Task > Run this lab.
Small, runnable examples of several agents working on one job: a buyer's RFQ becomes a checked, approved quote and an email. Each numbered file shows one pattern. New to multi-agent? Read learn-multi-agent.md first: what it is and why, the mental model in code and diagrams, the labs in three stages, key decisions and advanced topics. Before you start: agents: every agent here is one of those, reused as-is. After it, you can: split work across agents, and know when not to. Done with the labs? Try the three exercises and the build-it-yourself task in PRACTICE.md.
It builds on ../agents: every agent here is the single agent from ../agents (agent.run()), with its own prompt and a few tools from the catalog MCP server from mcp-server. What's new is the part between agents: handoffs, routing, fan-out, review, one budget and one pause for the whole flow. Hand-rolled first (workflow.py); lab 07 rebuilds it in LangGraph.
Setup¶
Install steps for all topics are in ../INSTALL.md. This topic reuses ../agents and ../mcp-server (the root requirements.txt covers them). From the ai-learning folder:
source .venv/bin/activate # the one venv at ai-learning/ (see ../INSTALL.md section 4)
uv pip install -r requirements.lock # all topics, the tested versions
cd multi-agent && pytest -q && python 01_rfq_pipeline.py
Run every example from this folder. 05 and 07 use the catalog HTTP server: the first run starts it in the background and it keeps running between commands. Stop it (fresh stock and credit) with cd ../mcp-server && python -m b2b_catalog.http_app --stop. 01 asks for approval with input(), so run it in a terminal.
Files¶
Track: Core labs are the Core path through the course. Before you ship: safety lessons to do before anything you build goes to real users. Go further: when your work needs that pattern (see Use it when).
| File | Track | Pattern | Use it when | Time |
|---|---|---|---|---|
01_rfq_pipeline.py |
Core | Sequential pipeline: intake, pricing, approval policy, reply, with typed handoffs checked in code | The job has clear stages with different skills | ~2 min |
02_supervisor.py |
Go further | Supervisor routes each message to a specialist (RFQ team, order status, account, a person), with code guards | One inbox, many kinds of request | ~1-2 min |
03_parallel_lines.py |
Go further | Fan-out: one line agent per RFQ line in parallel, merged in code; one agent vs fan-out, timed | Independent sub-tasks; a long list a single agent drops items from | ~2 min |
04_critic.py |
Go further | Critic = code checks plus one narrow model question per quote line, measured on seeded faults, then in the loop: issues sent to their owner, one fix | Mistakes code can't see, like the wrong product at the right quantity | ~3 min |
05_pause_and_resume.py |
Go further | The whole workflow pauses for a manager, saves, resumes in a new process with re-checks | Approvals that come later, from someone else | ~2 min |
06_single_vs_multi.py |
Core | The agents topic's single agent vs this team on five RFQs, scored in code | Deciding whether to split at all | ~6-7 min |
07_langgraph.py |
Go further | The same workflow as a LangGraph graph: nodes, conditional edges, interrupt, SQLite | Deciding whether you need a framework | ~2 min |
Shared code:
| File | What it holds | Read? |
|---|---|---|
workflow/stages.py |
Workflow (save, load, decide), step(), run_workflow(): the stages wired together |
Read |
workflow/handoffs.py |
Rfq, QuoteHandoff, Approval, Review, Route: the typed contracts |
Read |
workflow/intake.py, pricing.py, approval.py, reply.py |
One file per stage: intake(), price_with_agent() / price_with_fanout(), approval_policy(), write_reply() |
Read with the lab that uses it |
workflow/review.py, supervisor.py |
The critic (review()), the router (route(), SPECIALISTS) |
Read with labs 04, 02 |
workflow/runners.py, ctx.py |
ask_json(), run_agent(); Ctx, ScopedTools, WorkflowBudget, Trace |
Skim |
workflow/data.py |
Sample RFQs with expected quotes, score_quote() |
Skim |
workflow/config.py, printing.py |
Paths, AUTO_LIMIT, print_summary() |
Skip: plumbing |
lg_workflow.py |
build_graph(): the same stages as LangGraph nodes |
Read with lab 07 |
../agents/agent/ |
run(), budgets, retries, checks (reused as-is) |
Skip: agents |
../mcp-server/host.py |
connect(), the servers (reused as-is) |
Skip: mcp-server |
Labs import everything from the package (from workflow import Workflow, run_workflow). Each lab's docstring names the functions to read first.
Exercises to practise with: PRACTICE.md (your own files go in my-work/). Questions and answers are in FAQ.md. The learning guide is learn-multi-agent.md (diagrams in diagrams/).
Rules of thumb¶
- Start with one agent. Split only when a trace shows one agent failing at a specific job, or when jobs need different tools, permissions or owners. Measure before and after (
06). - Agents hand off data, not chat. Every handoff is a typed object (Pydantic), built from tool results where possible, and checked in code before the next agent starts.
- Each fact has exactly one field in a handoff. A fact filed twice (delivery city also as a special request) fires two rules downstream (
01, real run). - Send each agent only the facts it should use. An empty field in the prompt ends up in the output ("No manager note." in a buyer email,
01). - The order of agents is code. Let a model choose only where the input decides the path (a router), and make it pick from a fixed list.
- Give each agent only its tools, and enforce it in
call(), not just in the tool list the model sees. - Don't make an agent of an if-statement. Approval policy, merging, re-checks and "call create_quote with these lines" are code.
- Keep the blast radius small: a sub-task that can fail on its own (one RFQ line) gets its own agent, so a failure costs that line, not the job (
04,resolve_line). - One trace and one budget for the whole workflow. Parallel agents reserve their share before they start.
- A failed check goes back to the agent that owns it, once. Then a person. Two models can argue forever.
- A critic is worth having only if you've measured it: seeded faults it must catch, correct work it must pass. Ask a small model narrow questions (one per line), not "review this": the open version passed every fault (
04). - Check tool arguments, not just answers: a SKU must come from a search result before an agent can use it (
ScopedTools(seen=...)). - Pause the workflow, not an agent: save the handoffs, resume at the stage, re-check what may have changed.
- Keep stage functions framework-free, so you can test them without the framework and move them into one (
07).
Tests¶
pytest -q runs model-free tests with a fake model per agent (picked by its system prompt) and a fake catalog: scoped tools, the intake contract and its one fix, line matching, fan-out with NOT FOUND, the pricing fix round, approval routes, the email check, pause/save/resume, rejection with a reason, a stock change while waiting, review routing, the shared budget, the router guard, the real catalog server from ../mcp-server and LangGraph interrupt and resume.
How qwen3:8b actually behaves (whether line agents say NOT FOUND, whether the critic is right) can only be seen by running the labs against Ollama.