Phase 14: Agent Engineering

Tree of Thoughts and LATS: Deliberate Search

A single chain-of-thought trajectory has no room to backtrack. ToT (Yao et al., 2023) turns reasoning into a tree with self-evaluation on each node. LATS (Zhou et al., 2024) unifies ToT with ReAct and Reflexion under Monte Carlo Tree Search. Game of 24 goes from 4% (CoT) to 74% (ToT); LATS hits 92.7% pass@1 on HumanEval. Frame reasoning as search: nodes are "thoughts," edges are "expansions," value is "how promising.". Implement a stdlib ToT-style BFS tree search with self-evaluation scoring. Extend to a toy LATS MCTS loop with select / expand / simulate / backpropagate. Decide when search is worth the token multiplier (Game of 24, code generation) and when a single trajectory is enough (simple Q&A). Chain-of-thought is a linear walk. If the first step is wrong, every subsequent step works on a bad premise. On Game of 24 (use four digits with + − × ÷ to make 24), GPT-4 CoT hits 4% accuracy. The model picks the wrong subexpression early and cannot recover. What reasoning needs is the ability to propose multiple candidates, evaluate them, pick the promising ones, and backtrack when dead ends appear. That is search. Tree of Thoughts and LATS are the two canonical formulations. Each node is a coherent intermediate step ("a thought"). Each node can expand to K child thoughts. The LLM…

Tree of Thoughts and LATS: Deliberate Search: A single chain-of-thought trajectory has no room to backtrack. ToT (Yao et al., 2023) turns reasoning into a…

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.