Introduction
This lesson implements Reason+Act (ReAct): an agent alternates thoughts with tool calls until it answers or hits a step limit. Unlike one-shot prompting, every thought, action, and observation is visible for debugging. Three tools — search, calculate, lookup — sit behind a planner in
react/loop.py;MetricsStorerecords each step; a FastAPI dashboard shows live counters.POST /demoruns three questions so metrics move from zero after the first click.The project in
aiam-day09/runs viastart.sh,demo.sh, andrun_tests.sh.
Highlights
Thought → Action → Observation with stopping on
final_answerormax_steps.Tool dispatch via
Action: name[argument]parsed by strict regex.AST-safe calculator — no
eval().Dashboard polls
/metrics;/demoexercises all three tools.Docker lifecycle scripts on port 8088.
What We Build
react/package:tools.py,loop.py,metrics.py,service.py.FastAPI (
app.py):/run,/demo,/metrics,/health,/dashboard.CLI demo (
main.py) printing steps, observations, and final answers.DEMO_QUESTIONS— search, calculate, lookup — so every dashboard counter updates.
Connection to Previous Lesson
Day 8 fanned typed work to workers in parallel. Day 9 sequences one tool per step: observe, then continue or stop with a Final Answer.
Enables Next Lesson
ReAct is the control loop prompt engineering will steer. Production swaps _plan_thought() for an LLM; the action/observation contract and metrics stay the same.
Architecture Context
Where this component sits: between
app.py(API) andreact/tools.py(tool backends).Why it exists: multi-step questions need grounded facts before a final answer.
Problem solved: bounded, observable tool use with measurable loop health.


