The tree format

Node types, decorators and the .beetree.yaml file format.

A behavior tree decides what an agent does by walking a tree from the root every moment. Each node reports success, failure or running.

A complete example

version: "1.0"
metadata:
  name: guard
  description: Patrol, chase and attack
  tags: [enemy, melee]
tree:
  type: selector
  name: guard_ai
  children:
    - type: sequence
      name: combat
      children:
        - {type: condition, name: can_see_target}
        - {type: action, name: chase_target}
    - {type: action, name: patrol}

Read it as: try to fight; if that fails, patrol.

Node types

TypeChildrenMeaning
actionnoneDoes something (move, attack, wait). May return running while it works.
conditionnoneChecks something and returns success or failure immediately.
sequence1 or moreRuns children in order and stops at the first that does not succeed. “Do all of these.”
selector1 or moreRuns children in order and stops at the first that does not fail. “Try these until one works.”
parallel1 or moreRuns all children each tick. Fails if any fails.
decoratorexactly 1Changes its child’s behaviour (see below).
subtreenoneRuns another tree file and returns its result (see Subtrees).

Every node needs a unique name. Leaves may also set node, the implementation id your engine provides, plus description and parameters.

Parallel

A parallel ticks every child on every tick, in order, even after one of them fails. It then fails if any child failed, is running if any child is still running, and succeeds when all succeeded. A failure decides the result, but it does not hide the other children: each one still runs and appears in the trace.

version: "1.0"
metadata:
  name: run_and_gun
  description: Move, aim and shoot in the same tick
tree:
  type: parallel
  name: run_and_gun
  children:
    - {type: action, name: shoot}
    - {type: action, name: move}
    - {type: action, name: aim}

beetree simulate run_and_gun.beetree.yaml --override shoot=FAILURE shows shoot failing, then move and aim succeeding, and run_and_gun failing. The web builder runs a parallel the same way.

Decorators

Set decorator: on a decorator node.

DecoratorEffect
repeatRun the child forever
negateSwap success and failure
always_succeed / always_failForce the result
until_fail / until_succeedKeep running until the child gets that result
retryRe-run a failing child (attempts, default 3)
timeoutFail if the child runs longer than seconds
cooldownAfter the child finishes, fail for seconds before allowing it again

Reactive evaluation

BeeTreeCraft’s runtime re-evaluates the tree from the root every tick. Put urgent checks (like “am I about to die?”) first and they will interrupt whatever lower-priority branch was running. Every sequence and selector is reactive: it starts again from its first child on each tick, so conditions in front of a running action are checked again too. Reactive versus memory nodes explains the trade-off and the memory version some engines use.

One tree, several agents

A squad tree drives several agents at once. The tree ticks once per frame, and each leaf names the agent it acts on with parameters.slot. The slots are leader, flanker and support. A leaf with no slot acts on the leader, so trees written for a single agent keep working. The validator rejects any other slot name.

version: "1.0"
metadata:
  name: squad
  description: One tree, three roles
tree:
  type: parallel
  name: squad_ai
  children:
    - {type: action, name: hold_position, parameters: {slot: leader}}
    - {type: action, name: circle_target, parameters: {slot: flanker}}
    - {type: action, name: follow_leader, parameters: {slot: support}}

A slot with no agent in the scene makes its leaf fail.

Explore’s Demo scene 3 runs this pattern; its tree is examples/squad.beetree.yaml.

Subtrees

A subtree node runs another tree file and returns that tree’s result, so a behavior written once (fleeing, first aid) is shared by every tree that needs it. Name the file directly with file, or list it once under subtrees and point at it with ref. Paths are relative to the tree that names them.

subtrees:
  - {name: flee, file: subtrees/flee.beetree.yaml}

and then, among a composite’s children:

- {type: subtree, name: run_away, ref: flee}
- {type: subtree, name: patch_up, file: subtrees/first-aid.beetree.yaml}

beetree validate, simulate, render and generate read the subtree files and build them in, so the generated code contains the whole behavior; the subtree’s blackboard variables join the tree’s own. A tree that includes itself, or a subtree file that does not exist, is rejected with the file and path of the reference that broke, such as loop.beetree.yaml tree.children[0]: subtree "back" includes itself: main.beetree.yaml -> loop.beetree.yaml -> main.beetree.yaml. The builder cannot open files from your disk, so there a subtree acts as one leaf and you choose the result the whole subtree returns. The full example is examples/caravan-guard.beetree.yaml.

Blackboard and custom nodes

Optional top-level blackboard (typed shared variables) and custom_nodes (your own node types with typed parameters) generate richer engine code. See examples/full-enemy-ai.beetree.yaml in the repository for a complete example.

When a leaf’s node: names one of the tree’s custom nodes, beetree validate checks its parameters: each must be one the custom node declares (a typo is answered with the closest declared name), and its value must fit the declared type (int, float, bool and string are checked). A custom node may be declared only once. A node: that names no declared custom node is treated as a plain engine class name and is not checked.

JSON Schema

The format is described by a JSON Schema (draft 2020-12), hosted at two addresses:

AddressHoldsUse it for
https://beetreecraft.com/schemas/v1/beetree.schema.jsonThe schema for format version 1 (version: "1.0")Anything pinned: a lint check in pre-commit or CI, a copy kept in your repository
https://beetreecraft.com/schemas/beetree.schema.jsonThe newest schema, whatever the format versionAn editor that should always follow the latest format

Pin the versioned address. Within a format version the schema only grows: a tree that is valid under v1 today stays valid under v1 after every release, so a check pinned to it never starts failing because the site changed. A change that would reject a tree that was valid comes with a new format version and a new address (v2), and v1 stays as it is. The schema’s own $id is the versioned address. Today both addresses serve the same file.

Point your editor at it to get completion and inline errors while you write a tree. In VS Code with the YAML extension, add this as the first line of your file:

# yaml-language-server: $schema=https://beetreecraft.com/schemas/v1/beetree.schema.json

The schema checks structure: required fields, the six node types, and child counts (leaves take none, sequence, selector and parallel take at least one, a decorator takes exactly one). Run beetree validate for the full set of checks: unique node names, known decorators, blackboard defaults that fit their type (int, float, bool and string are checked), duplicate blackboard variables, subtree references, custom node references and their parameters (the schema cannot check these), and no fields the format does not define (a misspelt field is named, with the closest valid one).

To run both checks on every commit and in CI, copy a recipe from Lint trees in pre-commit and CI.