Home/AI & Automation/LLM Prompt Patterns: When to Use CoT, ToT, and ReAct
AI & AutomationPrompt engineeringChain-of-Thought

LLM Prompt Patterns: When to Use CoT, ToT, and ReAct

Part 1’s Zero-shot, Few-shot, Role, Chain, and Format techniques work well for simple Q&A, but production tasks that need complex reasoning and multi-step planning require more sophisticated patterns. This post covers Chain-of-Thought, Tree

LLM Prompt Patterns: When to Use CoT, ToT, and ReAct
Contents
  1. Why You Need to Go Beyond the Basics
  2. Chain-of-Thought (CoT)
  3. Tree-of-Thought (ToT)
  4. ReAct: Interleaving Reasoning and Tool Calls
  5. Self-Consistency: Majority-Vote Ensemble
  6. Pattern Selection Guide
  7. Measuring Pattern Benefits Together with Cost

Why You Need to Go Beyond the Basics

The Zero-shot, Few-shot, Role, Chain, and Format techniques from Part 1 work well for simple Q&A. For production tasks that require complex reasoning and multi-step planning, you need more sophisticated patterns.

Chain-of-Thought (CoT)

Prompt the model to write out its reasoning step by step before giving the answer.

Python
# Zero-shot CoT: " "
zero_shot_cot = """
 3 Request.
 30 when .
 .

 after .
"""

# Few-shot CoT: example
few_shot_cot = """
example:
Q: 45 ,
: 30 + →
: ,

Q: 10 ,
: 30 + →
: when

Q: {_}
:"""

Cost tip: CoT consumes 2–3× more tokens. Use it only for important decisions.

Tree-of-Thought (ToT)

Instead of a single chain, explore multiple paths as a tree.

Python
async def beam_search_thoughts(problem: str, branches: int = 3, depth: int = 2):
    paths = [problem]
    for _ in range(depth):
        candidates = []
        for path in paths:
            new_thoughts = await expand(path, n=branches)
            scores = await asyncio.gather(*[evaluate(t) for t in new_thoughts])
            candidates.extend(zip(scores, new_thoughts))
        candidates.sort(reverse=True)
        paths = [t for _, t in candidates[:branches]]
    return paths[0]

Effective for strategy formulation and decomposing complex problems, but cost increases 10–20×.

ReAct: Interleaving Reasoning and Tool Calls

CODE
Thought: check
Action: get_orders(customer_id="12345")
Observation: [{"order_id": "ORD-789", "date": "2025-12-01", "status": "delivered"}]

Thought: 30 2025-12-31to
Action: process_refund(order_id="ORD-789")
Observation: {"status": "success", "amount": 89000}

Answer: . 3~5 .
Python
REACT_SYSTEM = """ reply:
Thought: [ ]
Action: [tool_name(param=value)]
Observation: [Result]
... ...
Answer: [ reply]"""

Self-Consistency: Majority-Vote Ensemble

Python
async def self_consistency(prompt: str, n: int = 5) -> str:
    responses = await asyncio.gather(*[
        llm.generate(prompt, temperature=0.7) for _ in range(n)
    ])
    answers = [extract_answer(r) for r in responses]
    return Counter(answers).most_common(1)[0][0]

At n=5, accuracy improves by 8–15% at 5× the cost. Apply only to high-value decisions.

Pattern Selection Guide

PatternBest forCost multiplier
CoTLogical reasoning, math2–3x
ToTStrategy, design10–20x
ReActTool use, information gathering3–5x
Self-ConsistencyHigh-confidence decisions5x

Part 3 covers prompt versioning and A/B testing so you can manage these patterns systematically.

Measuring Pattern Benefits Together with Cost

CoT, Self-Consistency, and ReAct can raise accuracy, but they all add tokens and latency. Decide by comparing accuracy and cost on the same evaluation set.

Cause: when a pattern doesn't help as expected

  • Adding CoT to simple classification/extraction only lengthens output with no accuracy gain
  • Self-Consistency multiplies calls by the sample count, so cost grows N-fold
  • Adding "think step by step" to models with built-in reasoning yields little (some provider guides say explicit CoT instructions are unnecessary for such models)

Measurement script

Python
variants = {"plain": PROMPT, "cot": PROMPT + "\nWork through it step by step, then give only the answer on the last line."}
for name, p in variants.items():
    acc, toks, lat = evaluate(p, eval_set)   # accuracy, mean output tokens, p95 latency
    print(f"{name:6s} acc={acc:.2f} out_tokens={toks:.0f} p95={lat:.1f}s")

Decision rules

  • If accuracy gains are small and output tokens grow a lot, keep the plain prompt.
  • If gains appear only for some types (math, multi-step reasoning), route only those types to the pattern.
  • Limit Self-Consistency to tasks where wrong answers are costly, and increase the sample count from a small number until gains stop.

Prevention

  • Re-run the comparison whenever you change models; the same pattern behaves differently on different models.
✦ ✦ ✦
Sources and verification

Sources and checks vary by article. Only articles with a recorded check date, scope and sources below were checked, and only within that scope. For other articles, verify against the current docs for your version before applying anything, and email us about errors. Editorial policy · email us

This article has no recorded human check (date and scope) yet.

Published ·

Comments

Be the first to comment.