The examples below are minimal, made-up scenarios to help you get going. For real-world usage of bonsai-bt in the wild, see:
- utahrobotics/utah-lunabotics-2026 — orchestrates core autonomy on a lunar rover. The team placed 3rd out of 50 in the autonomy challenge at NASA Lunabotics 2026.
- catornot/bp-ort — NPC plugins for Titanfall 2 mod servers (Northstar). Live demo.
- AnotherlandServer/anotherland — NPC behaviors for the Anotherland MMORPG.
cargo build --package examples
Demonstrates use of a behavior tree in minimal and easy to follow console application setting where a fictional non-playing game character updates its AI state. Run and inspect this example if you want to get a quick introduction on how behavior tree can be used in an application.
cargo run --bin simple_npc_ai
Two short console demos in one binary, showing the difference between memoryless composites and their stateful (memory) siblings:
- memoryless
Sequence(Sequence(...).memory(false)) — chase while visible. When visibility flips off mid-chase, the runningChaseaborts on the next tick because the leadingEnemyVisiblecheck is re-run from scratch. A regularSequencewould resume the running child and keep chasing. - memoryless
Select(Select(...).memory(false)) — priority preemption.Attackis preferred overChase. While the enemy is out of range, attack fails and chase runs. Once the enemy enters range, the next tick preempts the chase and runs attack.
cargo run --bin memoryless_chase
Constructing boids flocking behavior by copying the same behavior tree across many agents. Each agent follows the following rules:
- Fly towards the center of the swarm
- Avoid other agents and predators (predator being the mouse cursor)
- Match the velocity of other agents
cargo run --bin boids
PS! if for some how you're unable to build and run the example, it is most likely because you're lacking some dependencies. Try installing the following dependencies:
sudo apt-get update && sudo apt-get install libudev-dev pkg-config librust-alsa-sys-dev
This is basically a really chaotic 3d animation intended to show how you can create a reactive and responsive animations including behaviors such as shape-shifting, color changes, mouse callback, object rotation and translation and timers.
cargo run --bin 3d
This is an example to simulate behavior of a drone, where some of the task called in the behavior tree are long-running and must be conducted in background threads to avoid blocking the execution of the tree.
The simulated drone will first take off, then if the batteries allow it fly to a goal point and then land. If the batteries are too low, the drone will fly back to the docking station. Finally the drone will land. All of this is done while collision avoidance is running in parallell.
cargo run --bin async_drone
Compile the behavior tree into a graphviz compatible DiGraph.
cargo run --bin graphviz
This simple example shows an example of using the Race behavior to time out a long-running job that takes a random amount of time to complete.
cargo run --bin race_timeout
A live web-based visualizer for a running behavior tree. The example builds a 30-node tree (one memoryless Sequence and one memoryless Select included — memory = false, both drawn with a dashed circle), enables the visualizer via a single API call BT::with_telemetry(8910), and re-ticks every ~400 ms so leaf statuses (green / yellow / red) and the running-path highlight animate continuously.
To see it in example, run the following command:
cargo run --bin visualizer_smoke
Then open http://127.0.0.1:8910/ in a browser. The tree renders within ~1 s and the status bar reads connected / 30 nodes. Ctrl-C and restart — the page reconnects within ≤ 1 s. See the module-level doc comment at src/visualizer_smoke/main.rs for the full DFS tree layout and the per-leaf status-cycle rationale.





