Skip to content

bug: ContinuousSpace boundary check allows agents to move outside bounds #198

@abhinavk0220

Description

@abhinavk0220

Describe the bug

move_one_step() in inbuilt_tools.py uses pos[i] > hi for the upper
boundary check in ContinuousSpace. This allows an agent to land exactly
on the boundary value, which is outside the valid space.

To Reproduce

from mesa.model import Model
from mesa.agent import Agent
from mesa.experimental.continuous_space import ContinuousSpace
from mesa_llm.tools.inbuilt_tools import move_one_step

class DummyModel(Model):
    def __init__(self):
        super().__init__()

class DummyAgent(Agent):
    def step(self): pass

model = DummyModel()
model.space = ContinuousSpace(dimensions=[[0, 10.0], [0, 10.0]], torus=False)

agent = DummyAgent(model=model)
agent.pos = (2.0, 9.0)

move_one_step(agent, "North")
print(agent.pos)  # prints (2.0, 10.0) — WRONG, agent is outside bounds

Expected behavior

Agent at (2.0, 9.0) moving North in a [0, 10.0] space should stay at
(2.0, 9.0) — the boundary is reached, movement should be blocked.

Actual behavior

Agent moves to (2.0, 10.0) which is outside the defined space dimensions.

Root cause

_is_out_of_bounds() checks pos[i] > hi instead of pos[i] >= hi.
Since the upper bound is exclusive, a position exactly equal to hi is
out of bounds but the check misses it.

Fix

Change pos[i] > hi to pos[i] >= hi in _is_out_of_bounds().

This fix is included in PR #195.

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