Planning with HTN and Evolutionary Search
Symbolic planning handles the cases where the plan is provably correct. Evolutionary code search handles the cases where the fitness function is machine-checkable. ChatHTN (2025) and AlphaEvolve (2025) show what each unlocks when paired with an LLM. Explain Hierarchical Task Networks: tasks, methods, operators, preconditions, effects. Describe ChatHTN's hybrid loop — symbolic search with LLM fallback decomposition. Explain AlphaEvolve's evolutionary loop and why it only works with a programmatic evaluator. Implement a toy HTN planner plus a toy evolutionary search in stdlib. ReWOO (Lesson 02), Plan-and-Execute, and ReAct cover most agent planning. Two cases they don't cover well: Plans with provable correctness. Scheduling, flight pathing, compliance workflows — the plan must be sound by construction. A fluent LLM plan that sometimes hallucinates a step is unacceptable. Optimizations with a machine-checkable fitness function. Matrix multiplication, scheduling heuristics, compiler passes — the goal is not "a correct plan" but "the best plan.". HTN planning and AlphaEvolve solve the two different problems. Both use LLMs as amplifiers, not replacements. An HTN is: Tasks — compound (to be decomposed) and primitive (directly executable). Methods — ways to decompose a compound task into subtasks, with preconditions. Operators — primitive actions with preconditions and effects. State — a set of facts. Planning: given a goal task and an initial state, find a decomposition into primitive operators…
Planning with HTN and Evolutionary Search: Symbolic planning handles the cases where the plan is provably correct. Evolutionary code search handles the cases…
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.