# Behavior Trees Behavior trees define the decision-making logic for characters, institutions, and other entities. They model how an entity chooses actions, responds to conditions, and adapts to its environment. Storybook uses behavior trees for character AI, NPC routines, and complex reactive behavior. ## What is a Behavior Tree? A behavior tree is a hierarchical structure that executes from root to leaves, making decisions based on success/failure of child nodes: - **Composite nodes** (choose, then) have multiple children and control flow - **Condition nodes** (if, when) test predicates - **Action nodes** execute concrete behaviors - **Decorator nodes** (repeat, invert, timeout, etc.) modify child behavior - **Subtree nodes** (include) reference other behavior trees Behavior trees are evaluated every tick (frame), flowing through the tree from root to leaves until a node returns success or failure. ## Syntax ```bnf ::= "behavior" ::= "{" * "}" ::= | | | | | ::= "choose"