DEV Community

Divya Munnuru
Divya Munnuru

Posted on

Building AgriMind: My Journey into Agentic AI – Part 3

Giving AI a Memory: Building Context-Aware Conversations for Farmers

In the first two parts of this series, I shared why I chose Agriculture as the domain to explore Agentic AI and how I designed MCP Servers to expose agricultural capabilities like crop recommendations, disease detection, mandi prices, and conversational assistance.

As I continued using the application, I noticed something interesting.

The AI was intelligent enough to answer questions.

It could detect diseases from crop images.

It could recommend crops.

It could even generate reports.

But every time I started a new conversation, it behaved as if we had never spoken before.

The farmer had to explain everything again.

That made me realize something important.

An AI Agent that forgets every conversation doesn't feel like an assistant—it feels like a search engine.

That became my motivation for implementing Memory and Context in Kisan Mitra AI.


Why Memory Matters

Imagine visiting your family doctor.

Every appointment begins with the doctor asking:

  • What's your name?
  • What illness did you have last month?
  • Which medicines were prescribed?
  • Have you recovered?

That would be frustrating.

Doctors become effective because they remember your medical history.

The same principle applies to AI.

A farmer shouldn't have to repeatedly explain:

  • Which crop they're growing
  • Which disease was detected previously
  • What treatment was recommended

An intelligent farming assistant should already know.


The Problem I Wanted to Solve

Let's imagine a farmer uploads an image of a tomato leaf.

The AI detects:

Crop:
Tomato

Disease:
Early Blight
Enter fullscreen mode Exit fullscreen mode

The farmer receives treatment recommendations.

Everything works perfectly.

Now imagine the same farmer comes back three days later and asks:

"How do I prevent this from happening again?"

Without memory, the chatbot has no idea what "this" refers to.

It asks the farmer to upload the image again or explain the disease from scratch.

That isn't a natural conversation.


My Approach

For this learning project, I wanted to keep the implementation simple while demonstrating the concept of persistent memory.

Instead of introducing databases or vector stores immediately, I implemented a lightweight JSON-based memory store.

Each farmer is identified using their email address.

Whenever a disease is successfully detected from an uploaded image, the application stores:

  • Farmer Email
  • Last Crop
  • Last Detected Disease

For example:

{
  "farmer@email.com": {
    "last_crop": "Tomato",
    "last_disease": "Early Blight"
  }
}
Enter fullscreen mode Exit fullscreen mode

Although simple, this creates persistent memory across chatbot sessions.


Bringing Context into the Conversation

Storing memory alone isn't enough.

The AI also needs to use that information.

Whenever the farmer opens the chatbot, the application checks whether previous memory exists.

If it does, the chatbot welcomes the farmer with something like:

Welcome back! I remember that your Tomato crop suffered from Early Blight during your last visit. How is your crop doing today?

Immediately, the conversation feels more personal.

More importantly, the previous crop and disease are injected into the AI's system prompt before sending the request to the LLM.

Instead of starting from zero, the model now has context.


How the Flow Works

The memory workflow is straightforward.

Farmer uploads crop image
          │
          ▼
Disease Detection
          │
          ▼
Store Crop + Disease
(using farmer email)
          │
          ▼
Persistent JSON Memory
          │
          ▼
Next Chat Session
          │
          ▼
Retrieve Previous Memory
          │
          ▼
Inject Context into LLM Prompt
          │
          ▼
Context-Aware Response
Enter fullscreen mode Exit fullscreen mode

This small enhancement dramatically changes the user experience.


A Practical Example

First Conversation

Farmer:

My tomato leaves have brown spots.

AI:

Your tomato crop is affected by Early Blight.

The diagnosis is saved.


A Few Days Later

Farmer:

How can I prevent this?

Instead of asking,

Which crop are you talking about?

the AI already knows.

It responds:

Since your tomato crop previously suffered from Early Blight, regular monitoring, proper spacing between plants, and avoiding overhead irrigation can significantly reduce future infections.

That's the difference context makes.


What I Learned

Before implementing this feature, I assumed "memory" simply meant saving conversations.

After building it, I realized it's much more than that.

Memory allows an AI Agent to:

  • Continue conversations naturally
  • Reduce repetitive questions
  • Personalize recommendations
  • Build trust with users

Even a small amount of remembered information makes the assistant feel far more intelligent.


Looking Ahead

This implementation is intentionally lightweight because my goal was to understand the fundamentals.

In the future, I plan to extend memory much further.

Instead of remembering only the last diagnosis, the AI could maintain a complete farming profile, including:

  • Soil type
  • State and district
  • Current crops
  • Disease history
  • Previous recommendations
  • Seasonal farming activities
  • Irrigation methods

Combined with Agentic AI, this opens the door to highly personalized agricultural assistance.

Imagine an AI that says:

"Last Kharif season, your groundnut crop experienced Leaf Spot disease. Based on the current weather forecast and your farm history, I recommend preventive measures this week."

That's no longer just a chatbot.

It's beginning to behave like a digital farming advisor.


What's Next?

Now that the AI can remember previous interactions, the next challenge is making it knowledgeable.

Memory helps the AI remember the farmer.

But what if the AI needs to answer questions using trusted agricultural documents, government advisories, or research papers instead of relying only on its training?

That's where Retrieval-Augmented Generation (RAG) comes in.

In Part 4, I'll share how I integrated RAG into Kisan Mitra AI so that the assistant can retrieve information from agricultural knowledge sources and provide more accurate, grounded, and reliable recommendations.

As always, I'm learning by building, and I hope this series helps others who are exploring the exciting world of Agentic AI.

Top comments (0)