Should Agent.step() be enforced as abstract, or warn if not overridden?
Problem
Agent.step() and Agent.advance() are empty stubs meant to be overridden by subclasses, but Mesa doesn't enforce this. A user can write:
model = Model()
agent = Agent(model)
agent.step() # Silent no output — user doesn't know they forgot to override
The agent does nothing. No error. No warning. The user has no idea. This is a common Python OOP bug — empty base methods that should signal "you must implement this."
Option A: Make Agent abstract with @abstractmethod (breaking change)
Pros:
- Enforced at class definition time — can't instantiate bare
Agent()at all - Type checkers (mypy, pyright) will catch missing implementations
- Follows Python's standard OOP pattern
Cons:
- Breaking change — any code doing
Agent(model)will fail - Would require Mesa 4.0+ release
- Subclasses that don't define
step()would also break
Option B: Add warnings.warn (non-breaking)
Pros:
- Non-breaking — existing code continues to work
- Users who forgot to override get alerted
- Easy to implement and test
Cons:
- Warning can be silenced by user (even accidentally)
- Doesn't prevent the bug, only warns about it
- Adds runtime overhead to every call
Option C: Both (warn in Mesa 3.x, enforce in Mesa 4.0) Add warnings now, then switch to ABC in the next major version when breaking changes are expected.
Which direction should we go? I can submit a PR for whichever approach you prefer.
I see where you are coming from, but I have to disagree with the premise that this is a bug that needs fixing in Mesa.
In Mesa, Agent.step() and Agent.advance() are intentionally left as empty stubs for several reasons:
-
Passive Agents: Not every agent in a simulation is an active decision-maker. Models frequently utilize inanimate or passive agents (e.g., obstacles, environmental markers, or static resources). If we enforce
step()via@abstractmethodor warnings, we force developers to write boilerplatedef step(self): passfor every single passive entity, which severely degrades the developer experience. -
The
advance()method comes underSimultaneousActivation. If a user is building a standard model withRandomActivationorSequentialActivation(refer https://github.com/mesa/mesa/blob/main/docs/tutorials/2_agent_activation.ipynb), throwing a warning that they forgot to implementadvance()would be inaccurate and confusing. -
The framework is actively shifting toward Event scheduling and time-based actions. In this new architecture, agents can react to scheduled events or execute specific
Actionswithout ever relying on a global, synchronousstep()loop. Forcing the implementation ofstep()would actually conflict with where the framework's internal architecture is heading
The silent "no output" behavior is exactly what a passive agent should do. While making Agent an ABC makes sense in pure OOP theory, it adds unnecessary rigidity to an ABM framework.
And
step()andandvace()are conventions but they are not actively used inside mesa. Typically, a user will do something likeself.agents.shuffle_do("my_custom_method").