Agentic Behavior Tree
also known as ABT, Behavior Tree for LLM Agents
Borrow the behavior-tree formalism: leaves are LLM calls or tools that return success/failure; a tree of selectors and sequences orchestrates control flow.
Context
An agent needs structured orchestration with clear fallback semantics — try one approach; if it fails, try the next; if all fail, escalate. Pure prompt chains and free-form ReAct loops have no first-class concept of 'failure of a sub-task triggers the sibling branch'. Behavior trees, widely used in game design and robotics, are the canonical formalism for this shape.
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.
Forces
- Selector (try children until one succeeds) and Sequence (run all children, fail on first failure) are the core BT primitives.
- Leaves can be LLM calls, tool invocations, or even sub-agents.
- Success/failure must propagate cleanly upward.
- Retries, timeouts, and decorators (e.g. invert, always-succeed) are standard BT extensions.
Example
A customer-onboarding agent's behavior tree at the top level is a Sequence: validate identity → set up account → send welcome. The validate-identity child is a Selector: try OAuth → fall back to email-verify → fall back to escalate-to-human. Each leaf is an LLM call or tool. If OAuth fails, the agent moves to email-verify without the LLM having to reason about fallback structure.
Diagram
Solution
Therefore:
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.
What this pattern forbids. Control flow with structured fallback must not be left entirely to LLM reasoning; selector/sequence/decorator semantics are explicit in the tree.
The smaller patterns that complete this one —
- usesFallback Chain★★— Try a primary handler; on failure or low confidence, fall through to a sequence of fallback handlers.
And the patterns that stand alongside it, or against it —
- alternative-toPlan-and-Execute★★— Plan all the steps once with a strong model, then execute each step with a cheaper model under the plan.
- alternative-toReAct★★— Interleave a single thought, a single tool call, and a single observation per step so the agent reasons over fresh evidence.
- complementsBehavior Tree Back Chaining·— Construct an agent's behavior tree starting from the desired goal condition and recursively adding child nodes whose post-conditions satisfy each parent's pre-conditions.
- composes-withAgent-as-Tool Embedding★— Wrap a sub-agent (with its own loop, prompt, and tool palette) behind a single function-shaped tool signature, so the parent agent calls it like any other tool and never sees the sub-agent's internal turns.
- complementsCircuit Breaker★★— Stop calling a failing dependency for a cooldown period after error rates exceed a threshold.
- complementsDegenerate-Output Detection★— Detect when the agent is about to emit a near-duplicate of its own recent output and either drop, replace, or escalate to a stronger model rather than ship the loop.
Neighbourhood
Click any neighbour to follow the language. Scroll to zoom, drag to pan.