Sollimann/bonsai
Rust implementation of behavior trees for deterministic AI (now with Python bindings)
What it solves
Bonsai provides a structured way to define complex, modular, and reactive behaviors for AI and robotics systems. It replaces cumbersome state machines by using Behavior Trees (BTs), which allow developers to organize the order and rules of execution for various processes in a more manageable way.
How it works
Bonsai implements Behavior Trees as a tree structure where each node represents a process. Each node returns one of three signals: Success, Failure, or Running. Parent nodes use these signals to determine the next action based on the logic defined by the node type:
- Sequence: Executes children in order; moves to the next if the previous one succeeds.
- Select: Tries children in order; moves to the next if the previous one fails.
- Parallel nodes:
WhenAll,WhenAny, andRaceallow multiple processes to run simultaneously with different completion criteria. - Control nodes:
If,Invert, andWhileloops handle conditional logic and repetition.
To maintain responsiveness, long-running tasks can be dispatched to background threads and tracked via channels to avoid blocking the tree traversal.
Who it’s for
This library is for developers working in AI and robotics who need to build reactive systems that can handle complex decision-making processes across both Rust and Python environments.
Highlights
- Cross-language support: Available as a Rust crate and a Python package (
bonsai-bt). - Modular design: Enables the creation of complex systems that are easy to modify and scale.
- Reactive execution: Designed to handle real-time responses to environment changes.
- Non-blocking: Supports asynchronous and background task execution for long-running operations.
Related
- Project
- Project
- Project
- Project
- Project