Inspiration

My wife's father died alone in his rice paddy.

He wasn't sick. He wasn't in an accident. He was just a regular Isan farmer doing what millions of Thai smallholders do every day: walking to the field under brutal sun, checking the water level by eye, deciding whether to pump. He spent hours out there — sometimes in storms, sometimes in the heat that kills — because that's what farming requires when you can't afford technology and there is no one to help. He was alone, and he collapsed, and no one found him in time.

We still farm the same land. Millions of families across Southeast Asia live the same story — except for the ending, mostly. They walk to the field because they have no sensors. They guess the water level because they have no data. They pump too much or too little because they have no advisor who remembers what worked last season.

This is why NaLog Agent exists. Not just as a hackathon demo. Not as a showcase of what AI can do. As part of a system already running in production at KhawTECH, putting affordable AWD sensors and a Qwen-powered agronomist — one with perfect memory for every farmer and every field — into the hands of people who could never afford the real thing.

The goal is simple: no farmer should have to risk their life just to check on water.

I've been building the base NaLog IoT platform at KhawTECH for years. The LoRaWAN sensors work. The data flows. But raw data on a phone screen isn't advice. Good irrigation guidance has to be hyper-local and remembered: this paddy drains faster after re-levelling, this farmer prefers to approve the pump himself near flowering, last season AWD here cut pumping by 31% with no yield loss. No generic chatbot can do that. You need an agent with memory.

When the Alibaba Cloud hackathon opened the MemoryAgent track, it felt like the missing piece of a platform I'd been shipping in the field for four years — not a demo idea, but the agronomist-with-perfect-memory layer the product always needed. I'm entering this hackathon to win further funding that goes directly into buying more sensors and LoRa gateways for farming communities that need them. Real talks with local government bodies in Isan are already happening.

What it does

NaLog Agent is a Qwen-powered MemoryAgent on top of the live NaLog IoT platform. A farmer asks in Thai or English ("Does Paddy 3 need pumping now?") and the agent:

  1. Reads real sensor data — water levels, AWD cycle phase, growth stage, trends — from production IoT sensors already deployed in the field.
  2. Recalls relevant past experience — preferences, outcomes, and field-specific patterns from prior sessions and seasons.
  3. Explains a recommendation grounded in actual numbers, not guesses.
  4. Proposes pump actions for human approval — it never switches a pump on its own. Only after the farmer approves does a LoRaWAN downlink go to the physical pump relay in the field.

Example flow: the agent reads −12 cm vs a −15 cm AWD (Alternate Wetting and Drying) trigger, recalls last season's drain rate and the farmer's flowering preference, proposes pump ON, the farmer approves, and a ChirpStack downlink (0x01) is sent to the pump.

Behind the scenes it runs a bounded ReAct tool loop (up to 6 rounds), persists a 3-tier memory system (profile · episodic · semantic recall), and autonomously learns durable facts after each conversation using a cheap qwen3.6-flash extraction pass.

Sensor threshold breaches can also trigger unprompted reasoning via POST /api/alerts — the agent verifies live data and creates a pump proposal on its own — but actuation always stays behind human approval.

The farmer UI streams the agent's work (Qwen thinking, tool calls, reply) over SSE so advice is transparent on slow rural connections. Farmers can attach a field photo and qwen3-vl-plus reads crop condition into the reasoning loop.

The same capabilities are exposed as an MCP server, so any MCP client can read field state, query memory, and prepare irrigation proposals (one implementation, two surfaces).

This is a production system. The same codebase is deployed on Alibaba Cloud Function Compute in Bangkok (ap-southeast-7) and serves real farmer conversations through the KhawTECH NaLog platform today.

How I built it

The stack is deliberately modular and production-shaped:

Layer Technology
Reasoning & tool use Qwen 3 on Alibaba Cloud Model Studio — qwen3.7-max (thinking, ReAct loop)
Natural language qwen3.6-plus (Thai / English NLG)
Memory extraction qwen3.6-flash (cheap post-turn learning)
Field photos qwen3-vl-plus (multimodal crop reading)
Embeddings text-embedding-v3 via Model Studio
Reranking qwen3-rerank cross-encoder on recall candidates
Structured memory Tablestore (profiles, episodic rows with TTL, sessions, HITL proposals)
Semantic recall DashVector
Runtime Function Compute 3.0 — ZIP custom runtime (custom.debian10, Node 20), no container registry
Platform connector Read-only REST client to the live NaLog API (farms, paddies, sensors, AWD cycles, irrigation history)
Field actions ChirpStack LoRaWAN downlink on approval (0x01 on / 0x00 off)
Service Express 5, swappable local vs alibaba storage drivers

Memory retrieval is vector-first and bounded:

  1. DashVector returns candidate memory IDs (O(topK), not a full-table scan).
  2. Tablestore BatchGetRow hydrates only those rows.
  3. qwen3-rerank re-orders candidates by query relevance.
  4. A 3-tier blend scores the top results for the context window.

$$ \text{score} = 0.60 \cdot s_{\text{semantic}} + 0.25 \cdot s_{\text{recency}} + 0.15 \cdot s_{\text{reinforcement}} $$

