mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Agent is missing __repr__ inconsistent with every other core Mesa class

Open dietcoke-17 opened this issue 5 months ago • 2 comments

SUMMARY Agent defines __str__ but not __repr__. This means repr(agent) falls back to object.__repr__, returning a useless memory address that changes every run.

This makes agents invisible in debuggers, logging output, and interactive shells.

Current behaviour

class Wolf(Agent):
    pass

model = Model()
wolf = Wolf(model)

print(str(wolf))   # Wolf, agent_id = 0        
print(repr(wolf))    

Expected behaviour

print(repr(wolf))  # Wolf(unique_id=0) 

This is an internal inconsistency Every other core Mesa class already defines __repr__. Agent is the only one that was skipped. The pattern is already established in the codebase. Agent was one core object where it was never defined. Precedent PR #2195 added __repr__ to EventList for exactly this reason. Same fix.

I'd like to submit a PR for this

dietcoke-17 avatar Jun 23 '26 10:06 dietcoke-17

I agree with addressing this, and we probably should open an issue to add __repr_html__ to most base classes (i.e., Model, Agent, AgentSet`, and the various spaces).

quaquel avatar Jun 24 '26 07:06 quaquel

Should i open an issue regarding adding repr_html to the base classes and start working on adding it?

dietcoke-17 avatar Jun 27 '26 06:06 dietcoke-17