RSS Amplifier

Hands On AI Agent Mastery Course · Aug 13, 2026

Lesson 9 — ReAct Loop

0
Sign in to vote or save

AI Roadmap · Hands On AI Agent Mastery Course

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.

  • 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.

  • 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.

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.

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.

  • 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.

Read the original on aiamastery.substack.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.