Ai behavior trees utility ai

From huytran1120/vie-agentic-skills · View interactive version

Ai behavior trees utility ai is an AI agent skill from the GitHub repository huytran1120/vie-agentic-skills. Build a production behavior-tree runtime (Blackboard, action/condition leaves, sequence/selector/parallel composites, decorators) and a Utility AI system (response curves — linear, exponential, sigmoid, quadratic — considerations, and action evaluators), plus hybrid BT-drives-Utility agents. Use whe

How to use this skill

Skill file

Behavior Trees & Utility AI

Two complementary ways to structure NPC decision-making, plus how to combine them. A

behavior tree (BT) expresses structured, prioritized, reactive logic as a tree that is

"ticked" each step. Utility AI answers "how much do I want each option right now?" by

scoring actions with normalized curves and picking the best. Ship believable agents by using a

BT for structure and Utility AI where graded trade-offs matter.

This skill is the implementation companion to game-ai (which helps you choose between

FSM / BT / steering / pathfinding). Read game-ai to pick a model; read this to build the

runtime.

When to use

Sequence/Selector/Parallel composites, and decorators (Inverter, Cooldown, Repeat).

scores and selects actions (max, softmax, or weighted-random for variety).

choice to a utility evaluator.

When not to use: to choose between FSM, BT, steering, or pathfinding, and for A*/navmesh

routing, use game-ai. For Unreal's asset-based BehaviorTree/Blackboard, BTTask/BTService

and AIController, use unreal-behavior-trees. For the navmesh agent that moves the NPC, use

unity-navmesh or the engine's navigation node.

Core workflow

  1. Pick the model. Structured, prioritized, interruptible behavior → BT. Continuous

"score every option" decisions (targeting, needs, item choice) → Utility. Both → hybrid.

  1. Design the Blackboard first. One typed key/value store per agent is the shared memory that

decouples nodes; leaves read/write it and never hold references to each other.

  1. Write leaves. Conditions return Success/Failure immediately; actions return

Running across frames until they finish. Keep leaves small and side-effect-explicit.

  1. Compose. Selector = OR/fallback (first non-failure wins); Sequence = AND (stop at first

non-success); Parallel for concurrent branches. Wrap with decorators for policy (invert,

cooldown, repeat, force-success).

  1. For Utility: enumerate considerations, map each raw fact through a normalized 0..1 curve,

combine (weighted product with compensation, or weighted sum), then select the max — add

hysteresis so agents don't flip-flop on ties.

  1. Tick deliberately. Tick the tree/evaluator once per decision step (often slower than

render). Preserve Running state between ticks; verify by drawing the active path and the

per-action scores on screen while tuning.

Architecture at a glance

A behavior tree evaluates top-down, left-to-right; each node returns a status up to its parent:

flowchart TD
    Root["Selector (root)"] --> Combat["Sequence: Combat"]
    Root --> Patrol["Action: Patrol"]
    Combat --> See["Condition: CanSeePlayer?"]
    Combat --> InRange{"Selector: Reach"}
    Combat --> Attack["Action: Attack (Running)"]
    InRange --> Close["Condition: InAttackRange?"]
    InRange --> MoveTo["Action: MoveToPlayer (Running)"]

Utility AI is a scoring pipeline — every candidate action is scored, then one is selected:

facts (distance, health, ammo…)
      │  each fact → a normalized 0..1 response curve (consideration)
      ▼
score(action) = weight · combine(consideration_1 … consideration_n)   # product+compensation or sum
      ▼
select: argmax  ·  or softmax / weighted-random for variety  ·  + hysteresis to avoid jitter

Status is a three-value enum shared by every node — this is the contract that makes the tree

composable:

public enum Status { Success, Failure, Running }

public abstract class Node
{
    public abstract Status Tick(Blackboard bb, float dt);
    public virtual void Reset() { }   // called when a parent abandons this subtree
}
// Selector = fallback/OR: return the first child that is not Failure.
// `Current` (from Composite) remembers a Running child so the next tick resumes there.
public sealed class Selector : Composite
{
    public override Status Tick(Blackboard bb, float dt)
    {
        for (; Current < Children.Count; Current++)
        {
            var s = Children[Current].Tick(bb, dt);
            if (s == Status.Running) return Status.Running;            // resume here next tick
            if (s == Status.Success) { Current = 0; return Status.Success; }
        }
        Current = 0;
        return Status.Failure;                                         // every child failed
    }
}

