AI Agent Reasoning Frameworks: CoT, ReAct, and Plan-and-Execute

    Learn how Chain of Thought, ReAct, and Plan-and-Execute structure AI agent reasoning, tool use, and long-running workflows. This article compares their mechanisms, trade-offs, and use cases, with illustrative code and a production checklist covering observability, state management, cost control, recovery, and security.

    1. The Starting Point: Models Need Structure, Not Just Knowledge

    Using a large language model as a simple question-answering system often exposes three limitations: multi-step tasks collapse into a single guess, requests for current external information invite fabricated answers, and outputs lack intermediate evidence that can be checked. The underlying issue is not simply model size. It is an uninterrupted path from input to output, with no opportunity to intervene.

    A reasoning framework adds a logical control layer to that path. Positioned between the model and its tools, it defines how tasks are decomposed, how intermediate states are represented explicitly, and when earlier decisions should be revised.

    The framework does not change model weights, but it can substantially change behavior. This explains why the same model can perform very differently under different frameworks.

    2. Framework One: Chain of Thought (CoT)

    2.1 How It Works

    Chain of Thought turns a direct answer into a step-by-step process. The model is prompted to produce intermediate reasoning steps before giving its answer.

    Explicit intermediate steps offer two main benefits:

    • They break complex problems into simpler subproblems, reducing the difficulty of each individual step.
    • They make the generated explanation easier to inspect, helping developers identify where an error appears.

    Common approaches include asking the model to analyze a task step by step, providing few-shot examples with worked solutions, or using a model’s built-in extended reasoning mode. Some reasoning models already support extended reasoning without additional prompt engineering.

    2.2 Illustrative Code

    1. COT_PROMPT = """
    2. Handle the task using the following requirements:
    3. 1. List the known facts and constraints.
    4. 2. Explain the basis for each step.
    5. 3. Output "Final answer:" separately at the end.
    6. Task: {task}
    7. """
    8. def run_cot(llm, task):
    9. reasoning = llm(COT_PROMPT.format(task=task))
    10. return extract_after(reasoning, "Final answer:")

    2.3 Benefits and Trade-offs

    CoT is particularly useful for tasks in which intermediate steps strongly affect the outcome, such as mathematical calculations, logical reasoning, code generation, and complex structured extraction.

    Its costs are also clear:

    • Longer outputs increase latency and inference costs.
    • Errors can accumulate, with an incorrect early step amplified by later steps.
    • A model’s generated explanation may not reflect its actual internal computation and should not be treated as auditable evidence.

    For debugging, retain available intermediate explanations while presenting only the result to users. Independently validate critical conclusions, for example through reverse calculations or consistency checks across separate samples.

    3. Framework Two: ReAct

    3.1 The Thought–Action–Observation Loop

    ReAct combines reasoning and external interaction in a repeating loop:

    Thought → Action → Observation

    The loop continues until a termination condition is met.

    The key difference from CoT is that reasoning is no longer confined to information already in the context. The model can retrieve external facts and revise its approach based on what it observes. This makes ReAct a widely used practical framework for querying data, performing operations, and interacting with business systems.

    3.2 Illustrative Code

    1. def run_react(llm, tools, question, max_steps=8):
    2. history = [f"Question: {question}"]
    3. for step in range(max_steps):
    4. out = llm(build_prompt(history, tool_specs=tools))
    5. thought, action, arg = parse(out) # Parse Thought/Action
    6. history.append(f"Thought {step}: {thought}")
    7. if action == "Finish":
    8. return arg
    9. observation = tools[action](**arg) # Execute the tool
    10. history.append(f"Observation {step}: {truncate(observation, 2000)}")
    11. return fallback(history) # Fall back at the step limit

    3.3 Engineering Details That Matter

    • Tool descriptions are interface contracts. Clearly define each tool’s name, purpose, parameters, and failure behavior. Incorrect tool selection often results from ambiguous descriptions rather than insufficient model capability.
    • Observations must be structured and bounded. Long responses quickly consume context space. Return only necessary fields and enforce length limits.
    • Termination conditions and step limits must be explicit. Prevent endless loops, and use a fallback strategy rather than failing abruptly when the limit is reached.
    • Write operations need idempotency and rollback support. Attach a unique identifier to each action so retries do not create duplicate side effects.

    4. Framework Three: Plan-and-Execute

    4.1 How It Works

    Plan-and-Execute first creates a task-level plan, represented as an ordered list or a directed acyclic graph. It then executes the steps.

    If an observation deviates from expectations, the framework triggers replanning to revise the remaining work. Compared with ReAct’s local, step-by-step decisions, this framework provides a broader view of the task. It can reduce drift during long workflows, and the plan itself serves as a progress view.

    1. Plan: [1] Retrieve metric definitions → [2] Fetch data →
    2. [3] Calculate period-over-period change → [4] Generate conclusions
    3. Execute: Run each step; on failure or deviation beyond a threshold,
    4. trigger Replan(remaining steps).

    4.2 Trade-offs

    The advantages include better control over long workflows, easier parallel execution, and plans that can be reviewed by humans.

    The drawbacks are that the initial plan’s quality strongly constrains the result, and information can be lost between planning and execution.

    A common compromise is coarse-grained planning with fine-grained ReAct execution: create a high-level plan, then use a reasoning-and-action loop inside each step.

    Other approaches include self-refinement, such as Self-Refine and Reflexion, which use critique and revision to improve outputs iteratively, and multi-path search, such as Tree of Thoughts, which evaluates alternative reasoning branches. These can serve as enhancement layers rather than replacements for the three frameworks.

    5. Comparison and Selection

    Dimension CoT ReAct Plan-and-Execute
    Core operation Step-by-step reasoning Thought–action–observation loop Plan first, then execute
    External information None in standalone use Strong reliance Strong reliance in tool-driven workflows
    Global perspective Limited Local Strong
    Latency and cost Moderate Moderate to high High
    Typical use cases Calculation, reasoning, extraction Queries, operations, tool orchestration Long workflows, coordination across systems

    Two practical questions guide selection:

    1. Does the task require external facts? If so, standalone CoT is insufficient.
    2. Does the workflow exceed five steps and require human review? If so, add a planning layer.

    6. Production Implementation Checklist

    1. Observability: Persist available reasoning summaries, actions, and observations as structured records. Connect them to logging, monitoring, and alerting systems. Establish baselines and thresholds for step counts, tool failure rates, and per-task costs.

    2. State and memory: Store session state and intermediate artifacts in object storage or a cache. Decouple task processing through message queues rather than making a long model context the sole carrier of state.

    3. Cost control: Select model tiers according to step difficulty, cache repeated query results, and summarize long histories to reduce context size.

    4. Failure recovery: Make write operations idempotent, support compensating actions, and escalate repeated failures to a human fallback. Clearly tell users which stage the task has reached.

    5. Security boundaries: Apply least-privilege permissions to tools, require additional confirmation for high-impact operations, and treat external tool responses as untrusted data rather than instructions.

    7. Conclusion

    Reasoning frameworks are valuable not because they make a model appear to think, but because they divide uncertainty into smaller steps that can be observed, corrected, and rolled back where applicable.

    CoT adds structured reasoning, ReAct enables interaction with the outside world, and Plan-and-Execute brings order to long-running tasks. Combining these approaches with reliable logging, monitoring, and fallback mechanisms provides a practical path from agent demonstrations to production systems.