-
-
Notifications
You must be signed in to change notification settings - Fork 52
improve: add comprehensive type hints to LLMAgent and ModuleLLM #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abhinavk0220
wants to merge
11
commits into
mesa:main
Choose a base branch
from
abhinavk0220:improve/type-hints-llm-agent-module-llm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+629
−351
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
15df694
fix: migrate codebase to Mesa 4.x APIMesa 4.x removed mesa.space enti…
6baf6d7
fix: resolve merge conflict with upstream/main- Update test_inbuilt_t…
79d1dc2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3150700
fix: resolve ruff linting errors (PLC0415, F841)
951a5c4
fix: move import math to top level (ruff PLC0415)
3bdc711
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0b5dd9b
improve: add comprehensive type hints to LLMAgent and ModuleLLM- Add …
b4b207e
fix: resolve merge conflict - migrate test_llm_agent.py to Mesa 4.x A…
44ba636
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4881c4f
fix: address CodeRabbit review comments- Fix neighbor.memory ownershi…
55f5d78
Merge branch 'improve/type-hints-llm-agent-module-llm' of https://git…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,275 @@ | ||
| [1mdiff --cc tests/test_tools/test_inbuilt_tools.py[m | ||
| [1mindex fce291c,7a9c367..0000000[m | ||
| [1m--- a/tests/test_tools/test_inbuilt_tools.py[m | ||
| [1m+++ b/tests/test_tools/test_inbuilt_tools.py[m | ||
| [36m@@@ -3,9 -3,9 +3,10 @@@[m [mfrom __future__ import annotation[m | ||
| from types import SimpleNamespace[m | ||
| [m | ||
| import pytest[m | ||
| [31m -from mesa.discrete_space import OrthogonalMooreGrid, OrthogonalVonNeumannGrid[m | ||
| [31m -from mesa.space import ContinuousSpace, MultiGrid, SingleGrid[m | ||
| [32m +from mesa.discrete_space import OrthogonalMooreGrid[m | ||
| [32m +from mesa.experimental.continuous_space import ContinuousSpace[m | ||
| [32m +[m | ||
| [32m+ [m | ||
| from mesa_llm.tools.inbuilt_tools import ([m | ||
| move_one_step,[m | ||
| speak_to,[m | ||
| [36m@@@ -155,3 -329,256 +334,257 @@@[m [mdef test_move_one_step_on_continuousspa[m | ||
| [m | ||
| assert agent.pos == (2.0, 3.0)[m | ||
| assert result == "agent 6 moved to (2.0, 3.0)."[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_boundary_on_continuousspace():[m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = None[m | ||
| [32m+ model.space = ContinuousSpace(x_max=10.0, y_max=10.0, torus=False)[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=30, model=model)[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ model.space.place_agent(agent, (2.0, 9.0))[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "North")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.pos == (2.0, 9.0)[m | ||
| [32m+ assert "boundary" in result.lower()[m | ||
| [32m+ assert "North" in result[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_torus_wrap_on_continuousspace():[m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = None[m | ||
| [32m+ model.space = ContinuousSpace(x_max=10.0, y_max=10.0, torus=True)[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=31, model=model)[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ model.space.place_agent(agent, (2.0, 9.0))[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "North")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.pos == (2.0, 0.0)[m | ||
| [32m+ assert result == "agent 31 moved to (2.0, 0.0)."[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_boundary_singlegrid_north():[m | ||
| [32m+ """Agent at top edge of SingleGrid trying to go North gets a clear message."""[m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = SingleGrid(width=5, height=5, torus=False)[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=20, model=model)[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ model.grid.place_agent(agent, (2, 4)) # y=4 is the top edge[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "North")[m | ||
| [32m+ [m | ||
| [32m+ # agent should not have moved[m | ||
| [32m+ assert agent.pos == (2, 4)[m | ||
| [32m+ assert "boundary" in result.lower()[m | ||
| [32m+ assert "North" in result[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_torus_wrap_singlegrid_north():[m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = SingleGrid(width=5, height=5, torus=True)[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=23, model=model)[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ model.grid.place_agent(agent, (2, 4))[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "North")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.pos == (2, 0)[m | ||
| [32m+ assert result == "agent 23 moved to (2, 0)."[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_boundary_multigrid_west():[m | ||
| [32m+ """Agent at left edge of MultiGrid trying to go West gets a clear message."""[m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = MultiGrid(width=5, height=5, torus=False)[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=21, model=model)[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ model.grid.place_agent(agent, (0, 2)) # x=0 is the left edge[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "West")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.pos == (0, 2)[m | ||
| [32m+ assert "boundary" in result.lower()[m | ||
| [32m+ assert "West" in result[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_torus_wrap_multigrid_west():[m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = MultiGrid(width=5, height=5, torus=True)[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=24, model=model)[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ model.grid.place_agent(agent, (0, 2))[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "West")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.pos == (4, 2)[m | ||
| [32m+ assert result == "agent 24 moved to (4, 2)."[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_singlegrid_occupied_target():[m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = SingleGrid(width=5, height=5, torus=False)[m | ||
| [32m+ [m | ||
| [32m+ moving_agent = DummyAgent(unique_id=25, model=model)[m | ||
| [32m+ blocking_agent = DummyAgent(unique_id=26, model=model)[m | ||
| [32m+ model.agents.extend([moving_agent, blocking_agent])[m | ||
| [32m+ model.grid.place_agent(moving_agent, (2, 2))[m | ||
| [32m+ model.grid.place_agent(blocking_agent, (2, 3))[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(moving_agent, "North")[m | ||
| [32m+ [m | ||
| [32m+ assert moving_agent.pos == (2, 2)[m | ||
| [32m+ assert blocking_agent.pos == (2, 3)[m | ||
| [32m+ assert "occupied" in result.lower()[m | ||
| [32m+ assert "North" in result[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_boundary_orthogonal_grid():[m | ||
| [32m+ """Agent at edge of OrthogonalMooreGrid with no cell in that direction gets a clear message."""[m | ||
| [32m+ [m | ||
| [32m+ class _DummyOrthogonalGrid(OrthogonalMooreGrid):[m | ||
| [32m+ pass[m | ||
| [32m+ [m | ||
| [32m+ orth_grid = object.__new__(_DummyOrthogonalGrid)[m | ||
| [32m+ orth_grid.torus = False[m | ||
| [32m+ orth_grid.dimensions = (5, 5)[m | ||
| [32m+ start = (0, 1)[m | ||
| [32m+ start_cell = SimpleNamespace([m | ||
| [32m+ coordinate=start, agents=[], connections={}, is_full=False[m | ||
| [32m+ )[m | ||
| [32m+ orth_grid._cells = {start: start_cell}[m | ||
| [32m+ [m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = orth_grid[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=22, model=model)[m | ||
| [32m+ agent.cell = start_cell[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "North")[m | ||
| [32m+ [m | ||
| [32m+ # cell should be unchanged[m | ||
| [32m+ assert agent.cell is start_cell[m | ||
| [32m+ assert "boundary" in result.lower()[m | ||
| [32m+ assert "North" in result[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_boundary_orthogonal_torus_missing_wrapped_cell():[m | ||
| [32m+ class _DummyOrthogonalGrid(OrthogonalMooreGrid):[m | ||
| [32m+ pass[m | ||
| [32m+ [m | ||
| [32m+ orth_grid = object.__new__(_DummyOrthogonalGrid)[m | ||
| [32m+ orth_grid.torus = True[m | ||
| [32m+ orth_grid.dimensions = (3, 3)[m | ||
| [32m+ start = (0, 0)[m | ||
| [32m+ start_cell = SimpleNamespace(coordinate=start, agents=[], is_full=False)[m | ||
| [32m+ # Wrapped target for North would be (2, 0), but it is intentionally absent.[m | ||
| [32m+ orth_grid._cells = {start: start_cell}[m | ||
| [32m+ [m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = orth_grid[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=38, model=model)[m | ||
| [32m+ agent.cell = start_cell[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "North")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.cell is start_cell[m | ||
| [32m+ assert "boundary" in result.lower()[m | ||
| [32m+ assert "North" in result[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_full_target_orthogonal_grid():[m | ||
| [32m+ class _DummyOrthogonalGrid(OrthogonalMooreGrid):[m | ||
| [32m+ pass[m | ||
| [32m+ [m | ||
| [32m+ orth_grid = object.__new__(_DummyOrthogonalGrid)[m | ||
| [32m+ orth_grid.torus = False[m | ||
| [32m+ orth_grid.dimensions = (5, 5)[m | ||
| [32m+ start = (1, 1)[m | ||
| [32m+ end = (0, 1)[m | ||
| [32m+ start_cell = SimpleNamespace([m | ||
| [32m+ coordinate=start, agents=[], connections={}, is_full=False[m | ||
| [32m+ )[m | ||
| [32m+ full_target_cell = SimpleNamespace([m | ||
| [32m+ coordinate=end,[m | ||
| [32m+ agents=[SimpleNamespace(unique_id=99)],[m | ||
| [32m+ connections={},[m | ||
| [32m+ is_full=True,[m | ||
| [32m+ )[m | ||
| [32m+ start_cell.connections[(-1, 0)] = full_target_cell[m | ||
| [32m+ orth_grid._cells = {start: start_cell, end: full_target_cell}[m | ||
| [32m+ [m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = orth_grid[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=27, model=model)[m | ||
| [32m+ agent.cell = start_cell[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "North")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.cell is start_cell[m | ||
| [32m+ assert "full" in result.lower()[m | ||
| [32m+ assert "North" in result[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_diagonal_on_orthogonal_vonneumann_grid():[m | ||
| [32m+ class _DummyOrthogonalVonNeumannGrid(OrthogonalVonNeumannGrid):[m | ||
| [32m+ pass[m | ||
| [32m+ [m | ||
| [32m+ orth_grid = object.__new__(_DummyOrthogonalVonNeumannGrid)[m | ||
| [32m+ orth_grid.torus = False[m | ||
| [32m+ orth_grid.dimensions = (5, 5)[m | ||
| [32m+ start = (2, 2)[m | ||
| [32m+ end = (1, 3) # NorthEast[m | ||
| [32m+ start_cell = SimpleNamespace(coordinate=start, agents=[], is_full=False)[m | ||
| [32m+ end_cell = SimpleNamespace(coordinate=end, agents=[], is_full=False)[m | ||
| [32m+ orth_grid._cells = {start: start_cell, end: end_cell}[m | ||
| [32m+ [m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = orth_grid[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=28, model=model)[m | ||
| [32m+ agent.cell = start_cell[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "NorthEast")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.cell is end_cell[m | ||
| [32m+ assert result == "agent 28 moved to (1, 3)."[m | ||
| [32m+ [m | ||
| [32m+ [m | ||
| [32m+ def test_move_one_step_torus_wrap_orthogonal_grid():[m | ||
| [32m+ class _DummyOrthogonalGrid(OrthogonalMooreGrid):[m | ||
| [32m+ pass[m | ||
| [32m+ [m | ||
| [32m+ orth_grid = object.__new__(_DummyOrthogonalGrid)[m | ||
| [32m+ orth_grid.torus = True[m | ||
| [32m+ orth_grid.dimensions = (3, 3)[m | ||
| [32m+ start = (0, 0)[m | ||
| [32m+ end = (2, 2) # NorthWest wraps on torus[m | ||
| [32m+ start_cell = SimpleNamespace(coordinate=start, agents=[], is_full=False)[m | ||
| [32m+ wrapped_cell = SimpleNamespace(coordinate=end, agents=[], is_full=False)[m | ||
| [32m+ orth_grid._cells = {start: start_cell, end: wrapped_cell}[m | ||
| [32m+ [m | ||
| [32m+ model = DummyModel()[m | ||
| [32m+ model.grid = orth_grid[m | ||
| [32m+ [m | ||
| [32m+ agent = DummyAgent(unique_id=29, model=model)[m | ||
| [32m+ agent.cell = start_cell[m | ||
| [32m+ model.agents.append(agent)[m | ||
| [32m+ [m | ||
| [32m+ result = move_one_step(agent, "NorthWest")[m | ||
| [32m+ [m | ||
| [32m+ assert agent.cell is wrapped_cell[m | ||
| [32m+ assert result == "agent 29 moved to (2, 2)."[m | ||
| [32m++[m | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the stray patch artifact.
This file is checked-in diff text for
tests/test_tools/test_inbuilt_tools.py, not source. It duplicates content already undertests/and looks like an unresolved patch/merge artifact, so it should be dropped from the PR.🤖 Prompt for AI Agents