fix: add adaptive risk agents example with relative-import tests#306
fix: add adaptive risk agents example with relative-import tests#306pragam-m25 wants to merge 3 commits intomesa:mainfrom
Conversation
|
@quaquel Thanks for the guidance earlier — moved this example to mesa-examples as suggested. |
EwoutH
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Can you fix the forced newlines?
There was a problem hiding this comment.
Good catch — I’ll fix the forced line breaks in the README and push an update.
| def choose_action(self) -> str: | ||
| """Choose between a safe or risky action.""" | ||
| if self.model.random.random() < self.risk_preference: | ||
| return "risky" | ||
| return "safe" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Fair point — thanks for calling that out.
I’ll keep responses concise and in my own words going forward.
Appreciate the feedback.
There was a problem hiding this comment.
@EwoutH
Sorry but this person seems like a bot. Final decision is up on your hands.
There was a problem hiding this comment.
@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) |
There was a problem hiding this comment.
@colinfrisch you're the expert on Agent memory, could you check how this is implemented here?
There was a problem hiding this comment.
What do these tests do? They are not in our standard structure.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thanks for the pointer.
The approach used in mesa/mesa#2767 looks like a good reference for improving visualization tests here as well.
There was a problem hiding this comment.
Let's keep them out of this PR, but if you have a specific proposal be sure to open a discussion.
There was a problem hiding this comment.
okay Ewouth thank's for your guidance ,i will definetly do as you say
for more information, see https://pre-commit.ci
Thanks for opening a PR! Please click the
Previewtab and select a PR template:Summary
This PR adds a new diagnostic example demonstrating adaptive risk-taking agents.
Each agent:
The example is intentionally minimal and uses only core Mesa primitives.
Motivation
Many adaptive agent models in Mesa end up concentrating:
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
model.randomfor reproducibilityTesting
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.