Course contentsShow
← AI Engineering
Lesson 615 of 1,88615. AI Agents - ArchitectureFree lesson

Beam Search and Plan Ranking

Generating multiple candidate plans and selecting the most promising based on heuristics or cost estimates.

Beam Search and Plan Ranking

What you'll learn: How AI agents generate multiple candidate plans simultaneously and select the best one using scoring heuristics.

The Core Idea

When an agent needs to accomplish a complex task, generating just one plan might lead to a dead end. Instead, beam search explores multiple promising paths at once—like a chess player considering several moves ahead on different branches—and ranks them by estimated quality before committing to execution.

How It Works

Beam search maintains a fixed number of candidate plans (the "beam width"). At each planning step:

  1. Generate candidates: For each current partial plan, produce possible next actions
  2. Score all options: Apply heuristics (estimated cost, likelihood of success, alignment with goal)
  3. Keep top-K: Retain only the highest-scoring candidates (e.g., top 3 plans)
  4. Expand iteratively: Repeat until plans reach completion or termination criteria

This differs from ReAct (single plan) or full tree search (exponentially expensive). Beam search balances exploration with computational limits.

Ranking Heuristics

Plans can be scored by:

  • Estimated steps to goal (fewer is better)
  • Tool availability (prefer actions with accessible tools)
  • Historical success rate (learned from memory)
  • Resource cost (API calls, time)
  • Confidence scores from reasoning steps

Why It Matters

Without beam search, agents commit to the first plan they generate—even if it's suboptimal. By maintaining multiple hypotheses and pruning weak ones early, agents avoid local minima and increase success rates on complex, multi-step tasks.

Key Takeaway: Beam search lets agents hedge their bets by exploring several candidate plans in parallel, then selecting the most promising path based on cost estimates or heuristics—improving robustness over single-plan approaches.