mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Proposal: Define a cohesive behavioral framework API for Mesa

Open falloficaruss opened this issue 9 months ago • 3 comments

Context

Mesa has gained strong building blocks over the last releases (e.g., AgentSet, discrete_space, mesa.time, observables/signals, experimental continuous-space work). However, behavior modeling still tends to be implemented ad hoc per model, with limited shared abstractions for representing decision flow, task execution, and behavior composition.

Related discussions and prior work: https://github.com/mesa/mesa/discussions/2526, https://github.com/mesa/mesa/discussions/2529, https://github.com/mesa/mesa/discussions/2538, https://github.com/mesa/mesa/pull/2851

This issue is not assuming immediate acceptance of a full framework. The goal is to clarify the problem and discuss whether a scoped, incremental approach is worth pursuing.

Problems / Limitations

Today, users can implement behaviors in many ways, but there is no common Mesa-level contract for:

  • Expressing behavior units consistently (action vs task vs event semantics).
  • Composing behaviors (sequence, priority, fallback, interruptibility).
  • Integrating behavior execution with Mesa-native time/event scheduling.
  • Connecting behavior updates to reactive state changes (observables/signals) in a predictable way.
  • Reusing and comparing behavior patterns across examples/models.

Result: duplicated patterns, inconsistent terminology, and higher onboarding cost for advanced behavior modeling.

Candidate Approach

Introduce a minimal experimental behavioral API focused on interoperability, not a full “one true architecture”.

Potential scope:

  • Define a small set of core interfaces/concepts:
  • Task (lifecycle-based executable unit)
  • Behavior (orchestrates task selection/composition)
  • Condition/Predicate (gating and switching logic)
  • Make integration with existing Mesa primitives explicit:
    • scheduling via mesa.time
    • optional reactive triggers via observables/signals

Keep this in mesa.experimental until semantics and ergonomics are validated through real examples. Prefer composable primitives over an opinionated monolithic framework.

Why this might be valuable

  • Reduces reinvention in complex ABMs.
  • Improves readability and comparability of model logic.
  • Creates a clearer path from simple step() models to richer behavior systems.
  • Aligns with Mesa’s established experimental-to-stable evolution pattern.

Questions

  1. What is the smallest useful API surface that avoids overdesign?
  2. Should Mesa standardize terminology first (event, action, task, behavior) before code?
  3. Which 1–2 reference models would be best to validate feasibility and ergonomics?
  4. What criteria should determine whether this remains experimental or moves toward stabilization?

falloficaruss avatar Feb 14 '26 04:02 falloficaruss

Maybe it would help to prototype this inmesa.experimental with one or two real example models first (e.g., task-switching or interruptible agents), and use that to shape the API based on what actually feels natural in practice?

ShreyasN707 avatar Feb 14 '26 04:02 ShreyasN707

I’m not proposing immediate framework adoption; I’m proposing we validate the shape in mesa.experimental first with 1–2 concrete models

The goal would be to use those prototypes to answer:

  1. what minimal abstractions are actually useful,
  2. which semantics feel natural (task/action/event boundaries),
  3. how this should integrate with existing Mesa primitives (mesa.time, observables/signals).

falloficaruss avatar Feb 14 '26 04:02 falloficaruss

I’ve been reading through the related discussions (#2526, #2529, #2538, #2851) to better understand the context.

From what I gather, the key challenge seems to be introducing reusable behavior abstractions without making Mesa too opinionated about how agents should be implemented.

A possible starting point might be a very small set of primitives:

Task
A lifecycle-based executable unit representing a concrete action an agent can perform.

Condition
A predicate evaluated against the agent’s current state or environment.

Behavior
A lightweight orchestrator that selects or composes tasks based on conditions.

Keeping these primitives minimal could allow users to build different behavior patterns (priority systems, behavior trees, task switching, etc.) without enforcing a single architecture.

Integration with existing Mesa features could also be important, for example:

  • using mesa.time for scheduling and execution timing
  • optional reactive triggers via observables/signals
  • compatibility with emerging work around continuous state dynamics

To explore ergonomics, it might be useful to validate the API with one or two small example models (e.g., a simple foraging agent or a task-switching agent). This could live under mesa.experimental until the design stabilizes.

I’m curious what others think about starting with a minimal behavioral contract like this before introducing more complex abstractions.

sakshi-thigale avatar Mar 09 '26 17:03 sakshi-thigale