Skip to content

improve: add type hints to reasoning module + fix Mesa 4.x compatibility#179

Open
abhinavk0220 wants to merge 3 commits intomesa:mainfrom
abhinavk0220:improve/type-hints-reasoning-module
Open

improve: add type hints to reasoning module + fix Mesa 4.x compatibility#179
abhinavk0220 wants to merge 3 commits intomesa:mainfrom
abhinavk0220:improve/type-hints-reasoning-module

Conversation

@abhinavk0220
Copy link

@abhinavk0220 abhinavk0220 commented Mar 9, 2026

Summary

Adds comprehensive type hints and improved docstrings to all four
reasoning files, and fixes multiple Mesa 4.x compatibility issues
discovered after syncing with upstream main.

Type Hints Added

reasoning.py

  • Reasoning.__init__None
  • execute_tool_callPlan, chaining_message: str
  • aexecute_tool_callPlan, chaining_message: str
  • dictdict[str, Any] in Observation and Plan dataclasses
  • Expanded Args/Returns docstrings on both execute methods

cot.py

  • CoTReasoning.__init__None
  • Args/Returns docstrings on get_cot_system_prompt, plan, aplan

react.py

  • ReActReasoning.__init__None
  • Args/Returns docstrings on get_react_system_prompt, get_react_prompt, plan, aplan

rewoo.py

  • ReWOOReasoning.__init__None
  • remaining_tool_calls: int attribute annotation
  • Args/Returns docstrings on get_rewoo_system_prompt, plan, aplan

Mesa 4.x Fixes

  • Replace mesa.space imports with mesa.discrete_space and
    mesa.experimental.continuous_space across llm_agent.py,
    inbuilt_tools.py, tests/conftest.py, test_cot.py,
    test_inbuilt_tools.py
  • Fix test_parallel_stepping.py: Model(seed=42)Model()
    (pre-existing upstream failure)
  • Fix record_model.py: self.stepsself._time
    (Mesa 4.x uses _time as the step counter, steps doesn't exist)
  • Fix reasoning.py: safe step counter access — tries model.steps
    first, falls back to int(model._time) for Mesa 4.x

Testing

All tests passing (including test_parallel_stepping.py which was
previously broken on upstream main).

Related

Follows up on #153 (Mesa 4.x migration) and #170 (type hints for
LLMAgent/ModuleLLM).


GSoC contributor checklist

Context & motivation

The reasoning module Reasoning, CoTReasoning, ReActReasoning,
ReWOOReasoning had no type hints, making it hard for new contributors
to understand method signatures without reading the full implementation.
This PR adds comprehensive type hints across all reasoning classes and
fixes Mesa 4.x compatibility issues found while auditing the module.

What I learned

The reasoning module is the heart of mesa-llm every agent decision
flows through it. Adding type hints here forced me to understand exactly
how Plan, Observation, and Reasoning interact. I also found that
the async paths in reasoning classes had subtle inconsistencies with the
sync paths that type hints made immediately visible.

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

abhinavKumar0206 and others added 2 commits March 9, 2026 17:43
… hints added:- reasoning.py: Reasoning.__init__ -> None, execute_tool_call -> Plan, aexecute_tool_call -> Plan, chaining_message: str, dict -> dict[str, Any] in Observation/Plan dataclasses, expanded Args/Returns docstrings on execute_tool_call methods- cot.py: CoTReasoning.__init__ -> None, get_cot_system_prompt Args/Returns docstring, plan/aplan Args/Returns docstrings- react.py: ReActReasoning.__init__ -> None, get_react_system_prompt/get_react_prompt Args/Returns docstrings, plan/aplan Args/Returns docstrings- rewoo.py: ReWOOReasoning.__init__ -> None, remaining_tool_calls: int, get_rewoo_system_prompt Args/Returns docstring, plan/aplan Args/Returns docstringsMesa 4.x fixes:- Replace mesa.space imports with mesa.discrete_space and mesa.experimental.continuous_space across llm_agent.py, inbuilt_tools.py, tests/conftest.py, test_cot.py, test_inbuilt_tools.py- Fix test_parallel_stepping.py: Model(seed=42) -> Model()- Fix record_model.py: self.steps -> self._time (Mesa 4.x step counter)- Fix reasoning.py: safe step counter access via model.steps with _time fallback for Mesa 4.x compatibilityAll tests passing.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 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: c2630a6b-e073-417d-b1f8-561298f48234

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
  • Post copyable unit tests in a comment

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.

"""

def __init__(self, agent: "LLMAgent"):
def __init__(self, agent: "LLMAgent") -> None:
Copy link
Author

Choose a reason for hiding this comment

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

Used TYPE_CHECKING guard for LLMAgent forward reference to avoid
circular imports between reasoning.py and llm_agent.py. Return types
on plan() and aplan() explicitly typed as Plan to make the contract
clear for subclass implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant