AI Agents path

🤖 Using AI & AI Agents

Chapter 9 of 24

🔄 Chapter 9: Think and Act

ReAct and agentic loops in depth

Agentic patterns define the control flow: how the agent decides when to think, when to act, and when to stop. ReAct (Reason + Act) alternates: the model outputs a "Thought" (reasoning), then an "Action" (e.g. a tool call), then the app returns an "Observation" (tool result); this repeats until the model outputs an "Answer". Plan-and-execute first asks the model to produce a full plan (step 1, 2, 3…), then the app runs each step and feeds results back. Tool-augmented (single-call) gives the model access to tools in one round; it may return one or more tool calls, and you can run them and optionally do one more LLM call with the results. Choosing a pattern affects latency, cost, and how well the agent handles multi-step tasks.

Common agentic patterns

  • 🔄

    ReAct

    Reason + Act in a loop (thought → action → observation)

  • 📋

    Plan-and-Execute

    Plan steps first, then execute each step

  • 🔧

    Tool-augmented

    Single call with tools; model chooses which to use

How an agent runs: the loop

User message
LLM (with system prompt + history + tool list)
Tool call?
App runs tool
Observation back to LLM
(loop back up)
or
Final answer
User sees reply

The agent keeps looping (think → act → observe) until it produces a final answer or hits a step limit.

ReAct in practice: one loop

Reason (Thought) → Act (call a tool) → Observe (get result). Repeat until the agent can answer.

User: What's the population of Tokyo?
Thought: I need to look up current data. I'll use search.
Action: search(query: "Tokyo population 2024")
Observation: Result: ~37.3 million (metro)
Thought: I have the answer.
Answer: Tokyo's metro population is about 37.3 million.

Example: Plan-and-execute in practice

Task: "Compare the top 3 laptops on this site." Plan: (1) Fetch the product page, (2) Extract names and prices, (3) Summarize. The app executes each step, passes results to the model, and the model produces the final comparison.