Chengshuo Dai
Back to Blog

Advanced Prompt Engineering: Chain of Thought and Tree of Thoughts

Prompt Engineering

Prompt Engineering has evolved far beyond simply writing clear instructions. It is now a rigorous discipline focused on structuring inputs to maximize the reasoning capabilities of Large Language Models. Among the most impactful techniques discovered are Chain of Thought (CoT) and Tree of Thoughts (ToT).

Chain of Thought prompting fundamentally alters how an LLM processes complex problems. Standard prompting asks the model to output a final answer directly. In contrast, CoT forces the model to generate intermediate reasoning steps before arriving at the conclusion. This can be achieved via Zero-Shot CoT (simply appending "Let's think step by step" to the prompt) or Few-Shot CoT (providing examples that include the reasoning process). By externalizing its computation into the output context window, the model avoids accumulating errors in complex logic or arithmetic tasks. It effectively gives the model "time to think," as each generated token provides additional context for the next.

Tree of Thoughts (ToT) is a more advanced framework designed for tasks requiring strategic planning, exploration, and backtracking, such as creative writing or complex puzzle solving. While CoT represents a single, linear path of reasoning, ToT structures the reasoning process as a tree. The LLM generates multiple alternative "thoughts" (branches) at each step. The system then evaluates these thoughts—often using the LLM itself as a heuristic evaluator—to score their potential for success.

Using classic search algorithms like Breadth-First Search (BFS) or Depth-First Search (DFS), the ToT framework explores the most promising branches and abandons dead ends. This transforms the LLM from a simple sequence generator into an active problem solver capable of deliberate search and self-correction. While ToT requires multiple API calls and external orchestration code, it unlocks capabilities in LLMs that are impossible with standard linear prompting.

References:

  1. DAIR.AI: Prompt Engineering Guide - https://www.promptingguide.ai/
  2. Princeton University: Tree of Thoughts: Deliberate Problem Solving with Large Language Models - https://arxiv.org/abs/2305.10601