Algorithm of thoughts

Also known as: AoT

On this page 7

Algorithm of thoughts (AoT) is a prompting technique in which in-context examples demonstrate an explicit search procedure, such as depth-first search with backtracking, so that a large language model explores, evaluates and abandons candidate solutions inside a single generation. In the prompting branch of artificial intelligence, it was proposed in 2023 as a cheaper alternative to multi-query search methods, because the whole exploration happens in one or very few model calls.

The core intuition is that a model can imitate the trace of an algorithm it has seen in the prompt. Instead of an external program that calls the model many times to expand and score branches, the prompt itself teaches the model to write out a compact search, prune weak paths and continue from promising ones.

How algorithm of thoughts structures a prompt

An AoT prompt consists of task instructions plus worked examples whose reasoning is written as an algorithmic trace. Each example lists a candidate step, briefly judges whether it can lead to a solution, backtracks when a branch fails and records the path that finally succeeds. The model then receives a new problem and continues in the same style.

The examples are deliberately not perfect, linear solutions. They include dead ends, because the goal is to teach the procedure of exploring rather than the habit of guessing the answer at once. This is the main difference from ordinary chain-of-thought demonstrations, which typically show only the successful line of reasoning.

The following table lists the components of a typical AoT prompt and their purpose.

ComponentWhat it containsWhy it matters
Task instructionGoal, rules and output formatDefines the search space
Search demonstrationStep-by-step trace with branchesTeaches the exploration pattern
Evaluation cuesShort judgments of each branchEnables pruning of weak paths
Backtracking markersExplicit returns to earlier statesPrevents fixation on one path
Final answer slotFixed marker for the resultMakes parsing reliable
Building blocks of an algorithm of thoughts prompt

Search styles that AoT can imitate

The original formulation showed that a model can follow both depth-first and breadth-first search patterns when the examples use them consistently. The choice of pattern shapes how the generated reasoning looks and how many tokens it consumes.

PatternHow the trace looksBest suited to
Depth-first with backtrackingFollow one path deeply, retreat on failurePuzzles with quick dead-end detection
Breadth-first explorationList several options per level firstProblems needing comparison of alternatives
Heuristic-guided searchTry the most promising option firstTasks where intuition ranks moves well
Search patterns used in AoT demonstrations

Reported results suggest that the model does not copy the algorithm mechanically. It often visits fewer nodes than the textbook algorithm would, because its learned intuition ranks promising options early. This behavior is useful, but it also means the search is neither exhaustive nor guaranteed to find a solution.

AoT belongs to a family of methods that make reasoning more deliberate. Its closest neighbors are tree of thoughts and graph of thoughts, which also explore multiple branches, and self-consistency, which samples several independent answers. The distinguishing feature of AoT is that the exploration lives inside one context rather than across many orchestrated calls.

TechniqueNumber of model callsExploration styleMain cost
Chain-of-thoughtOneSingle linear pathLow, but no recovery from errors
Self-consistencySeveral to dozensIndependent samples, majority voteProportional to sample count
Tree of thoughtsMany, often dozens to hundredsExternal search controllerHigh call count and latency
Algorithm of thoughtsOne or a fewSearch trace within one outputLong outputs, context use
AoT and neighboring reasoning techniques

The trade-off is clear: AoT saves calls and orchestration code but places the full burden of tracking states on the model. Tree of thoughts can enforce rigorous bookkeeping in external code, whereas AoT depends on the model keeping its own trace consistent across a long generation.

When to use AoT and how to write the examples

AoT works best on combinatorial problems with checkable intermediate states, such as arithmetic puzzles, constraint satisfaction, scheduling with a few hard rules and small planning tasks. It is less useful for open-ended writing or factual questions, where there is no clear notion of a failed branch.

  • Match the demonstrations to the task structure, because a trace for one puzzle type transfers poorly to another.
  • Show genuine dead ends and short reasons for abandoning them, not only the winning path.
  • Keep state notation compact, such as remaining numbers or filled cells, to limit token growth.
  • Fix an answer marker so downstream code can extract the result.
  • Validate the final answer externally whenever a programmatic checker exists.

Modern reasoning models trained with long internal deliberation already perform similar exploration without demonstrations. For them, AoT-style prompts can still help when a specific search order or output trace is required, but the marginal gain is usually smaller than with standard chat models.

Limitations and common mistakes

The main risk of AoT is unreliable self-evaluation. A model may declare a branch dead when it was viable or accept an invalid state as correct, and nothing in the prompt can enforce the rules.

ProblemCauseRemedy
Search stops too earlyExamples are too shortInclude longer traces with several retreats
Invalid intermediate statesModel miscalculates silentlyAdd explicit state checks in examples
Output exceeds token limitSearch space is too largeRestrict depth or split the problem
Answer contradicts its own traceWeak final consolidationRequire restating the winning path
Typical problems with AoT prompts

Another mistake is treating AoT as a guarantee of correctness. It improves exploration efficiency, yet the result remains a model output that needs verification wherever errors are costly.

Understanding it simply

Think of solving a maze on paper. You try one corridor. If it ends in a wall, you go back and try another. You keep going until you reach the exit.

Algorithm of thoughts teaches an AI model to do the same thing in writing. The prompt shows it a few solved puzzles, including the wrong turns. The model learns to try, check, back up and try again, all in one answer.

The benefit is speed and cost. The model asks itself the questions instead of waiting for a separate program to guide each step.

Applied in practice

A logistics planner uses a language model to draft shift rosters for a small warehouse team of eight people over five days. Each roster must respect rest periods, skill requirements and personal availability, so many first drafts break at least one rule.

The planner writes an AoT prompt with two worked examples. Each example assigns shifts day by day, checks the constraints after every assignment, records the conflict when a rule fails and backtracks to the last valid day. The new request follows the same format in a single model call.

Compared with a plain request, the share of rosters that pass the planner’s automatic rule checker rises noticeably. The remaining failures are mostly arithmetic slips in counted hours, so the planner keeps the external checker as the final gate and asks the model to repair any roster that fails it.