Summary
Squad AI patterns address how groups of AI agents coordinate their behaviour without each agent needing to know the full tactical picture. The most scalable approach is a hierarchical architecture: multiple layers of decision-making at increasing levels of abstraction, with orders flowing downward and status reports flowing upward.
The canonical implementation described here is the Killzone 3 bot AI (Guerrilla Games, Chapter 4, see source-game-ai-pro-360-tactics-strategy), which uses three layers — individual bot, squad, and commander — each with its own HTN planner and information sources.
Key ideas
- Layers, not monoliths: Each layer only knows what it needs. Individual bots manage perception, locomotion, and moment-to-moment combat. Squads manage tactical positioning and group movement. Commanders manage objective assignment and resource allocation.
- HTN planning at every layer: HTN (Hierarchical Task Network) planning is used at both the individual and squad layers. It provides prioritised, predictable plan decomposition without the search overhead of GOAP.
- Information flows down as orders; up as completion messages. Layers never reach across — the commander does not directly control an individual bot, and a bot never tries to reason about objectives.
- Strategic graph: A cluster-level summary of the waypoint graph, used for squad-level pathfinding and influence propagation. Provides the spatial vocabulary for squad and commander reasoning.
Three-layer architecture
Commander
│ objective assignment
▼
Squad (HTN planner)
│ move orders, attack orders, hold orders
▼
Individual bot (HTN planner)
│ actions: move, shoot, take cover, throw grenade
▼
Game world / perception
Individual bot layer
The bot layer handles:
- Perception: Vision, hearing, contact detection. Maintained continuously regardless of squad state.
- Self-preservation: Health-triggered retreat, cover seeking. These override squad orders when life is at immediate risk.
- HTN plan execution: The root task (
behave) decomposes into a prioritised set of branches:- Self-preservation (health critical → flee/heal)
- Class abilities (e.g. medic → heal nearby allies if available)
- Squad orders (execute the current movement or attack order)
- Default combat (fall back to autonomous combat behaviour if no order is active)
Each branch has preconditions — the bot only enters a branch if its conditions are met. This ordering gives designers explicit control over priority without complex condition trees.
Continuation conditions check whether an active plan remains valid on each tick. If the plan becomes invalid (e.g. the target moves out of reach), the bot replans immediately rather than completing an obsolete action sequence.
Squad layer
The squad layer runs its own HTN planner, using:
- Strategic graph for routing squads between strategic locations.
- Influence map (see influence-maps) for threat-cost-weighted pathfinding — squads avoid routes with high enemy influence.
- Orders from the commander as the top-level goal.
The squad planner produces orders for each of its member bots: move to position X, provide covering fire on sector Y, hold until the other squad reaches objective Z.
Area corridors: The strategic graph defines corridors — sequences of strategic graph edges between two locations. Individual bots are constrained to navigate within their squad’s assigned corridor. This prevents bots from pathfinding across the entire map, reducing NavMesh overhead and keeping the squad coherent.
Commander layer
The commander assigns objectives to squads. In Killzone 3, the commander uses a greedy heuristic:
- Identify all current strategic objectives (capture points, player last known positions, etc.).
- Score each objective for each squad based on: travel cost (strategic graph distance), squad strength, and objective priority.
- Assign each squad the highest-scoring unassigned objective.
- Reassign periodically or when a squad completes its objective.
The commander does not micromanage. Once an objective is assigned, the squad planner determines how to execute it.
HTN planning detail
HTN planning works by decomposing abstract tasks into concrete subtasks through methods — conditional decomposition rules. Each method has:
- A set of preconditions (what world state must hold)
- A decomposition (the ordered list of subtasks this method produces)
The planner tries each method for the current task in priority order. The first method whose preconditions are satisfied is applied, producing subtasks that are in turn decomposed until only primitive actions remain.
Example domain fragment (Killzone 3 bot)
Task: behave
Method 1: [precondition: health < 20%]
→ flee-to-safety
Method 2: [precondition: isMediac AND nearbyAllyNeedsHealing]
→ heal-ally
Method 3: [precondition: hasSquadMoveOrder]
→ execute-squad-move-order
Method 4: [precondition: canSeeEnemy]
→ combat-behaviour
Method 5: [precondition: always]
→ idle-patrol
Method 1 always takes priority — a dying bot does not execute squad orders. This is cleaner to read and maintain than a large utility scoring function, and priority is unambiguous.
Replanning rate
The HTN planner does not replan every frame. Replanning is triggered by:
- A plan step completing.
- A continuation condition failing (the current plan is no longer valid).
- A new squad order arriving.
- A fixed-rate background check (catching cases the above miss).
This keeps replanning cost bounded while maintaining responsiveness.
HTN vs. GOAP vs. Behaviour Trees
| Behaviour Tree | GOAP | HTN | |
|---|---|---|---|
| Priority control | Structural (child order) | Implicit (cost function) | Explicit (method order) |
| Plan composition | Reactive, no planning | Full search | Structured decomposition |
| Designer legibility | High | Low–medium | High |
| Surprise behaviours | Rare | Common | Rare (predictable) |
| Best for | Reactive agents | Multi-step goal pursuit | Hierarchical role-based bots |
HTN is favoured for squad bots because designers can read and predict the plan without simulating the planner. Unexpected behaviours in multiplayer shooters are costly — they confuse players and testers alike.
Implementation sketch (Unity)
A minimal HTN framework in Unity C#:
public abstract class HTNTask { }
public class PrimitiveAction : HTNTask
{
public Func<AIAgent, bool> Precondition;
public Action<AIAgent> Execute;
}
public class CompoundTask : HTNTask
{
public List<HTNMethod> Methods;
}
public class HTNMethod
{
public Func<AIAgent, bool> Precondition;
public List<HTNTask> Decomposition;
}
public static class HTNPlanner
{
public static List<PrimitiveAction> Plan(AIAgent agent, CompoundTask root)
{
var plan = new List<PrimitiveAction>();
var tasks = new Stack<HTNTask>();
tasks.Push(root);
while (tasks.Count > 0)
{
var task = tasks.Pop();
if (task is PrimitiveAction action)
{
if (action.Precondition(agent))
plan.Add(action);
else
return null; // Plan failed — replan
}
else if (task is CompoundTask compound)
{
var method = compound.Methods.FirstOrDefault(m => m.Precondition(agent));
if (method == null) return null; // No applicable method
foreach (var sub in Enumerable.Reverse(method.Decomposition))
tasks.Push(sub);
}
}
return plan;
}
}In a real system, the agent also needs a world state model that methods and continuation conditions query — either a snapshot of actual game state or a simplified belief model.
Trade-offs
| Approach | Pros | Cons |
|---|---|---|
| Single global coordinator (e.g. combat-coordinator-pattern) | Simple; low overhead | Couples all agents to one system; hard to scale beyond ~8 agents |
| Three-layer hierarchy | Scales; each layer manageable | Communication latency between layers; framework overhead |
| Decentralised (each agent fully autonomous) | Resilient; no single point of failure | Hard to produce coherent group tactics |
| Scripted choreography | Highly predictable; designer control | Not adaptive; breaks if agents die or obstacles change |
The three-layer hierarchy is the right choice when:
- The game has meaningful squad-level tactics (capture, push, defend).
- Designers need direct control over priority and plan structure.
- NPCs need to remain responsive to both squad orders and personal threat.
For CRE341, this makes HTN via squad AI a strong advanced topic rather than the default first architecture. See overview-cre341-agent-ai-route for the recommended route.
Examples
- Killzone 3 (Guerrilla Games): The reference implementation for this pattern. Three HTN layers with strategic graph and influence map at squad layer.
- Halo series (Bungie / 343 Industries): Well-documented hierarchical AI with leader/follower structure and reactive flanking.
- The Last of Us (Naughty Dog): The combat-coordinator-pattern page covers the flatter (coordinator + roles) approach that Naughty Dog used instead of full hierarchical layers.
Evidence
- The Killzone 3 bot architecture is described by the Guerrilla Games AI team (Chapter 4, see source-game-ai-pro-360-tactics-strategy) including the strategic graph construction, influence-weighted squad pathfinding, and commander assignment algorithm.
- HTN planning theory and its application to game AI is covered in depth in the same chapter, including the comparison with GOAP and behaviour trees.
Open questions
- What is the latency cost of the three-layer message-passing model in scenarios where individual bot threats change rapidly (e.g. grenade thrown at squad)?
- Can a single HTN framework serve all three layers, or do the different planning timescales require separate implementations?
- How does the strategic graph remain consistent when objectives are destroyed or the level layout changes (destructible environments)?
Related
tactical-position-selection · influence-maps · combat-coordinator-pattern · game-ai-agent-design · strategic-ai-rts · npc-perception-systems · source-game-ai-pro-360-tactics-strategy