Exercise: one agent or a supervisor and two workers
- Track
- Multi-Agent Systems
- By
- Sourav Banerjee
- Last updated
- 30 Nov 2026
01 Context
Problem statement
Larkspur Cloud's support assistant is one agent with every tool. The team wants to split it into a supervisor and two specialist workers, one for accounts (billing, refunds, plans, support tiers, credits) and one for the platform (outages, backups, export, security, API limits, regions). Before anyone ships the split, you build both designs over the same handbook, run them on the same 20 golden questions, and compare what each costs and what each answers.
The rule you apply comes from lesson 1 of T11.1: a team buys focus with more model calls, and whether it also buys better answers is settled by measuring, question by question. Keep the split only if the answers it wins are worth the calls it adds.
02 Outcomes
What you will learn
- Build one ReAct agent with two search tools, and the same tools split behind a supervisor and two workers.
- Count the cost of each design in model calls and tokens per question, with one callback over every call.
- Score answers with code checks and a judge model that never learns which design wrote them.
- Read the questions where the designs disagree, and trace a loss to the request a worker saw.
- Explain when a supervisor's extra routing calls buy nothing.
03 Setup
Before you start
Lessons
- T11.1 Multi-Agent Architectures: lesson 1 of T11.1 Monolithic vs multi-agent for the monolithic agent, the specialist team and a fair comparison, lesson 2 of T11.1 The five multi-agent architectures for the tool-calling supervisor and
recursion_limit, and lesson 4 of T11.1 Supervisors and hierarchical teams for what a supervisor's routing calls cost. - T11.2 Collaboration, Control & Parallel Agents: lesson 5 of T11.2 Parallel agents, async nodes and streaming for the fan-out and join in the extension.
- T11.3 Multi-Agent Applied Builds: lesson 5 of T11.3 Five practical agent patterns, side by side for a supervisor with agents as tools and context isolation.
Dataset
The Larkspur Cloud handbook (13 files) and its 30-question golden set, in data/. The exercise uses 20 of the questions: the 6 multi-hop, the 4 numeric, the 5 out-of-corpus and the first 5 single-file lookups. 15 have evidence spans and a reference answer. The 5 out-of-corpus ones have neither, and the right reply is to decline.
Code
load_handbook, load_jsonl, tfidf_retriever and is_hit from src/lab_kit.py, create_agent from langchain.agents, StateGraph from langgraph, UsageMetadataCallbackHandler from langchain_core.callbacks and ChatOllama from langchain_ollama.
Environment
The course's default environment (uv run jupyter lab), or Colab after cloning the repository. Everything runs offline through Ollama: install it, run ollama pull qwen2.5:3b and ollama pull llama3.2:3b, and keep ollama serve running. No API keys. With no provider bill, cost is counted in model calls and tokens, the units a provider prices on.
04 Architecture
Experiment workflow
The questions, the model, the two retrievers, the answer rule and the cap stay fixed. Only the agent design changes between the two main rows.
Extension: a third row that sends every question to both workers at once and merges their replies.
05 Build
Implementation tasks
Task 1: Load the data
Load the handbook and the golden set from
data/larkspur/, and pick the 20 questions. Split the handbook into two knowledge bases by file name, cut each with the recursive splitter and give each its own TF-IDF retriever.ACCOUNTS = {"01_billing.md", "02_refunds.md", "03_plans.md", "07_account_deletion.md", "10_support_tiers.md", "12_sla_credits.md", "13_onboarding.md"} RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50) tfidf_retriever(chunks, k=4)Task 2: Meter every model call
Subclass
UsageMetadataCallbackHandlerto count calls as well as tokens, and pass one meter per question in the run config. Log every chunk a tool returns, so you can check later whether the evidence ever reached a model.Task 3: Build the baseline: one agent
Build one
create_agentagent with two tools,search_accountsandsearch_platform. The docstrings say which half of the handbook each one searches. The system prompt tells it to answer only from the passages, and to reply exactlyNOT IN HANDBOOKwhen they do not answer.create_agent(llm, [search_accounts, search_platform], system_prompt=...) agent.invoke({"messages": [...]}, config={"callbacks": [meter], "recursion_limit": 8})Task 4: Change one thing: split it
Wrap each half in a worker: it searches only its own half with the question it is given and answers in one call. Make the two workers the tools of a supervisor agent,
ask_accounts_agentandask_platform_agent. Same model, same retrievers, same answer rule, samerecursion_limit.Task 5: Run and score
Run both designs on the 20 questions, alternating which runs first. Score each answer three ways: whether any retrieved chunk held an evidence span (
is_hit), whether an out-of-corpus question gotNOT IN HANDBOOK, and whether a judge model finds the answer matches the reference answer. Before the judge scores anything, check each candidate judge on five answers you labelled by hand, and keep the one that agrees most often.class Verdict(BaseModel): reason: str correct: bool ChatOllama(model=m, temperature=0).with_structured_output(Verdict) # m in ("llama3.2:3b", "qwen2.5:3b")New here: the judge is a local model with structured output, blind to the design as in lesson 1 of T11.1. Checking it on hand-labelled answers first is a few lines of code the lessons do not show.
Task 6: Read the disagreements
List every question where the two designs differ on a correct answer. For each one, read which tools ran, what question the supervisor passed to a worker, and whether the evidence was retrieved.
Task 7: Decide
Keep the split only if it wins questions the single agent loses and loses none it answered, at a cost you can name in calls and tokens per question.
Task 8: Extension: fan out to both workers
Build a
StateGraphthat sends the customer's own question to both workers in one super-step, joins their replies with a reducer and a list edge, and merges them in one call. Score it the same way and add it as a third row.
06 Measure
Record results
What you enter stays in this browser only.
| Design | Model calls per question | Tokens per question | Judged correct (of 15) | Evidence retrieved (of 15) | Out of corpus declined (of 5) | Questions lost against the single agent |
|---|---|---|---|---|---|---|
| Single agent (baseline) | none | |||||
| Supervisor and two workers | ||||||
| Fan-out to both workers (extension) |
Model calls and tokens are means over all 20 questions, judge calls excluded. Judged correct and evidence retrieved count the 15 questions with a reference answer. A lost question is one the single agent answered correctly and this design did not.
07 Verify
Done when
0 of 4 done
What you enter stays in this browser only.
08 Debug
Common mistakes
Counting only the supervisor's calls
The workers' calls happen inside tools. Pass one callback in the run config so every call under that invoke is counted, or the split looks cheaper than it is.
Trusting the judge alone
A 3B judge makes mistakes. In our run llama3.2:3b agreed with only 3 of the 5 hand labels, and passed a wrong availability figure. Check the judge before it scores, and read the answer yourself where the judge and the code checks disagree (lesson 1 of T11.1).
A worker that sees only a rewritten question
The worker never sees the customer's message. When the supervisor drops a detail from the question it passes, the worker cannot answer it (lesson 5 of T11.3).
Letting the supervisor retype an exact marker
The workers replied NOT IN HANDBOOK, and the supervisor passed it on as NOT IN HANBOOKS. A reply that code reads must reach the user through code, not through another model call.
A tool argument the model will not fill
With the argument named request, qwen2.5:3b called the worker tools with no arguments and got a validation error back. Read the tool messages of a few runs before scoring.
09 Transfer
Interview angle
“When would you split one agent into a supervisor and specialist agents?”
Show a model answer
When one agent's prompt and tool list grow past what it can choose among well. Then measure the split against the single agent on the same golden set: count the extra routing calls and tokens, and keep it only if it wins named questions the single agent loses.
10 Review
Worked solution
The worked solution is solution/p10_exercise_solution.ipynb (open in Colab). Locally, open it from exercise/solution/ so ../data/ resolves, and run it top to bottom with the default environment and Ollama running. In Colab, clone the repository first, because the notebook reads the corpus and src/lab_kit.py from it, and install Ollama in the runtime.
Show our run and the reasoning
Our run: qwen2.5:3b through Ollama for the agents and the judge, langchain 1.4.7, langgraph 1.2.18, langchain-ollama 1.1.0 and scikit-learn 1.9.1, offline.
| Design | Model calls per question | Tokens per question | Judged correct (of 15) | Evidence retrieved (of 15) | Out of corpus declined (of 5) | Questions lost against the single agent |
|---|---|---|---|---|---|---|
| Single agent (baseline) | 1.7 | 717 | 9 | 7 | 5 | none |
| Supervisor and two workers | 2.9 | 996 | 11 | 9 | 2 | g27, g29, g30 |
| Fan-out to both workers (extension) | 3.0 | 784 | 13 | 14 | 1 | g26, g27, g29, g30 |
The judge check picked qwen2.5:3b, which agreed with all 5 hand labels, over llama3.2:3b, which agreed with 3. The judge is the same model that wrote the answers. Both designs share that bias, and the code checks do not depend on it.
The split costs 1.2 more model calls and 279 more tokens per question, about 39% more. The extra call is the supervisor writing the answer after the worker replies, and the extra tokens are the worker's own prompt and passages on top of the supervisor's. It wins g01 and g05. On g01, "How long does a refund take?", the single agent searched the platform half and answered NOT IN HANDBOOK, while the supervisor sent the question to the accounts worker. On g05 the single agent called no tool at all. Neither design ever called both tools or both workers, so every multi-hop question was answered from one half of the handbook.
The split loses three out-of-corpus questions. On g29 and g30 the platform worker declined, and the supervisor passed that on as NOT IN HANBOOKS, which the exact check rejects. On g27 Ollama aborted the supervisor's generation with "token repeat limit reached". The single agent declined all five. By the rule from lesson 1 of T11.1 the split is not kept as built: it buys two answers and breaks three declines.
The fan-out extension retrieved evidence for 14 of 15 questions, because both halves are always searched, and it answered 13 correctly at 3 calls a question. Its tokens stay below the supervisor's because no prompt carries tool schemas. It declined only 1 of 5 out-of-corpus questions with the exact marker. The next change to test is passing a worker's NOT IN HANDBOOK straight to the user in code, then running the same 20 questions again.