Planning & Control Flow

Agentic Behavior Tree

Borrow the behavior-tree formalism: leaves are LLM calls or tools that return success/failure; a tree of selectors and sequences orchestrates control flow.

Problem

Free-form ReAct gives the LLM total freedom over control flow, which is brittle on tasks where the design intent is exactly a structured sequence of try-then-fallback. Prompt chains hard-code one path with no fallback. Custom orchestrators reinvent BT semantics ad-hoc per project. Without a first-class BT layer, the team rebuilds the same selector/sequence/decorator vocabulary every time, with diverging implementations and no shared mental model.

Solution

Build the agent as a tree. Interior nodes are Selectors (try children left-to-right, succeed on first success) and Sequences (run children left-to-right, fail on first failure), plus standard decorators (Retry, Timeout, Invert). Leaves call the LLM or a tool and return SUCCESS or FAILURE. The tree executes top-down per tick; status propagates up. The tree itself is a versioned artifact reviewers can read. Distinct from [[plan-and-execute]] (one-shot plan + sequential run): a behavior tree is the structure of the controller across runs.

When to use

  • Control flow has structured retries, fallbacks, and escalations.
  • Reviewing the agent's structure is a first-class need.
  • Multiple leaf implementations (LLM, tool, sub-agent) need uniform success/failure semantics.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related