Help us shape the future of Go! Take the 2026 Go Developer Survey

planning

package
v0.0.0-...-a92561a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 6 Imported by: 0

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

type Expander interface {
	Expand(state string) []string
}

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

type Node struct {
	State    string
	Score    float64
	Depth    int
	Children []*Node
}

Node is one state in the search tree.

func BeamSearch

func BeamSearch(root string, expand Expander, score Scorer, beamWidth, maxDepth int) *Node

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.

type Scorer

type Scorer interface {
	Score(state string) float64
}

Scorer is the value function: higher is better.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL