Skip to content

Add scenario property to Agent class#3164

Merged
EwoutH merged 2 commits intomesa:mainfrom
EwoutH:agent_scenario_property
Jan 17, 2026
Merged

Add scenario property to Agent class#3164
EwoutH merged 2 commits intomesa:mainfrom
EwoutH:agent_scenario_property

Conversation

@EwoutH
Copy link
Copy Markdown
Member

@EwoutH EwoutH commented Jan 17, 2026

Summary

Adds a scenario property to the Agent class for convenient access to the model's scenario from within agent code.

Motivation

With the introduction of scenarios in #3103, agents frequently need to access scenario parameters. Currently, this requires writing self.model.scenario.parameter_name, which is verbose and inconsistent with how agents access random and rng.

Implementation

Adds a simple property that returns self.model.scenario, following the same pattern as the existing random and rng properties.

@property
def scenario(self):
    """Return the scenario associated with the model."""
    return self.model.scenario

Usage Example

# Before
def __init__(self, model):
    super().__init__(model)
    self.vision = self.model.scenario.citizen_vision
    self.legitimacy = self.model.scenario.legitimacy

# After
def __init__(self, model):
    super().__init__(model)
    self.vision = self.scenario.citizen_vision
    self.legitimacy = self.scenario.legitimacy

Additional Notes

  • Maintains consistency with existing random and rng properties
  • No breaking changes
  • Improves code readability and developer experience

Add convenience property to access model.scenario directly from agents.

This follows the same pattern as the existing random and rng properties, making scenario parameters easier to access within agent code.
@EwoutH EwoutH requested a review from quaquel January 17, 2026 17:04
@EwoutH EwoutH added experimental Release notes label enhancement Release notes label labels Jan 17, 2026
Introduces a test to verify that agents can access the scenario via a property and that the scenario object is shared between the agent and the model.
@github-actions

This comment was marked as off-topic.

@EwoutH EwoutH merged commit ccdac40 into mesa:main Jan 17, 2026
14 checks passed
quaquel pushed a commit to quaquel/mesa that referenced this pull request Jan 18, 2026
Add convenience property to access model.scenario directly from agents.

This follows the same pattern as the existing random and rng properties, making scenario parameters easier to access within agent code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Release notes label experimental Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants