Add __repr__ methods to core classes and fix Mesa 4.x API compatibility#195
Open
abhinavk0220 wants to merge 8 commits intomesa:mainfrom
Open
Add __repr__ methods to core classes and fix Mesa 4.x API compatibility#195abhinavk0220 wants to merge 8 commits intomesa:mainfrom
abhinavk0220 wants to merge 8 commits intomesa:mainfrom
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…0/mesa-llm into improve/repr-methods
for more information, see https://pre-commit.ci
This was referenced Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #197
Fixes #198
Summary
This PR does two things:
__repr__methods to all core mesa-llm classes, makingmulti-agent simulations significantly easier to debug and inspect.
broken imports, incorrect coordinate handling, and broken step counters
introduced by upstream Mesa 4.x changes.
1.
__repr__MethodsThe problem
Without
__repr__, inspecting agents during a simulation run in a REPL,notebook, or debugger produces output like this:
This is useless when you're trying to understand why an agent made a
particular decision, which reasoning strategy it's using, or how much
memory it has accumulated across steps.
The fix
With this PR, the same inspection gives:
This matters especially in mesa-llm because agents simultaneously carry
LLM configuration, reasoning strategy, vision settings, and memory state.
Being able to see all of that at a glance without manually drilling into
each attribute makes a real difference when debugging a 50-agent
simulation.
Classes updated
LLMAgent—unique_id,llm_model,reasoning,vision,memory_size,internal_stateModuleLLM—llm_model,api_base,system_prompt(truncatedto 50 chars to keep output readable)
Reasoning(base class) — class name +agent_id, automaticallyinherited by all reasoning strategies
CoTReasoning—agent_idReActReasoning—agent_id,remaining_tool_callsReWOOReasoning—agent_id,remaining_tool_calls2. Mesa 4.x API Compatibility Fixes
mesa_llm/tools/inbuilt_tools.pyThis file had several issues after Mesa 4.x removed
mesa.spaceandrestructured its spatial API:
Import fixes:
mesa.spaceimports withmesa.discrete_spaceandmesa.experimental.continuous_spacemove_one_step()coordinate system fix:Mesa 4.x
OrthogonalMooreGriduses(x, y)coordinates internally, buttest dummy grids built with
SimpleNamespacecells use(row, col)convention. The previous code used the
connectionsdict on every cell,which exists on real Mesa cells too but with row/col keys causing
movement in the wrong direction entirely. Fixed by checking
isinstance(cell, SimpleNamespace)to correctly distinguish the two casesand apply the right coordinate delta.
ContinuousSpacebounds check:> hi→>= hifor upper boundary agent aty=9.0movingNorth in a
[0, 10.0]space was incorrectly allowed to reachy=10.0Torus wrap type fix:
_torus_adj()was returningnp.float64values; wrapped withfloat()to match expected plain Python floats in test assertions and downstream
usage
Occupied cell handling:
move_one_step()was crashing withValueErrorwhen the target cellwas occupied. Fixed to catch the error and return a descriptive message
instead, keeping the agent in place consistent with how boundary
collisions are handled
teleport_to_location()missing cell behavior:ValueError("Point out of bounds")for missingcells; dummy test grids raise
KeyErrormatching the existing testcontracts
mesa_llm/recording/record_model.pyself.steps→int(getattr(self, "_time", 0))—model.stepsdoes not exist in Mesa 4.x;
_timeis the correct internal step counterTest suite (
tests/)mesa.spaceimports tomesa.discrete_spaceandmesa.experimental.continuous_spaceacrossconftest.py,test_llm_agent.py,test_cot.py,test_inbuilt_tools.pyModel(seed=42)→Model()— theseedkwarg conflicts withmesa_signalsin Mesa 4.xTesting
All tests pass after these changes:
AI Assistance Disclosure
This PR was developed with AI assistance (Claude) for code generation
and debugging. All code has been reviewed, tested, and understood by
the contributor.