Behaviors


Agents can (and typically do) have behaviors:

{
    ...
    behaviors: ['eats_fruit.js', 'messages_friends_fruit.py', 'has_friends.js']
}

Behaviors allow agents to exhibit agency in the simulation. An agent can have any number of behaviors.

Behaviors are pure functions in the form of: (current_state, context) => { // update state }

To run your simulation with hCloud, you'll need to define Behavior Keys for each behavior in your simulation.

The exact semantics vary by programming language, but in spirit every behavior is a pure function which receives a given agent's state, the world context visible to that agent, and produces its next state.

During a timestep an agent passes its state and context to its associated behaviors, modifying its state

Most behaviors output a single state with the same agent_id as they received. For example, the following behavior code causes an agent to move along the x-axis:

JavaScript
Python
const behavior = (state, context) => {
  state.position[0] += 1;
};

Agents can use behaviors to create new agents by sending a message to the special hash agent. This is covered more in-depth in Messages.

Previous

Join our community of HASH developers