#12 AI agents and MCP 6.1 min
Multi-Agent Patterns in Plain Python: Pipeline, Router, Loop
Build a pipeline and a router in plain Python with a local model, then test the four lines that guard a supervisor loop, using a scripted stand-in.
Make refunds a real team
Copy the code folder first. In guard.py add 'refunds' to HANDLERS. Predict how the output changes, in particular what step 2 prints, then run python guard.py.
A hint
The fallback only runs when the team is not in HANDLERS.
Raise the step limit
In guard.py change MAX_STEPS from 3 to 4 and predict the output. Then change it to 5 and predict again. Run python guard.py each time and compare.
A hint
STUB_DECISIONS only has four entries.
Add a second bad decision
In guard.py change MAX_STEPS to 4 and change the third item of STUB_DECISIONS from 'billing' to 'shipping'. Predict every line the script will print, then run it and compare.
A hint
Each unknown route is replaced by 'other' before the step is printed.
Tighten the editor
In pipeline.py change the editor instruction from at most 12 words to at most 6 words. Predict whether the 2-3 business days detail will survive, then run python pipeline.py. This needs Ollama with llama3.2 and the ollama and pydantic packages. Read both lines and decide whether the editor kept what the writer made up.
A hint
The video says the second step can only work with what the first one gave it, so check each step's output.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
Wiring only: simple tasks on one small local model, nothing measured at scale. The supervisor loop is a scripted stand-in with no model call, so the guards are tested against a planned bad decision, not a real model failure. The pattern advice comes from agency and vendor pages.
Up next in AI agents and MCP
More in AI agents and MCP
Related videos
- #06 Test Your LLM App with pytest: An Eval Harness in 40 Lines LLM engineering and evals
- #56 Prompt Versioning: Compare Changes Case by Case LLM engineering and evals
- #10 Fine-Tuning vs RAG vs Prompting: A Test You Can Run Local and open models
- #18 Prompt Injection Live: Attacking My Own LLM App AI security and governance
