← all repositories
Sollimann/bonsai

Behavior trees that won't ghost your game loop

A Rust BT library with Python bindings, built for deterministic AI that can't afford to block.

546 stars Rust AgentsOther AI
bonsai
Velocity · 7d
+0.4
★ / day
Trend
steady
star history

What it does

Bonsai implements behavior trees in Rust for AI that needs to be predictable and responsive. Nodes return Success, Failure, or Running; parents compose them with sequences, selectors, parallel runs, and inversions. The library also ships Python bindings that wrap the same Rust crate, so you can prototype in Python and port without semantic drift.

The interesting bit

The crate explicitly solves the “long-running task” problem that trips up naive BT implementations: it dispatches blocking work to background threads and polls completion through channels, keeping the tree traversal instant. This is the kind of boring infrastructure that separates toy BTs from production ones.

Key highlights

  • Core composites: Sequence, Select, If, Invert, While, WhenAll, WhenAny, Race, After
  • Python bindings in bonsai-py/ with side-by-side Rust/Python examples
  • Direct continuation of the ai_behavior crate from the Piston project
  • async drone example demonstrates background task dispatch
  • Published on crates.io as bonsai-bt

Caveats

  • The README notes Rust 1.72+ but doesn’t specify if this is a hard floor or aspirational
  • No explicit performance benchmarks or comparison numbers against the “similar crates” it lists

Verdict

Worth a look if you’re building game AI or robot control in Rust and need deterministic, non-blocking behavior trees. Skip if you want a visual editor or baked-in planner; this is code-first infrastructure.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.