AIdeas Winner: How I Built AgriNexus AI's Closed-Loop Nudge Engine (And How You Can Too)
A step-by-step walkthrough of the closed-loop nudge engine behind AgriNexus AI, Innovation Award winner in the AWS 10,000 AIdeas Competition. Weather-gated triggers, EventBridge Scheduler one-shot reminders, and DynamoDB Streams cancel-on-done — a pattern that transfers to any domain where follow-through matters.
Why a reminder needed to become a loop
Ramesh farms two acres of cotton in Latur, Maharashtra. The advice he needs exists. ICAR and FAO have published it for decades. His problem is timing: spray before the wind picks up, in a dry window, and the treatment works. Miss that window and the same advice is worthless.
Every advisory tool I studied sends the tip and stops. An SMS goes out, a push notification fires, and nobody can tell you whether a single farmer acted. The organizations funding the advice can't tell either, which means they can't prove impact to a donor, which means the program shrinks next season.
So I inverted the design. AgriNexus doesn't just send. It sends when the weather says the moment is right, then follows up at 24 and 48 hours until Ramesh replies "हो गया" (done) or opts out. The reply is the product. Everything below exists to capture it.
The loop in one line
Weather trigger → send nudge → schedule follow-ups → listen for the reply → cancel or expire.
Five AWS services carry it: Lambda, Step Functions, EventBridge Scheduler, DynamoDB (with Streams), and the WhatsApp Business Cloud API for delivery. Here is each step with the decisions behind it.

Step 1: The trigger
A WeatherPoller Lambda runs four times a day on an EventBridge schedule. For each district with active farmers, it pulls current conditions from OpenWeatherMap (API key in Secrets Manager) and checks them against per-crop rules: wind under a threshold, no rain in the window. The exact thresholds are configurable per crop and stored as data, not code, so an agronomist can tune them without a deploy.
When conditions pass, the poller starts a Step Functions execution for that district. One execution, seconds long. Which brings up the decision that shaped the whole engine.
Step 2: Send, then schedule — the EventBridge Scheduler decision
My first sketch kept the Step Functions execution open across the whole reminder cycle: send the nudge,
Wait 24 hours, send a reminder, Wait again, check status, exit. It works. It also means every farmer with a pending nudge holds an open execution for up to 72 hours.Run that forward to 10,000 farmers in spray season and you carry tens of thousands of long-running executions at once. Costs grow with transitions and retries, the console becomes unreadable, and a bad deploy mid-wait strands in-flight state.
The fix: let the workflow finish in seconds and push the waiting into EventBridge Scheduler as one-shot schedules. The NudgeSender Lambda sends the WhatsApp message, writes a
NUDGE# record to DynamoDB, and creates two schedules:python
scheduler.create_schedule( Name=f"nudge-{nudge_id}-t24", ScheduleExpression=f"at({(now + timedelta(hours=24)).isoformat()})", FlexibleTimeWindow={"Mode": "OFF"}, Target={ "Arn": REMINDER_LAMBDA_ARN, "RoleArn": SCHEDULER_ROLE_ARN, "Input": json.dumps({"nudge_id": nudge_id, "attempt": 1}), }, ActionAfterCompletion="DELETE",)ActionAfterCompletion="DELETE" makes each schedule self-cleaning. It fires once, invokes the ReminderSender, and removes itself. No orchestration stays open, and cancelling a reminder is a delete_schedule call rather than surgery on a running state machine.
In my cost model this pattern came out roughly 67 times cheaper than holding wait states open at the 10K-farmer scale (modeled, not audited; assumptions in ADR 0007 ). Scheduler pricing sits around a dollar per million invocations, so at pilot scale the reminder infrastructure costs pennies. The bigger win was operational: zero long-lived state to babysit.
Step 3: Listening for "हो गया"
The reply path is the part most advisory systems skip, and it turned out to be the cleanest piece of the architecture.
Inbound WhatsApp messages hit the webhook Lambda, which verifies Meta's HMAC-SHA256 signature, deduplicates on the message's WAMID with a 24-hour TTL (Meta retries webhooks, and a retry must not double-process), and writes a short-lived
MSG# row to DynamoDB.A ResponseDetector Lambda consumes the table's DynamoDB Stream. When a new message row lands for a farmer with a pending nudge, it matches the text against done-keywords in the farmer's language. Hindi "हो गया" and "ho gaya" both count; farmers code-switch, so the matcher accepts transliteration. On a match:
python
if is_done_response(message_text): update_nudge_status(phone_number, "DONE") delete_scheduled_reminders(nudge_id) # both one-shot schedules, goneThat is the whole cancel-on-done mechanic. The stream decouples it from the webhook path, so reply detection adds zero latency to normal message handling, and the webhook Lambda never needs to know nudges exist.
If no reply arrives, the T+24h and T+48h reminders fire, and at T+72h the nudge is marked
EXPIRED . Expired is data too. A partner running a program wants to know who went quiet, not just who confirmed.The guardrails that made it shippable
Three rules protected farmers and my sleep:
Consent gates the sender. Farmers opt into nudges during onboarding, and the NudgeSender checks consent immediately before every send. Enrolling someone can never message them by itself. No
granted , no send.One nudge in flight per farmer. Before sending, the engine checks for an existing pending nudge and backs off. Weather that stays favorable for three days must not produce three overlapping reminder chains.
Idempotency everywhere the network retries. WAMID dedup on the webhook, conditional writes on status updates. Meta retries, Lambda retries, Streams deliver at least once. Atomic operations and idempotent operations solve different problems, and this engine needed both.
What it costs
The full AgriNexus stack, all four pipelines included, runs about $53 a month modeled at 1,000 farmers, roughly $0.54 per farmer per year at 10,000 (assumptions in the public cost model ). The nudge engine itself is the cheapest slice: Scheduler and Streams together barely register next to Bedrock inference. Behavior change turned out to be nearly free infrastructure. The expensive part is answering questions; following up costs almost nothing.
Build this for your own domain
Strip away agriculture and the pattern is three primitives:
- A trigger that decides the moment (my weather poller; yours might be a price feed, a sensor reading, a calendar).
- One-shot schedules for follow-ups, created at send time and deleted on confirmation.
- A stream-driven detector that turns replies into state.
Medication adherence, savings reminders, irrigation windows: the loop transfers, only the trigger and the message copy change. Everything above fits inside the Free Tier at prototype scale, and the AgriNexus repo has the SAM template, 144 EARS requirements, and the ADRs if you want to trace decisions to code.
What's next
The engine now has a partner layer. Last week I submitted Outturn , a control plane that lets an NGO or a KVK run cohorts on top of this loop and see follow-through rates per district, to a hackathon. The live infrastructure proof shows the same engine driven from a partner dashboard, keyless via OIDC. The roadmap after that: sensor-driven triggers alongside weather, and per-partner WhatsApp numbers via Meta Embedded Signup.
The core stays what it was on day one. Ramesh gets the advice in time, and for the first time somebody can prove he acted on it.
AgriNexus AI won an Innovation Award in the AWS 10,000 AIdeas Competition.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article