mesa-examples icon indicating copy to clipboard operation
mesa-examples copied to clipboard

Add ForagerBehavior example — GSoC 2026 behavioral framework prototype

Open 1khaled-ctrl opened this issue 8 months ago • 5 comments

What this adds

A new example demonstrating a modular behavioral framework for Mesa agents.

ForagerBehavior model

Agents switch between behavioral states:

  • searching — moves randomly and forages for resources
  • resting — recovers energy when exhausted

Transition logic:

  • searching → resting when energy <= 20
  • resting → searching when energy >= 80

Files added

  • model.py — ForagerAgent and ForagerModel
  • app.py — SolaraViz visualization with sliders
  • README.md — explanation and usage guide

Context

This example is part of my GSoC 2026 proposal: Behavioral Framework for Agent Models in Mesa

The full prototype is at: https://github.com/1khaled-ctrl/mesa-behavior-framework-prototype

— Khaled Saber

1khaled-ctrl avatar Mar 16 '26 20:03 1khaled-ctrl

Thanks! Can you do a self-review and then request a peer review, following:

  • https://github.com/mesa/mesa-examples/issues/390

EwoutH avatar Mar 17 '26 14:03 EwoutH

Hi @EwoutH — self-review is complete. Code is clean and tested locally. Could you please review when you have time? Thank you!

1khaled-ctrl avatar Mar 17 '26 14:03 1khaled-ctrl

Hey, cool concept! A few things to fix though:

  • Indentation bug in ForagerModel.init everything after super().init() is at class level instead of inside the method. This will crash on run.
  • mesa.space.MultiGrid is gone in Mesa 4, switch to mesa.discrete_space. This also affects _move() and _forage() since agents now use self.cell instead of self.pos.
  • run_simulation.py doesn't exist, README should say solara run app.py instead.
  • import random isn't needed, use self.random instead for reproducibility.
  • README describes StateMachine, BehaviorModules, etc. but the actual code is just if/else logic worth syncing those up.

Fix the crashes first and it'll be in much better shape!

Harshini2411 avatar Mar 20 '26 17:03 Harshini2411

Hi @EwoutH @codebreaker32 @Harshini2411 — I have addressed all the feedback:

  • Switched from mesa.space.MultiGrid to mesa.discrete_space
  • Updated self.pos to self.cell
  • Removed import random, using self.random instead
  • Fixed README to say solara run app.py
  • Fixed indentation in ForagerModel.init

Ready for re-review. Thank you!

1khaled-ctrl avatar Mar 21 '26 15:03 1khaled-ctrl

The Mesa 4 fixes look good! One thing still outstanding though the README still mentions StateMachine, BehaviorModules, EnergyDepletionBehavior etc. which don't exist in the code. Just update it to describe what the model actually does and it's ready!

Harshini2411 avatar Mar 22 '26 01:03 Harshini2411