Add ForagerBehavior example — GSoC 2026 behavioral framework prototype
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 ForagerModelapp.py— SolaraViz visualization with slidersREADME.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
Thanks! Can you do a self-review and then request a peer review, following:
- https://github.com/mesa/mesa-examples/issues/390
Hi @EwoutH — self-review is complete. Code is clean and tested locally. Could you please review when you have time? Thank you!
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!
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!
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!