Add missing mesa-internal attributes to mesa_primitives blocklist in create_meta_agent#3538
Add missing mesa-internal attributes to mesa_primitives blocklist in create_meta_agent#3538
mesa_primitives blocklist in create_meta_agent#3538Conversation
|
Performance benchmarks:
|
|
As this is clearly a bug and there are some related issues as identified in #3472, instead of both #3538 and #3472 why dont we just ensure the meta-agent doesn't overwrite attributes it already has. This approach is very brittle, and so issues identified in #3472 and #3538, plus the current brittleness can all be solved with not overwriting existing meta-agent attributes. |
This is a better direction for the attribute side. It seems more robust than extending the mesa_primitives blocklist, and it also looks like it would cover both the internal-attribute corruption in this PR and the explicit-attribute overwrite case in #3472. I do think methods are still a separate question, since inferred method-name collisions are not addressed by the same rule, but for attributes this feels like the cleaner approach. |
|
@tpike3 @falloficarus22 I have updated the PR. |
|
@codebyNJ Could you look at the Warehouse Model failure. The warehouse model is the other meta-agent example so we need to understand why this code broke it. https://github.com/mesa/mesa-examples/tree/main/examples/warehouse |
|
sure @tpike3 i will look into warehouse model and find out the reason why this code broke. |
|
@tpike3 Fixed the warehouse failure. The issue: Solution: Always apply explicit meta_attributes (user intent takes precedence). |
Pre-PR Checklist
Summary
Fixes
add_attributesincreate_meta_agentso existing meta-agent attributes are not overwritten by values inferred from constituting agents. Useshasattr()checks to preserve existing attributes—both internal Mesa attributes and explicitly-provided ones.Bug / Issue
When
assume_constituting_agent_attributes=True, the previous implementation unconditionally copied all public non-callable attributes from constituent agents onto the meta-agent, silently overwriting:Expected behavior: don't overwrite attributes that already exist on the meta-agent.
Actual behavior: any existing attribute could be silently overwritten without warning.
Related context: issues #3433, #3506, #3472 all identified meta-agent attribute problems.
Implementation
Updated
add_attributeshelper insidecreate_meta_agentinmesa/experimental/meta_agents/meta_agent.py:not hasattr(meta_agent_instance, name)before copyingif not hasattr(meta_agent_instance, key)before callingsetattr()Why this is better than a blocklist:
mesa_primitivesblocklist increate_meta_agent#3538 and preserve explicit meta attributes/methods over inferred members #3472) with one approachTesting
Added
test_assume_attributes_does_not_overwrite_existing_attributes:meta_attributesare preserved when adding agents withassume_constituting_agent_attributes=TrueAdditional Notes
This change keeps behavior predictable: existing attributes are preserved, inferred values only fill missing keys.
No API changes are required for current users.
This complements determinism-related fixes (#3433, #3506) and does not replace them.