Sollimann/bonsai

Rust implementation of behavior trees for deterministic AI (now with Python bindings)

What it solves

Bonsai provides a modular and reactive way to organize complex behaviors in AI and robotics. It replaces rigid state machines with a tree-based structure that allows developers to create flexible, hierarchical rules for how processes execute and react to their environment.

How it works

Bonsai implements Behavior Trees (BTs), where each node in the tree represents a process that returns a status of Success, Failure, or Running. Parent nodes use these signals to determine the next action. The library provides several control flow nodes, such as:

  • Sequence: Executes children in order until one fails.
  • Select: Tries children until one succeeds.
  • If: Executes a specific child based on a condition.
  • Parallel nodes: WhenAll, WhenAny, and Race allow multiple tasks to run concurrently.
  • Looping: While and WhileAll allow for repetitive behavior based on conditions.

To maintain responsiveness, long-running tasks can be dispatched to background threads and monitored via channels to avoid blocking the tree traversal.

Who it’s for

Developers working in robotics, game programming, and AI agents that require a structured yet flexible way to manage complex, reactive behaviors.

Highlights

  • Multi-language support: Written in Rust for performance, with Python bindings available via PyPI.
  • Reactive design: Supports asynchronous and long-running tasks to ensure the system remains responsive.
  • Comprehensive control flow: Includes a wide array of logic gates (Invert, Timeout, AlwaysSucceed) and parallel execution patterns.

Related

  • Project
  • Project
  • Project
  • Project
  • Project