The reciprocal Sequence (AND — stop at first non-Success), the reactive variants that let a

higher-priority branch interrupt a running one, Parallel, the Blackboard, the leaf base

classes, and every decorator are in references/behavior-tree-core.md. The leaves use Unity's

Vector2 member names (magnitude, normalized, sqrMagnitude); in Godot C# use Length(),

Normalized() and LengthSquared().

Utility scoring in one snippet

// A consideration maps one raw fact to 0..1 through a response curve.
float Score(Blackboard bb)
{
    float distance01 = Curves.InverseLerp01(bb.Get<float>("distToPlayer"), 20f, 2f); // near = 1
    float health01   = Curves.Sigmoid(bb.Get<float>("health01"), k: 8f, mid: 0.4f);  // hurt = low
    // A 0 in any factor still vetoes the action; compensation stops each extra
    // consideration from dragging every score toward 0. No allocation per call.
    return Curves.Compensate(distance01 * health01, count: 2);
}

The full curve library (linear, quadratic, exponential, logistic/sigmoid, smoothstep), the

Consideration/UtilityAction types, and the UtilityEvaluator selection strategies are in

references/utility-ai-system.md.

Pitfalls

resume where you left off; only Reset() a subtree when a parent actually abandons it.

trees and conditional aborts (a higher-priority condition can interrupt a lower branch).

Sequence resumes at the running child, so [CanSeePlayer?, Chase] keeps chasing after sight

is lost. Use a ReactiveSequence (re-checks from the first child each tick) or have the action

itself fail when its blackboard input disappears.

Keep the ready-time when the branch is aborted.

dominates. Every consideration must return 0..1.

so the agent commits instead of oscillating.

spawn; keep per-tick work allocation-free.

References

leaves, Sequence/Selector/Parallel, and the decorator library (full C#).

and the UtilityEvaluator (argmax, softmax, weighted-random, hysteresis).

AI, and a hybrid agent, as drop-in templates.

event-driven aborts, and combining Utility AI with BTs (hybrid architecture).

Related skills

VAS installation notes

Imported from gamedev-skills/awesome-gamedev-agent-skills at

19d93f97c9c1ea0f8b306e77aa81e0d3e352d3e9, Apache-2.0.

Copyright 2026 Abhishek Barali and the awesome-gamedev-agent-skills contributors.

The complete upstream LICENSE and NOTICE accompany this standalone skill.

Third-party notices, including the Go-Fonts license where provided, remain intact.

Only documented VAS naming, router-path adaptations and these notes differ;

supporting files and executable modes are preserved.

Use Copy Agent Prompt in the VAS catalog or ./vas install <canonical-id> --target <agent>.

VAS uses its existing agent-folder mapping and CLI-compatible receipt. Installing

a skill only copies/links its payload; it never runs bundled Python/Luau/Go code,

installs engines, SDKs, packages, plugins or MCP servers, connects accounts,

generates assets through paid services, uploads builds or publishes a game.

Review code and request permission before installation, execution, downloads,

external services, private-data submission, purchases or publishing.

Respect the existing project's pinned engine/dependency versions. Baselines in

the upstream runbooks are snapshots, not claims about the newest release.

Actual use may need the matching engine, Go/.NET/Luau/Node toolchain, SDK,

hardware or platform account. create-game-assets' optional image helpers need

Pillow>=10,<14; no Pillow or other runtime dependency is installed automatically.

Generated Ebitengine projects fetch their own Go modules only with approval;

the bundled Go-Fonts notice does not change the license of this runbook.

Storefront publishing, signing credentials and paid asset generation are separate,

explicitly authorized actions. Missing prerequisites or failed commands are errors,

not evidence that a game works or has shipped.

Collection names performance-optimization and godot-export mean VAS canonical IDs

gamedev-performance-optimization and gamedev-godot-export respectively, not the

unrelated existing application-performance or Blender-export skills.

Other source skill names retain their canonical IDs and installed folder names.

Cross-skill composition recommendations do not imply that other independent

skills or external tools have been installed. Each specialized skill includes

its own complete local references, helpers and assets. For automatic selection

across the collection, the separately installable router includes all 77 original

specialized payloads as read-only companions under bundled/skills/, with

RUNBOOK.md filenames rather than additional auto-discovered SKILL.md files.

Read only the selected companion and its references on demand; never execute

its helpers automatically. Bundled companions are references, not extra catalog

records or separately registered agent skills. External engines, documentation,

SDKs, services and generated project's dependencies remain separate prerequisites.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.