Behaviors

A behavior is a visual graph that defines agent logic. Each behavior starts with a Trigger node that maps to one of Mesa's two real entry points:

  • On Init — Runs once when the agent is created (__init__). Use for setup logic like connecting to databases, initializing counters, or computing derived state.
  • On Step — Runs every model tick (step()). Use for the agent's recurring behavior: movement, decision-making, state changes.

Graph Structure

Every behavior graph starts with a Trigger node. The white exec wire flows from the Trigger through your logic nodes in order.

A simple On Step behavior might be:

Trigger (On Step) → Move (random walk)
Trigger (On Step) → Get Property (energy) → Subtract (1) → Set Property (energy)
Trigger (On Step) → Get Property (energy) → Compare ≤ 0 → Branch → Remove Self

Flow Control

Use flow control nodes to create complex logic:

  • Branch — If/else based on a boolean condition
  • Sequence — Execute multiple paths in order (then_0, then_1, ...)
  • ForEach — Loop over a collection (e.g., neighbors)
  • Gate — Only execute if a condition is true (no else branch)

Working with Data

Data flows through colored wires. Each data type has a color:

  • Blue — Integer
  • Green — Float
  • Red — Boolean
  • Yellow — String
  • Purple — Agent reference

Expression nodes (math, compare, logic) have no exec ports — they compute values on demand when a downstream node reads their output.

Multiple Behaviors

An archetype can have multiple behaviors. On Step behaviors execute in order during each tick — the behavior list is the execution schedule. On Init behaviors run once at agent creation. Use separate behaviors to organize complex logic (e.g., a "Setup" init behavior, then "Movement", "Feeding", and "Reproduction" step behaviors).