improve: add type hints to reasoning module + fix Mesa 4.x compatibility#179
improve: add type hints to reasoning module + fix Mesa 4.x compatibility#179abhinavk0220 wants to merge 3 commits intomesa:mainfrom
Conversation
… 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.
for more information, see https://pre-commit.ci
|
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)
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 |
| """ | ||
|
|
||
| def __init__(self, agent: "LLMAgent"): | ||
| def __init__(self, agent: "LLMAgent") -> None: |
There was a problem hiding this comment.
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.
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.pyReasoning.__init__→Noneexecute_tool_call→Plan,chaining_message: straexecute_tool_call→Plan,chaining_message: strdict→dict[str, Any]inObservationandPlandataclassescot.pyCoTReasoning.__init__→Noneget_cot_system_prompt,plan,aplanreact.pyReActReasoning.__init__→Noneget_react_system_prompt,get_react_prompt,plan,aplanrewoo.pyReWOOReasoning.__init__→Noneremaining_tool_calls: intattribute annotationget_rewoo_system_prompt,plan,aplanMesa 4.x Fixes
mesa.spaceimports withmesa.discrete_spaceandmesa.experimental.continuous_spaceacrossllm_agent.py,inbuilt_tools.py,tests/conftest.py,test_cot.py,test_inbuilt_tools.pytest_parallel_stepping.py:Model(seed=42)→Model()(pre-existing upstream failure)
record_model.py:self.steps→self._time(Mesa 4.x uses
_timeas the step counter,stepsdoesn't exist)reasoning.py: safe step counter access — triesmodel.stepsfirst, falls back to
int(model._time)for Mesa 4.xTesting
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,ReWOOReasoninghad no type hints, making it hard for new contributorsto 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, andReasoninginteract. I also found thatthe 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
pytest --cov=mesa tests/)ruff check . --fix)