Skip to content

Add Agriculture decision Model#259

Open
niteshver wants to merge 10 commits intomesa:mainfrom
niteshver:agriculture_model
Open

Add Agriculture decision Model#259
niteshver wants to merge 10 commits intomesa:mainfrom
niteshver:agriculture_model

Conversation

@niteshver
Copy link
Copy Markdown
Contributor

This PR introduces a new Agriculture Decision Model built using Mesa + Mesa-LLM.

The model simulates farmer decision-making under uncertainty, incorporating factors such as rainfall variability, market prices, and social influence. Farmer agents use LLM-based reasoning and tool execution (planting, fertilizing, harvesting) to manage crops over a season.

The model tracks key metrics including total yield, profit, and crop distribution, and demonstrates how reasoning-driven agents adapt to environmental conditions.

Here is the reasoning:-
Screenshot 2026-03-23 at 6 56 55 PM
Screenshot 2026-03-23 at 6 28 51 PM

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7aae9ef-c706-4375-8d35-f3832f31aca3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.78%. Comparing base (8fe8992) to head (a53b830).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #259      +/-   ##
==========================================
+ Coverage   90.67%   90.78%   +0.10%     
==========================================
  Files          19       19              
  Lines        1555     1573      +18     
==========================================
+ Hits         1410     1428      +18     
  Misses        145      145              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@niteshver
Copy link
Copy Markdown
Contributor Author

Hi @colinfrisch , @sanika-n
I’ve added an Agriculture ABM in this PR. Would really appreciate your review and feedback.
Thanks!

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 63f93fb3a1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +40 to +44
self.land_size = random.randint(1, 5)
self.wealth = random.randint(1000, 50000)
self._base_internal_state = list(self.internal_state)

self.crop_type = random.choice(["wheat", "rice", "maize"])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use the model RNG for seeded farmer attributes

When a user reruns the example with the same Random Seed, these fields are still drawn from Python's global random module, so the seed only stabilizes grid placement, not land size / wealth / crop type (and compute_yield() also uses random.uniform). That makes the new seed control misleading and breaks reproducibility for experiments based on this example.

Useful? React with 👍 / 👎.

Comment on lines +54 to +57
self.memory = STLTMemory(
agent=self,
llm_model="ollama/llama3.1:latest",
display=True,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pass the configured llm_model into STLTMemory

If someone follows the new example docs and switches app.py to OpenAI or Gemini, the agent still creates its memory backend with hard-coded ollama/llama3.1:latest. Once the short-term buffer fills and memory consolidation runs, the simulation will try to talk to a local Ollama server even though the main agent model is configured differently, which turns the example into a runtime failure after a few steps for non-Ollama setups.

Useful? React with 👍 / 👎.

Comment on lines +53 to +57
if agent.crop_state == CropState.IDLE:
return "No crop planted"

agent.fertilizer += level
if agent.crop_state == CropState.PLANTED:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject fertilizer after a crop becomes READY

Once current_day reaches harvest_date, update_crop_state() marks the crop READY, but this tool still increments agent.fertilizer for that state. Because harvest_crop() immediately feeds the final fertilizer level into compute_yield(), any agent that fertilizes on or after harvest day can inflate yield and profit without affecting growth time, which corrupts the simulation outputs whenever the LLM chooses that action.

Useful? React with 👍 / 👎.

Comment on lines +123 to +125
self.yield_output = base_yield * rain_factor * fert_factor * noise
price = self.model.market_price[self.crop_type]
self.profit = self.yield_output * price
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Accumulate profit across harvests

model.py reports Total Profit and Average Profit by summing a.profit, but this assignment overwrites the previous value on every harvest. As soon as a farmer completes a second crop cycle (for example by choosing a short days_to_harvest, or just because the run keeps going), all earlier revenue is discarded and the charts only reflect the latest harvest per agent.

Useful? React with 👍 / 👎.

Comment on lines +126 to +128
self.current_day += timedelta(days=1)
self.agents.shuffle_do("step")
self.datacollector.collect(self)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge End the run after the 120-day season

The example is described as a single farming season, but step() only advances the date, steps agents, and keeps collecting metrics forever. In the Solara app that means farmers can keep replanting indefinitely unless the user stops the run manually, so the reported crop-state and profit curves stop representing one season's outcome and drift upward over time.

Useful? React with 👍 / 👎.

@wang-boyu wang-boyu added the example Release notes label label Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

example Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants