Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Runner

The Runner executes a behavior tree from the file system without writing the application boilerplate. It is a wrapper above the Forester engine that is configured with an optional YAML run profile instead of code.

Unlike Simulation, which replaces the actions with stubs, the Runner performs a real execution: all actions must be implemented, either as remote actions registered in the profile or as built-in actions.

Available since forester-rs 0.7.0 and f-tree 0.4.0.

Run Profile

The run profile is a YAML file where every section is optional and falls back to its default value when absent. An empty file (or no profile at all) gives the default profile: run until the root finishes, no tracing, no blackboard load/dump, no server, no remote actions.

Note: The relative paths in the profile are resolved against the folder that contains the main tree file.

Example profile:

run_until:
  limit: 10          # or `run_until: no_limit` (the default)

bb:
  load: "bb_init.json"
  dump: "bb_final.json"

tracer:
  indent: 2
  time_format: "%H:%M:%S"
  to_file: "trace.log"

api:
  type: http
  host: "localhost"
  port: 8080

actions:
  - type: http
    name: fetch_data
    url: "http://localhost:10000/action"

run_until Section

Defines when the run stops.

SettingDescriptionDefault
no_limitRuns until the root tree returns Success or Failure.
limitRuns at most the given number of ticks.

bb Section

The blackboard configuration.

SettingDescriptionDefaultExample
loadA JSON file with a blackboard snapshot to load the initial data from before the run.None (disabled)bb_init.json
dumpA file to dump the final blackboard state to as JSON after the run.None (disabled)bb_final.json

tracer Section

Maps to the engine tracer.

SettingDescriptionDefaultExample
indentThe indent for the nested trace lines.24
time_formatThe time format for the trace timestamps (chrono format string).None"%H:%M:%S"
to_fileA file to write the trace to. When absent the trace stays in memory.Nonetrace.log

api Section

The HTTP server the engine exposes during the execution. The remote actions send their requests to it to reach the blackboard and the tracer.

SettingDescriptionDefaultExample
typeThe server type. Only http for now.Requiredhttp
hostThe host the server binds to.127.0.0.1localhost
portThe port the server binds to.0 (a random available port)8080

actions Section

The remote actions to register in the engine. The name should match the action name in the tree.

SettingDescriptionDefaultExample
typeThe action type. Only http for now.Requiredhttp
nameThe name of the action in the tree.Requiredfetch_data
urlThe url of the remote server executing the action.Requiredhttp://localhost:10000/action

Process

You can run a tree via the CLI or directly in Rust code.

In the Console

Use the f-tree CLI:

f-tree run --root tree/tests/runner/smoke/ --profile profile.yaml

CLI Defaults:

  • --root: If omitted, defaults to the current working directory (<pwd>).
  • --main: If omitted, defaults to main.tree.
  • --tree: If omitted, defaults to main.
  • --profile: If omitted, the default profile is used. The path is resolved against the root folder.

In the Code

Use Runner from the runner module:

#![allow(unused)]
fn main() {
use std::path::PathBuf;
use forester_rs::runner::Runner;
use forester_rs::runner::config::RunProfile;

fn smoke() {
    let profile = RunProfile::from_file("runner/smoke/profile.yaml").unwrap();

    let mut runner = Runner::build(
        PathBuf::from("runner/smoke/main.tree"),
        "main".to_string(),
        profile,
    )
    .unwrap();

    let result = runner.run().unwrap();
    println!("Result: {:?}", result);
}
}

Runner::build accepts the path to the main tree file, the name of the root tree in that file, and the profile (RunProfile::default() for the default one). Runner::run executes the tree until the root finishes or the run_until tick limit is reached, and afterwards dumps the blackboard if bb.dump is set.