liveBook · Manning

Behavior tree

As explained in AI Agents in Action

A behavior tree is a hierarchical control pattern in which nodes represent conditions, actions, and control-flow choices for selecting and executing behavior.

A behavior tree is a hierarchical control pattern for selecting and executing behavior. Its nodes represent conditions, actions, and control-flow choices, producing success or failure rather than Boolean values. section 6.1 section 6.1.1

Build a tree from a small set of cooperating node types:

  • Selector or fallback tries children in order and stops at the first successful child. section 6.1
  • Sequence runs children in order and fails when any required child fails. section 6.1
  • Condition checks state, while an action performs work; decorators wrap behavior and parallel nodes support dual execution. section 6.7
  • Execution proceeds from top to bottom and left to right, falling back when a sequence cannot continue. section 6.1.1

Choosing what to eat

A root selector first tries a sequence containing Has apple and Eat apple. If the condition fails, it tries a second sequence containing Has pear and Eat pear. This makes the tree an explicit decision path rather than a tangled collection of state transitions. section 6.1.1

Running a tree with Python

Using py_trees, define custom condition and action classes, instantiate them, place each pair in a Sequence, and attach those sequences to a root Selector. Change condition results or remove a sequence to observe different behavior. section 6.1.3

Figure 6.8 The ABT for the coding challenge
figure

The coding-challenge ABT shows how separate assistants can perform, review, and verify work through action and condition nodes. section 6.3.2

How AI Agents in Action covers it

How deep it goes
Explains node roles, traversal, tradeoffs, Python construction, and agentic applications, while deferring custom node types and deeper controls.
Examples
Uses apple-or-pear selection, py_trees code, coding challenges, assistant verification, and goal-driven ABT construction.
What you can do after
Build it from scratch in Python, run it with py_trees, and design agent workflows using actions, conditions, and verification paths.
How it connects
Connects behavior trees with robotics, game AI, finite state machines, blackboards, assistants, and back chaining.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action. The section links point to the parts of the book it draws on.