#26 AI agents and MCP 5.8 min
Plan, Act, Reflect: Does It Help a Small Model?
One example in the prompt took a small model from 2 of 6 to 6 of 6. Reflection added nothing.
Use the safe calculator
Copy the code folder first. In a Python prompt import calc and price from tools. Work out 3 helmets and 2 locks by calling calc('3*helmet + 2*lock', {'helmet': price('helmet'), 'lock': price('lock')}). Check you get 160.0, the answer for the first question in tasks.py.
A hint
The second argument is a dictionary from item names to prices.
Try to break the calculator
Call calc with the expressions '2**3' and 'abs(3)', and one that uses an item name you did not give in the names dictionary. Predict first what happens to each. When we ran them, all three raised a ValueError that began with not allowed. Write a sentence on why that matters when a model writes the expression.
A hint
Only numbers, the given names and plus, minus, times and divide are allowed. Power and function calls are not.
Plan a new question by hand
Write the plan yourself for the question: what do 2 gloves and 1 pump cost? Use a lookups list and one expression, then run it with calc and price from tools.py. We got 50.98. Then do the same for the average price of a helmet, a lock and a light, and compare your result with the 29.16 in tasks.py. We got 29.16333333333333, which passes the check in compare.py because it is within 0.01 of the answer.
A hint
For the average, add the three names and divide by 3.
Predict the code check
The code check problem_with in agent.py looks at known names and unused lookups. Predict what it returns for a plan with lookups ['bottle'] and expression '2*bottles', for lookups ['bottle', 'tube'] and expression '2*bottle', and for lookups ['bottle'] and expression '2*bottle'. Then check by importing Plan and problem_with from agent, which needs the packages from the video. We expected unknown names bottles, then looked up but not used: tube, then None.
A hint
The check collects the lower case words in the expression and compares them with the price list and the lookups.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
Six made up shopping questions, one worked example that looks like them, one small model (llama3.2), one run at temperature zero. No larger model and no tool-choosing loop was tested.
Up next in AI agents and MCP
More in AI agents and MCP
- #01 Local AI Agent in Python: No API Key (Ollama)
- #12 Multi-Agent Patterns in Plain Python: Pipeline, Router, Loop
- #22 OpenAI Agents SDK vs LangGraph vs Plain Python
- #23 Agent Memory: What to Keep and What to Forget
- #24 Approval Gates for Risky Agent Actions
- #25 Tool Errors: Retries, Fallbacks and Made-Up Answers
Related videos
- #58 JSON Mode vs Schema vs Function Calling: Measured (Ollama) LLM engineering and evals
- #05 Structured Outputs in Python: Valid JSON Is Not Correct JSON LLM engineering and evals
- #47 6 RAG Failure Modes Reproduced: Which Ones Actually Break RAG and vector search
- #51 Multi-User RAG: Filter Before You Search (Leak Test) RAG and vector search
