Skip to content

typing: type hint meta-agent instance creation - #4034

Merged
EwoutH merged 6 commits into
mesa:mainfrom
sohamsa7:soham
Nov 16, 2026
Merged

EwoutH merged 6 commits into
mesa:mainfrom
sohamsa7:soham

Conversation

@sohamsa7

@sohamsa7 sohamsa7 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Note

Use this template for bug fixes only. For enhancements/new features, use the feature template and get maintainer approval in an issue/discussion before opening a PR.

Pre-PR Checklist

  • This PR is a bug fix, not a new feature or enhancement.

Summary

This PR resolves the static typing technical debt marked by the # TODO(typing) comment in meta_agent.py. It replaces the broad Any return type on internal meta-agent instantiation and the public membership manager's create() method with concrete MetaAgent type annotations. This improves static type-checking (mypy) compliance, IDE autocompletion, and developer experience

Implementation

Updated _create_meta_agent_instance in mesa/experimental/meta_agents/meta_agent.py to return MetaAgent instead of Any. Narrowed internal helper return types (_build_meta_agent_class, _find_existing_meta_agent) to use MetaAgent classes/instances cleanly. Updated the public .create() method signature in the MetaAgents manager class (mesa_agents_api.py) to correctly return MetaAgent. Re-sorted all and import blocks to comply with ruff and project style guidelines.

Testing

Verified that all unit tests in tests/test_meta_agents.py, tests/test_meta_agents_api.py, and tests/test_multi_level_meta_agents.py pass successfully.

Checked code style and formatting via ruff check and ruff format

Additional Notes

Hello! I am Soham, currently an engineering student, relatively new to open source and found mesa quite interesting so i thought of contributing here. Any and all types of feedback would be appreciated cause i really love learning about open source.

@github-actions github-actions Bot added the experimental Release notes label label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.0% [-1.4%, -0.7%] 🔵 -0.3% [-0.6%, -0.1%]
BoltzmannWealth large 🔵 +0.2% [-0.1%, +0.4%] 🔵 -0.3% [-0.5%, -0.0%]
Schelling small 🔵 +0.6% [+0.1%, +1.0%] 🔵 -1.8% [-2.7%, -0.9%]
Schelling large 🔵 +0.4% [-0.7%, +1.4%] 🔵 -0.1% [-1.3%, +1.4%]
WolfSheep small 🔵 +0.0% [-0.4%, +0.4%] 🔵 -0.3% [-4.1%, +3.8%]
WolfSheep large 🔵 +1.2% [+0.7%, +1.7%] 🔵 -0.2% [-1.0%, +0.5%]
SugarscapeG1mt small 🔵 +0.8% [+0.5%, +1.1%] 🔵 -1.3% [-2.8%, +0.2%]
SugarscapeG1mt large 🔵 +0.9% [+0.2%, +1.5%] 🔵 +0.7% [-1.4%, +3.2%]
BoidFlockers small 🔵 -1.1% [-1.5%, -0.8%] 🔵 +0.1% [-0.3%, +0.6%]
BoidFlockers large 🔵 -0.5% [-0.9%, +0.1%] 🔵 +0.6% [+0.3%, +0.9%]
MultiLevelAllianceModel small 🔵 -2.7% [-3.9%, -1.5%] 🔵 -1.0% [-1.5%, -0.7%]
MultiLevelAllianceModel large 🔵 +0.0% [-0.9%, +0.9%] 🔵 -0.7% [-1.2%, -0.1%]

@mesa-triage-bot

Copy link
Copy Markdown

The description says this replaces _create_meta_agent_instance()'s Any return annotation and resolves its typing TODO, but the diff leaves both unchanged. Could you complete that part, or clarify why it remains? That would let a reviewer assess whether the typing task described here is resolved.


Automated triage note, written by an AI model for the Mesa maintainers. It can be wrong, and it doesn't make decisions: maintainers do. If it missed the point, say so here.

@sohamsa7 sohamsa7 closed this Nov 10, 2026
@sohamsa7 sohamsa7 reopened this Nov 10, 2026
@sohamsa7

Copy link
Copy Markdown
Contributor Author

The required changes have been made. Apologies from my end that I had overlooked one line that may have caused the confusion. The change has been made and all tests have been passed

@EwoutH EwoutH left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@EwoutH
EwoutH merged commit ce53de0 into mesa:main Nov 16, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experimental Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants