39 releases (breaking)

0.31.0 Jun 10, 2019
0.29.0 Jun 6, 2019
0.27.0 Feb 6, 2019
0.26.0 Nov 15, 2018
0.0.1 Dec 13, 2014

#1 in #ai

Download history 145/week @ 2019-09-26 112/week @ 2019-10-03 40/week @ 2019-10-10 153/week @ 2019-10-17 126/week @ 2019-10-24 162/week @ 2019-10-31 47/week @ 2019-11-07 81/week @ 2019-11-14 79/week @ 2019-11-21 134/week @ 2019-11-28 90/week @ 2019-12-05 648/week @ 2019-12-12 30/week @ 2019-12-19 81/week @ 2019-12-26 39/week @ 2020-01-02

631 downloads per month
Used in 4 crates (2 directly)

MIT license

429 lines

ai_behavior Build Status Docs

AI behavior tree

You can serialize the behavior tree using Serde and e.g. Ron.

What is an AI behavior tree?

An AI behavior tree is a kind of state machine logic for processes.

Many things that a game logic does, e.g. controlling AI characters, fits the pattern of AI behavior trees.

An AI behavior tree is a very generic way of organizing interactive logic. It has built-in semantics for processes that signals Running, Success or Failure.

For example, if you have a state A and a state B:

  • Move from state A to state B if A succeeds: Sequence([A, B])
  • Try A first and then try B if A fails: Select([A, B])
  • Do B repeatedly while A runs: While(A, [B])
  • Do A, B forever: While(WaitForever, [A, B])
  • Wait for both A and B to complete: WhenAll([A, B])
  • Wait for either A or B to complete: WhenAny([A, B])

See the Behavior enum for more information.

Parallel semantics

This library has parallel semantics for AI behavior trees. It means that multiple processes can happen at the same time and the logic can be constructed around how these processes runs or terminate.

For example, While(A, [B]) runs both A and B at the same time. If either A or B fails, then the whole while-behavior fails.

A property of AI behavior trees with parallel semantics is that you can control termination conditions externally, as opposed to most programming languages where termination condition is controlled internally:

while A() {
    // This inner loop will never terminate unless `B` fails.
    while true {
      B();  // Runs `B` forever.
// This will terminate if `A` stops running, which also stops `B`.
  While(WaitForever, [

How to contribute


~29K SLoC