Behaviors

A behavior is a visual graph that defines what an agent does each simulation step. When Mesa calls agent.step(), Loom executes the behavior graph.

Graph Structure

Every behavior graph starts with an Entry node. The white exec wire flows from Entry through your logic nodes in order.

A simple behavior might be:

Entry → Move (random walk)
Entry → Get Property (energy) → Subtract (1) → Set Property (energy)
Entry → 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. They execute in order during each step. Use separate behaviors to organize complex logic (e.g., "Movement" behavior, "Feeding" behavior, "Reproduction" behavior).