# 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.

- **Category**: Agentic AI
- **Subcategory**: Planning & Control Flow
- **Canonical URL**: https://designpattern.fyi/patterns/agentic_behavior_tree/

---

## Description
**Intent**: 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.
**Solution**: - Build the agent as a tree of nodes. - 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 upward. - The tree itself is a versioned artifact that reviewers can read and diff.


## Use Cases
- 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.





## Trade-offs


### Advantages

- Retry, fallback, and escalation are first-class structural choices.

- Reviewable as a tree, not a prompt.

- Composes naturally with sub-agents at leaves.




### Considerations & Drawbacks

- Tree authoring is up-front design work; ad-hoc cases want to bypass the tree.

- Mixing LLM leaves with deterministic ones complicates timing and cost reasoning.

- Authors may overuse decorators to paper over leaf flakiness.







---
**Reference**: [Original Source](https://www.agentpatternscatalog.org/patterns/agentic-behavior-tree/)

