Agent Reasoning & Planning (ReAct, CoT)

📌 Why Agents Need to Reason

If you give an LLM access to tools, how does it know when to use them? If a user asks a complex question like, "What is the square root of the population of France?", the LLM shouldn't just guess. It needs to realize it lacks the information, search for the population, and then use a calculator.

Comic illustration of an AI robot choosing to use a search tool and calculator rather than guessing a complex answer
Comic illustration of an AI robot choosing to use a search tool and calculator rather than guessing a complex answer

To achieve this, developers use specific prompting frameworks that force the agent into a logical loop of reasoning.

📌 The ReAct Framework (Reason + Act)

ReAct is the most famous agent prompting framework. It forces the model to generate a "Thought" (internal monologue) before it is allowed to take an "Action" (using a tool). Once the action is complete, it receives an "Observation", which triggers the next Thought.

Flowchart showing the ReAct cycle: Thought 1 -></figure> Action 1 (Search Web) -> Observation 1 -> Thought 2 -> Action 2 (Use Calculator) -> Observation 2 -> Final Answer

Example of ReAct in practice:

  • Question: What is the square root of the population of France?
  • Thought 1: I need to find the current population of France first.
  • Action 1: [Web Search Tool: "Population of France 2024"]
  • Observation 1: The population is approximately 68,000,000.
  • Thought 2: Now I need to calculate the square root of 68,000,000.
  • Action 2: [Calculator Tool: "sqrt(68000000)"]
  • Observation 2: 8246.211
  • Final Answer: The square root of the population of France is approximately 8,246.

📌 Plan-and-Solve (Advanced Planning)

While ReAct is great for step-by-step problem solving, it struggles with massive, multi-step projects because it's too near-sighted (it only thinks about the very next step). This can lead to agents getting stuck in infinite loops.

To solve this, modern agents use a Plan-and-Solve architecture.

Flowchart showing a Planner Agent generating a checklist and passing it to an Executor Agent to process step-by-step
Flowchart showing a Planner Agent generating a checklist and passing it to an Executor Agent to process step-by-step
  • The Planner: A dedicated agent (or prompt) whose only job is to look at the massive goal and break it down into a strict step-by-step checklist.
  • The Executor: An agent that takes the first item on the checklist, executes it (often using ReAct), checks it off, and moves to the next.