Skip to content

Conversation

@pragam-m25
Copy link

Thanks for opening a PR! Please click the Preview tab and select a PR template:

Summary

This PR adds a new diagnostic example demonstrating adaptive risk-taking agents.

Each agent:

  • chooses between safe and risky actions,
  • maintains a short memory of past outcomes,
  • adapts its risk preference based on recent experience.

The example is intentionally minimal and uses only core Mesa primitives.


Motivation

Many adaptive agent models in Mesa end up concentrating:

  • decision-making,
  • action execution,
  • memory updates,
  • and learning logic

inside a single agent.step() method.

This example is designed to make that complexity explicit, rather than hide it,
and to serve as a concrete, example-first input for discussions around
richer behavioral abstractions in Mesa.


Scope

  • New example only (no API or behavior changes)
  • Uses current Mesa patterns (no deprecated schedulers, no DataCollector)
  • Relies on model.random for reproducibility
  • Includes minimal smoke tests to ensure the model initializes and steps

Testing

  • Added smoke tests verifying:
    • model initialization
    • stepping without errors
  • Tests intentionally do not assert outcomes or dynamics

Notes

This example is exploratory and educational by design.
It does not propose new abstractions or patterns,
but highlights current modeling constraints through a working example.

@pragam-m25
Copy link
Author

@quaquel Thanks for the guidance earlier — moved this example to mesa-examples as suggested.

Copy link
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Few comments. I'm a bit in doubt about the general usefulness of this example. On the one hand simple is good, but maybe this is too simple.

Even without a space, some sort of visualisation would be useful.

Copy link
Member

Choose a reason for hiding this comment

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

Can you fix the forced newlines?

Copy link
Author

Choose a reason for hiding this comment

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

Good catch — I’ll fix the forced line breaks in the README and push an update.

Comment on lines +39 to +43
def choose_action(self) -> str:
"""Choose between a safe or risky action."""
if self.model.random.random() < self.risk_preference:
return "risky"
return "safe"
Copy link
Member

Choose a reason for hiding this comment

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

Technically this is adaptive, since they update their risk_preference, but I don't know how much value this example actually shows.

@quaquel any opinions?

Copy link
Author

Choose a reason for hiding this comment

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

That’s a fair concern.
The intent of this example is not to showcase a sophisticated learning algorithm, but to isolate where adaptation, memory, and decision logic currently live in a Mesa agent.

If you feel it would be more useful with a minimal visualization or a slightly richer signal (e.g. payoff distribution), I’m happy to extend it — or we can treat it as a purely didactic example.

Choose a reason for hiding this comment

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

Could we avoid using GPT to write responses? It feels a bit strange to read. Let's try making Mesa a better package without using AI.

Copy link
Author

Choose a reason for hiding this comment

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

Fair point — thanks for calling that out.
I’ll keep responses concise and in my own words going forward.
Appreciate the feedback.

Choose a reason for hiding this comment

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

@EwoutH
Sorry but this person seems like a bot. Final decision is up on your hands.

Copy link
Author

Choose a reason for hiding this comment

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

i am a real person

Copy link
Author

Choose a reason for hiding this comment

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

@darshi1337 what i am doing is that i write in hinglish and give it to chatgpt than it change it into english ,and than i gave response ,because. i am not confident with my english that's why you fell like this ,i am sorry for that i definetly try not to use next time

) -> None:
super().__init__(model)
self.risk_preference = initial_risk_preference
self.memory: deque[int] = deque(maxlen=memory_size)
Copy link
Member

Choose a reason for hiding this comment

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

@colinfrisch you're the expert on Agent memory, could you check how this is implemented here?

Copy link
Member

Choose a reason for hiding this comment

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

What do these tests do? They are not in our standard structure.

Copy link
Author

Choose a reason for hiding this comment

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

These are intentionally lightweight smoke tests, meant only to ensure the example initializes and steps without errors.

If there’s a preferred structure for example tests in mesa-examples, I’m happy to refactor them accordingly.

Copy link
Member

@EwoutH EwoutH Jan 24, 2026

Choose a reason for hiding this comment

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

mesa-examples testing is basically a hacky mess. Any improvements are welcome. See #137 among other issues.

Edit: Mesa itself has something new, maybe that could also be applied to mesa-examples mesa/mesa#2767

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the context — that helps a lot.
I’ll keep the tests lightweight for now and avoid over-engineering, but I’m happy to iterate later if there’s a clearer direction (e.g. aligning with mesa/mesa#2767).
For this PR, I’ll treat the tests as minimal smoke checks unless you’d prefer a different baseline.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the pointer.

The approach used in mesa/mesa#2767 looks like a good reference for improving visualization tests here as well.

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep them out of this PR, but if you have a specific proposal be sure to open a discussion.

Copy link
Author

Choose a reason for hiding this comment

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

okay Ewouth thank's for your guidance ,i will definetly do as you say

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants