Skip to content

fix: codebase incompatible with Mesa 4.x (mesa.space removed) #152

@abhinavk0220

Description

@abhinavk0220

Description

Mesa 4.x removed mesa.space entirely, which breaks the mesa-llm codebase with a ModuleNotFoundError on import. Running python -m pytest tests/ on a fresh Mesa 4.x install fails with 24 test failures.

Root Cause

The codebase uses the old Mesa 2.x/3.x space API:

  • from mesa.space import MultiGrid, SingleGrid, ContinuousSpace

These classes no longer exist in Mesa 4.x.

Fix

Migrate to the new Mesa 4.x APIs:

Old New
mesa.space.MultiGrid mesa.discrete_space.OrthogonalMooreGrid
mesa.space.SingleGrid mesa.discrete_space.OrthogonalMooreGrid
mesa.space.ContinuousSpace mesa.experimental.continuous_space.ContinuousSpace
grid.place_agent(agent, pos) agent.cell = grid._cells[pos]
grid.get_neighbors() cell.get_neighborhood(radius=vision)
model.steps model.step

Result

All 203 tests passing after migration.

Files Affected

  • mesa_llm/llm_agent.py
  • mesa_llm/tools/inbuilt_tools.py
  • mesa_llm/recording/record_model.py
  • tests/conftest.py
  • tests/test_llm_agent.py
  • tests/test_parallel_stepping.py
  • tests/test_reasoning/test_cot.py
  • tests/test_tools/test_inbuilt_tools.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions