ai-behavior-trees-utility-ai
gamedev-skills/awesome-gamedev-agent-skills
Build production behavior-tree and utility-AI runtimes for NPC decision-making.
What is ai-behavior-trees-utility-ai?
Implement a reusable behavior-tree runtime with blackboard, composites, and decorators, plus a utility-AI scoring system with response curves. Use this to structure NPC decisions beyond simple FSMs, combine behavior trees with utility scoring for hybrid agents, or tune graded trade-offs in enemy/NPC behavior.
- Build a blackboard-based behavior-tree runtime with Sequence, Selector, and Parallel composites
- Implement action and condition leaf nodes with Status enum (Success, Failure, Running)
- Create a decorator library (Inverter, Cooldown, Repeat) to wrap and modify node behavior
- Design utility-AI response curves (linear, exponential, sigmoid, quadratic) and considerations for scoring actions
- Combine behavior trees with utility evaluators for hybrid agents that use BT structure with utility-driven leaf decisions
- Add hysteresis and selection strategies (argmax, softmax, weighted-random) to avoid agent indecision
How to install ai-behavior-trees-utility-ai
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill ai-behavior-trees-utility-ai- Basic understanding of game loops and per-frame updates
- Familiarity with tree data structures and enum-based state machines
- C# or equivalent language for implementation (examples provided in C#)
How to use ai-behavior-trees-utility-ai
- 1.Design your blackboard schema — the typed key/value store each agent will use to share state between nodes
- 2.Implement the Node base class and Status enum, then code Sequence, Selector, and Parallel composites
- 3.Write condition leaves (return Success/Failure immediately) and action leaves (return Running until complete)
- 4.Add decorators (Inverter, Cooldown, Repeat) by wrapping nodes and modifying their tick behavior
- 5.For utility AI, define considerations as functions that map raw facts to 0..1 via response curves
- 6.Build a UtilityEvaluator that scores each candidate action, applies hysteresis, and selects the best one
- 7.Tick your tree or evaluator once per decision step (not every frame); preserve Running state between ticks
- 8.Profile and tune: draw the active tree path and per-action scores on screen while adjusting curve parameters
Use cases
- Build a guard NPC that patrols by default but switches to combat when it sees the player, using a BT with Selector/Sequence composites
- Implement a villager that prioritizes actions (eat, sleep, work) based on utility scores of hunger, fatigue, and task urgency
- Create a hybrid agent where a BT handles high-level strategy but delegates tactical choices (which target, which ability) to a utility evaluator
- Tune enemy behavior by adjusting response curves so difficulty scales smoothly with player distance and NPC health
- Avoid FSM state-explosion by using a BT to express complex, interruptible decision logic with shared blackboard memory
- Game AI programmers implementing NPC behavior systems
- Game designers tuning enemy and NPC decision-making and difficulty curves
- Developers building reusable AI runtimes for multiple agent types
- Teams migrating from simple FSMs to more expressive decision models
ai-behavior-trees-utility-ai FAQ
Use behavior trees for structured, prioritized, reactive logic (patrol → see player → attack). Use utility AI for continuous scoring of graded trade-offs (hunger vs. fatigue vs. task priority). Combine both in a hybrid agent: BT handles high-level flow, utility evaluator picks the best leaf action.
The blackboard is a typed key/value store shared by all nodes in an agent's tree. It decouples nodes so they don't hold references to each other; leaves read/write facts (distance, health, target) and the tree structure remains reusable across different agents.
If you return Success or Failure every tick, the parent re-evaluates and restarts the action. Instead, return Running and resume from where you left off; only call Reset() when a parent actually abandons the subtree (e.g., a Selector picks a different branch).
Add hysteresis: give the currently-running action a small bonus (e.g., +0.05) when re-evaluating, so it must lose by more than the bonus to be interrupted. This makes agents commit to decisions instead of oscillating.
game-ai helps you *choose* between FSM, BT, steering, and pathfinding. This skill teaches you how to *implement* a BT runtime and utility-AI system. Read game-ai first to pick your model, then use this skill to build it.
Full instructions (SKILL.md)
Source of truth, from gamedev-skills/awesome-gamedev-agent-skills.
name: ai-behavior-trees-utility-ai description: > 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 when implementing a reusable behavior-tree or utility-based decision system, or tuning enemy/NPC decisions beyond a simple FSM, or when the user mentions behavior tree, blackboard, decorator, selector, sequence, tick status, utility AI, response/scoring curve, or consideration. For choosing between FSM/BT/steering or for pathfinding, use game-ai; for Unreal's BehaviorTree/Blackboard assets, use unreal-behavior-trees.
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
- Use to build a reusable BT runtime: a
Blackboard,Nodebase, action/condition leaves,Sequence/Selector/Parallelcomposites, and decorators (Inverter, Cooldown, Repeat). - Use to build a Utility AI decider: response curves, considerations, and an evaluator that scores and selects actions (max, softmax, or weighted-random for variety).
- Use to build hybrid AI — a BT whose leaf delegates the "which attack / which target" 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
- Pick the model. Structured, prioritized, interruptible behavior → BT. Continuous "score every option" decisions (targeting, needs, item choice) → Utility. Both → hybrid.
- 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.
- Write leaves. Conditions return
Success/Failureimmediately; actions returnRunningacross frames until they finish. Keep leaves small and side-effect-explicit. - Compose.
Selector= OR/fallback (first non-failure wins);Sequence= AND (stop at first non-success);Parallelfor concurrent branches. Wrap with decorators for policy (invert, cooldown, repeat, force-success). - 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.
- Tick deliberately. Tick the tree/evaluator once per decision step (often slower than
render). Preserve
Runningstate 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.
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.Failure) return s; // Success or Running stops the scan
}
_current = 0;
return Status.Failure; // every child failed
}
}
The reciprocal Sequence (AND — stop at first non-Success), Parallel, the Blackboard, the
leaf base classes, and every decorator are in references/behavior-tree-core.md.
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
// Product + compensation keeps a single 0 from vetoing while low values still dampen.
return Curves.CompensatedProduct(new[] { distance01, health01 });
}
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
- Re-ticking a
Runningaction from the root every frame restarts it. ReturnRunningand resume where you left off; onlyReset()a subtree when a parent actually abandons it. - Deep trees re-evaluated wholesale each tick waste time and cause thrash. Prefer shallow trees and conditional aborts (a higher-priority condition can interrupt a lower branch).
- Un-normalized considerations. If one curve outputs 0..100 and another 0..1, the big one dominates. Every consideration must return 0..1.
- Utility jitter on near-ties. Add hysteresis: give the currently-running action a small bonus so the agent commits instead of oscillating.
- Allocating nodes, closures, or arrays every tick creates GC spikes. Build the tree once at spawn; keep per-tick work allocation-free.
References
references/behavior-tree-core.md— Blackboard,Node/leaf base classes, action & condition leaves,Sequence/Selector/Parallel, and the decorator library (full C#).references/utility-ai-system.md— response-curve library,Consideration,UtilityAction, and theUtilityEvaluator(argmax, softmax, weighted-random, hysteresis).references/practical-examples.md— a guard Patrol→Combat BT, a villager needs-based Utility AI, and a hybrid agent, as drop-in templates.references/best-practices-and-pitfalls.md— memory management, profiling, avoiding deep trees, event-driven aborts, and combining Utility AI with BTs (hybrid architecture).
Related skills
game-ai— choose between FSM / BT / steering; A* and navmesh pathfinding.unreal-behavior-trees— Unreal's asset-based BT/Blackboard, tasks, decorators, services.unity-navmesh— theNavMeshAgentthat carries out "move to" intents.physics-tuning— agent radius, movement, and collision response for the motion layer.tower-defense,fps-shooter,rpg— genres that compose this decision layer.
Related skills
More from gamedev-skills/awesome-gamedev-agent-skills and the wider catalog.

audio-design
Design game audio mixing, adaptive music, and beat-synced SFX using buses, ducking, and layering.

bevy-ecs
Structure Bevy games in Rust using Entity Component System: App, components, resources, systems, and scheduling.

camera-systems
Build smooth, bounded game cameras with deadzone, look-ahead, orbit, and collision—engine-neutral techniques for 2D and 3D.

card-game
Build card games with zones, draw mechanics, turn structure, and effect resolution.

create-game-assets
Plan, generate, source, normalize, and validate cohesive visual game assets for any engine or art style.

dialogue-systems
Build branching dialogue trees with Ink, Yarn Spinner, or a custom JSON runner.