where recency decays with a half-life of ~120 days and reinforcement grows when a memory is actually used in a decision. Forgetting is both soft (ranking decay) and hard (Tablestore TTL ~400 days on episodic rows).

Contradiction detection — the Mem0 problem. Most memory systems (Mem0 included) are append-only: embed everything, retrieve by similarity, hope the model sorts it out. But embeddings capture topic, not truth — "farmer uses diesel pump" and "farmer switched to electric pump" score almost identically. Any retrieval that ranks by similarity returns both, and the model picks whichever won the cosine coin-flip. NaLog solves this at two layers: (1) the 3-tier blend suppresses old facts via recency + reinforcement, and (2) LLM-adjudicated supersession detects contradictions during learning and marks the old memory as superseded — kept for auditability but excluded from recall.

Benchmarked, not just claimed — on a synthetic two-season farmer corpus with direct contradictions and stale near-duplicates:

Strategy Recall@5 Stale facts served
Append-only (Mem0-style) 92.9% 10
3-tier + supersession (production) 100.0% 0

Reproducible via npm run bench (docs/BENCHMARK.md).

Deployment runs compute and Tablestore in Thailand (ap-southeast-7, Bangkok); DashVector and Model Studio are reached cross-region over HTTPS from Singapore/global endpoints. Local development works fully offline with file-backed memory and a bundled demo farm (only a DashScope key is required).

The repo is MIT-licensed and open source so co-ops, NGOs, or developers can run it themselves.

Challenges I ran into

  • No aggregated "paddy status" endpoint on NaLog — the agent stitches paddy + AWD cycle
    • sensors + latest readings itself, the way an agronomist would mentally compose the picture.
  • Cross-region Alibaba layout — Bangkok for FC/Tablestore, Singapore for DashVector/Model Studio. Everything works, but provisioning and env wiring took care.
  • Token budget on slow rural connections — the agent summarises recall into a compact block (top-K = 5), tiers models so qwen3.7-max is reserved for the reasoning loop, and reports per-turn token usage.
  • Safety by design — pump control is always a proposal. Integrating human-in-the-loop cleanly (UI approval card → persisted proposal → ChirpStack downlink) without the LLM ever having a direct "turn pump on" tool was a deliberate architectural choice.
  • The hardest part was not technical. It was ensuring that this technology actually reaches the people who need it — farmers who don't speak English, have intermittent connectivity, and have never used AI. Thai-first prompts, offline-capable recall, and approachable UI were design requirements, not afterthoughts.

Accomplishments that I'm proud of

  • It's already helping real farmers. This isn't a prototype that will be archived after the hackathon. It runs in production, serving real conversations with real sensor data from fields in Kut Chum, Yasothon.
  • Built on a real, deployed IoT platform — the agent reads live NaLog sensor data and sends real pump commands over LoRaWAN.
  • A complete MemoryAgent implementation: profile + episodic + semantic recall, vector-first retrieval with reranking, LLM-adjudicated contradiction supersession, timely forgetting, reinforcement, and autonomous post-turn learning — with reproducible benchmark numbers (100% Recall@5, 0 stale facts served, vs Mem0-style baseline at 92.9% with 10 stale leaks).
  • Human-in-the-loop actuation — propose → approve → LoRaWAN downlink, with full audit trail in Tablestore. Autopilot-style alert handling without ever giving the LLM a direct pump switch.
  • Full Alibaba Cloud stack in production: Qwen 3, Tablestore, DashVector, Function Compute, with smoke tests against the live deployment.
  • MCP interoperability — the agronomy tools work from the web UI and from any MCP client (Or integrating LINE/WhatsApp).
  • Active talks with local government in Isan to fund sensor expansion for more farming communities.

What I learned

  • Memory is the product unlock for agritech, not the chat UI. Farmers don't need another bot; they need something that remembers their fields and gets cheaper to run over time.
  • Forgetting is as important as remembering. Without TTL, recency decay, and reranking, episodic memory becomes noise within a season.
  • Grounding beats fluency. Tool-calling over live sensor data, with explicit "never invent water levels" prompt rules, produces trust in a domain where a wrong pump decision costs diesel, yield, or both.
  • Model tiering matters economically: qwen3.6-flash for extraction, qwen3.7-max only where reasoning quality counts. Per-turn token reporting makes the cost visible.
  • Impact requires more than code. The best memory architecture means nothing if you can't deploy it where the people are, in the language they speak, on the connection they have.

What's next for NaLog Agent

  • Sensor expansion — using hackathon funding and government support to deploy more AWD sensors and LoRa gateways across Isan farming communities. Every sensor deployed is one less reason for a farmer to walk to the field alone.
  • LINE/WhatsApp integration — the production farmer channel in the field; web chat was the hackathon surface.
  • Co-op / multi-farm views — extension agents managing dozens of smallholders from one memory-aware dashboard.
  • Community adoption — documentation and open-source release so NGOs and regional agritech teams can deploy MemoryAgents on their own IoT platforms, not just NaLog.

Built With

Share this project:

Updates