Documentation
¶
Overview ¶
Package planning implements tree-search backtracking over candidate states (Yao et al. ToT, NeurIPS 2023 arXiv 2305.10601; Zhou et al. LATS, ICLR 2024 arXiv 2310.04406). A value function scores each state, the search expands the best candidates breadth-first, and branches that dead-end (no expansion) are pruned so the search backtracks to the next best alternative.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PlanWithBeamSearch ¶
func PlanWithBeamSearch( provider types.ChatProvider, model, root, expandPrompt, scorePrompt string, beamWidth, maxDepth int, ) (string, error)
PlanWithBeamSearch runs a model-driven BeamSearch over a root plan state and returns the best reachable plan (or the root when nothing expands). It is the integration point that feeds real model outputs into the tree search.
Types ¶
type Expander ¶
Expander generates the candidate next states reachable from a state. An empty result means the state is a leaf (dead-end for that branch).
type ModelExpander ¶
type ModelExpander struct {
Provider types.ChatProvider
Model string
Prompt string // instructions for expansion, e.g. "suggest the next plan step"
}
ModelExpander asks an LLM provider to generate the candidate next states reachable from a state. It implements Expander so BeamSearch can be driven by real model outputs in the live agent loop.
func (*ModelExpander) Expand ¶
func (e *ModelExpander) Expand(state string) []string
Expand returns candidate next states generated by the model.
type ModelScorer ¶
type ModelScorer struct {
Provider types.ChatProvider
Model string
Prompt string // instructions for scoring, e.g. "rate this plan step 0..1"
}
ModelScorer asks an LLM provider to score a state on a 0..1 scale. It implements Scorer.
func (*ModelScorer) Score ¶
func (s *ModelScorer) Score(state string) float64
Score returns the model's 0..1 value for a state.
type Node ¶
Node is one state in the search tree.
func BeamSearch ¶
BeamSearch explores the tree from root breadth-first, keeping the top beamWidth candidates per depth, and backtracks by pruning branches that dead-end (produce no children). It returns the highest-scoring leaf reached within maxDepth, or nil if nothing expands.
It is deterministic given deterministic Expander/Scorer implementations.