Skip to content

fix: ReActReasoning.__repr__ AttributeError and STLTMemory Mesa 4.x model.steps compatibility#199

Open
abhinavk0220 wants to merge 8 commits intomesa:mainfrom
abhinavk0220:fix/repr-and-steps-compat
Open

fix: ReActReasoning.__repr__ AttributeError and STLTMemory Mesa 4.x model.steps compatibility#199
abhinavk0220 wants to merge 8 commits intomesa:mainfrom
abhinavk0220:fix/repr-and-steps-compat

Conversation

@abhinavk0220
Copy link
Copy Markdown

@abhinavk0220 abhinavk0220 commented Mar 13, 2026

Fixes #205

Fixes #204

Summary

Two small but real bugs fixed in this PR:

  1. ReActReasoning.__repr__() crashes with AttributeError
  2. STLTMemory uses model.steps which does not exist in Mesa 4.x

Bug 1 — ReActReasoning.__repr__() AttributeError

ReActReasoning.__repr__() was referencing self.remaining_tool_calls
which does not exist on ReActReasoning. That attribute belongs to
ReWOOReasoning only. Calling repr() on any ReActReasoning instance
would crash with:

AttributeError: 'ReActReasoning' object has no attribute 'remaining_tool_calls'

Fix: Removed remaining_tool_calls from ReActReasoning.__repr__().
ReWOOReasoning.__repr__() correctly keeps it since that class does have
the attribute.


Bug 2 — STLTMemory uses model.steps (Mesa 4.x incompatibility)

st_lt_memory.py was using self.agent.model.steps to record the current
step when consolidating memory entries. model.steps does not exist in
Mesa 4.x — it was removed. This causes AttributeError during any
simulation run that triggers memory consolidation.

# Before — crashes in Mesa 4.x
step=self.agent.model.steps,

# After — correct Mesa 4.x API
step=int(getattr(self.agent.model, "_time", 0)),

The same fix was already applied to record_model.py — this brings
st_lt_memory.py in line with the same pattern.


Testing

All existing tests pass:

python -m pytest tests/ -q --ignore=tests/test_parallel_stepping.py
# 0 failures

GSoC contributor checklist

Context & motivation

Found these two bugs while auditing the codebase after fixing the Mesa 4.x
issues in PR #195. ReActReasoning.__repr__() was referencing
self.remaining_tool_calls which only exists on ReWOOReasoning calling
repr() on any ReActReasoning instance would crash silently. The
STLTMemory bug surfaced the same pattern as record_model.py model.steps
removed in Mesa 4.x but still used in the memory consolidation path.

What I learned

Small bugs in base classes and memory modules can be harder to catch than
bugs in tools because they only surface under specific conditions
__repr__ only when you inspect an agent, memory consolidation only when
short-term capacity is exceeded. Reading the codebase with fresh eyes after
fixing one bug is often how you find the next one.

Learning repo

🔗 My learning repo: https://github.com/abhinavk0220/GSoC-learning-space
🔗 Relevant model(s): https://github.com/abhinavk0220/GSoC-learning-space/tree/main/models

Readiness checks

  • This PR addresses an agreed-upon problem (linked issue or discussion with maintainer approval), or is a small/trivial fix
  • I have read the contributing guide and deprecation policy
  • I have performed a self-review: I reviewed my own PR as if I were a reviewer and left comments on anything that needs explanation
  • Another GSoC contributor has reviewed this PR:
  • Tests pass locally (pytest --cov=mesa tests/)
  • Code is formatted (ruff check . --fix)
  • If applicable: documentation, examples, and/or migration guide are updated

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8705859e-9344-4339-876b-4d926d7cd4ee

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

agent=self.agent,
content=self.step_content,
step=self.agent.model.steps,
step=int(getattr(self.agent.model, "_time", 0)),
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same pattern as record_model.py model.steps doesn't exist in Mesa 4.x. Using int(getattr(self.agent.model, '_time', 0)) as the safe fallback. This only surfaces at runtime when memory consolidation triggers, which is why it wasn't caught earlier.

@abhinavk0220 abhinavk0220 force-pushed the fix/repr-and-steps-compat branch from 5e0eaa5 to 18218c3 Compare March 18, 2026 17:30
pre-commit-ci bot and others added 2 commits March 18, 2026 17:30
MultiGrid and SingleGrid were removed in Mesa 4.x. Replace all usages
in tests with OrthogonalMooreGrid and fix place_agent() calls to use
the Mesa 4.x cell-based API (agent.cell = grid._cells[pos]).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant