What It Is

A lightweight, header-only behavior tree library for C++23. Tree structure is resolved at compile time, execution is flattened, and node dispatch runs in sub-nanosecond time.

auto tree = (CheckBattery{} && Attack{}) || RunAway{};
tree.process(Tick{}, ctx);  // ~0.9 ns for full tree evaluation

Why It Exists

Existing behavior tree libraries (like BehaviorTree.CPP) use runtime polymorphism, heap allocation, and XML configuration. That’s fine for many use cases, but not when you’re running on constrained hardware with strict latency budgets.

How It Compares

behavior-tree-liteBehaviorTree.CPP
DispatchCompile-time (~0.1 ns)Runtime polymorphism (~15-30 ns)
Tree definitionC++ operators: && || !XML or runtime builder
DependenciesNone (STL only)Boost, tinyxml2, cppzmq
AllocationsZero (stack-only)Heap (shared_ptr, strings)
Header-onlyYesNo (shared library)
Binary sizeMinimal~500 KB shared lib

Features

  • Compile-time composition – tree structure flattened at compile time
  • Expressive DSL&&, ||, ! to compose trees naturally
  • Stack-based eventsstd::variant, no virtual dispatch
  • Built-in tree visualizer for debugging
  • ROS 2 ready – includes package.xml and ament_cmake integration

Installation

# CMake FetchContent
include(FetchContent)
FetchContent_Declare(behavior-tree-lite
    GIT_REPOSITORY https://github.com/PavelGuzenfeld/behavior-tree-lite.git
    GIT_TAG main)
FetchContent_MakeAvailable(behavior-tree-lite)
target_link_libraries(your_target PRIVATE behavior_tree_lite)

View on GitHub