Update warehouse example to the new meta-agents API - #483
Open
falloficaruss wants to merge 2 commits into
Open
Conversation
for more information, see https://pre-commit.ci
falloficaruss
marked this pull request as ready for review
August 21, 2026 13:35
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Note
This PR is a part of GSoC 2026 project "Hypergraph-Based Meta-Agents for Mesa"
Summary
This PR ports the warehouse example, the deliberate meta-agent creation showcase in mesa-examples from the removed experimental API (
mesa.experimental.meta_agents.create_meta_agent) to the new backend-authoritative MetaAgents manager introduced in mesa/mesa#3811 (mesa.meta_agents).mesa/mesa#3811 removes the old implementation outright (no shim), consistent with the Mesa 4.0 breaking-change window. The old API scattered membership state across live objects (meta_agent.constituting_agents, agent.meta_agent, get_constituting_agent_instance(...), assume_constituting_agent_*). The new API makes the model-level
MetaAgentsmanager the single write path, with all memberships stored as (member, group, relation) triplets in a canonical incidence backend. This example is rewritten to exercise that public surface: deliberate creation with overlapping memberships, and member <--> group resolution through the manager instead of object pointers.Changes
warehouse/model.py
MetaAgentsfrom the new top-levelmesa.meta_agentspackage (replacesmesa.experimental.meta_agents.meta_agent.create_meta_agent).self.meta_agents = MetaAgents(self)(and exposesself.membership_backend).self.meta_agents.create("RobotAgent", [router, sensor, worker], CellAgent, ...)with:meta_attributes: explicit group state: cell, status, path, item, carrying, loading_dock, charging_station (replaces the implicit assume_constituting_agent_attributes=True behavior, which no longer exists).meta_methods: find_path, move, initiate_task, continue_task are thin delegators that resolve the responsible sub-agent through the manager via typed relations (members_of(robot, relation="router" | "sensor" | "worker")).memberships=[(router, "router"), (sensor, "sensor"), (worker, "worker")]overlapping relation labels recorded in the backend, demonstrating multi-role membership for the same agent–group pair set.model.robot_agent_typeinstead of the fragiletype(model.RobotAgent)pattern called out in the old Readme; step() iteratesself.agents_by_type[self.robot_agent_type]and no-ops gracefully if no robots exist.WarehouseScenario(subclass of Scenario) with rows / cols / height, so warehouse size is a first-class model parameter; layout generation now uses the scenario dimensions and the model's rng for reproducible item codes.zip(..., strict=True)).warehouse/agents.py
self.meta_agent / get_constituting_agent_instance(...)lookups are replaced with backend-authoritative queries:robot: model.meta_agents.groups_of(self)model.meta_agents.members_of(robot, relation=...)SensorAgent.moveresolves its parent robot and the router member for obstacle re-routing;WorkerAgent.initiate_task/continue_taskresolve router/sensor members for pathing and movement, with fallbacks to the robot's own meta_methods.warehouse/make_warehouse.py
make_warehouse()accepts an rng parameter; item codes are generated from the model's seeded RNG instead of the global random module.app.py
LOADING_DOCKSis now imported frommake_warehouse.LOADING_DOCK_COORDS(single source of truth; no duplicated coordinate constants).model.robot_agent_type, with a guard forrobot_agent_typeisNone.warehouse/init.py / Readme.md
WarehouseModelandWarehouseScenario.Readmeupdated: robots assembled withMetaAgents.create+ typed memberships; notes that the backend supports overlapping memberships (this example still uses one group per robot); robots tracked viamodel.robot_agent_type; layout/size/seed configuration documented; stale file descriptions fixed.Old -> new API mapping used in this example
create_meta_agent(model, name, members, cls, ...)model.meta_agents.create(name, members, cls, ...)assume_constituting_agent_attributes=Truemeta_attributes={...}assume_constituting_agent_methods=Truemeta_methods={...}delegating to typed membersagent.meta_agentmodel.meta_agents.groups_of(agent)meta_agent.get_constituting_agent_instance(Cls)model.meta_agents.members_of(group, relation=...)type(model.RobotAgent)model.robot_agent_typeBehavior
robotsare assigned inventory tasks, A*-route to items (with obstacle re-routing via the sensor/router split), pick up, deliver to the loading dock, and return to open status. The visualization renders inventory and robot agents as before.Dependencies / Merge Order