Hands On AI Agent Mastery Course

Hands On AI Agent Mastery Course

Production AI Engineering

Lesson 9 — ReAct Loop

Aug 13, 2026
∙ Paid

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; MetricsStore records each step; a FastAPI dashboard shows live counters. POST /demo runs three questions so metrics move from zero after the first click.

The project in aiam-day09/ runs via start.sh, demo.sh, and run_tests.sh.

Highlights

  • Thought → Action → Observation with stopping on final_answer or max_steps.

  • Tool dispatch via Action: name[argument] parsed by strict regex.

  • AST-safe calculator — no eval().

  • Dashboard polls /metrics; /demo exercises 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) and react/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.

User's avatar

Continue reading this post for free, courtesy of AI Roadmap.

Or purchase a paid subscription.
© 2026 Systemdr, Inc. · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture