DEV Community

Akanksha Sharma
Akanksha Sharma

Posted on

I Built an AI Agent That Checks Before It Answers

I’ve had this happen more times than I’d like to admit.

I ask AI a technical question.

It gives me a beautifully written answer.

I think:

“Wow. That makes sense.”

Then I check the documentation.

And suddenly:

“Oh.” 😭

The answer wasn't completely useless.

It just didn't have enough context.

That little problem became the idea behind ContextGuide.

What if an AI agent looked things up before answering?

Instead of expecting an AI model to magically know everything, I wanted to give it something better:

a reliable place to look.

ContextGuide is an AI agent that queries a structured Knowledge Base through Sanity Context + MCP before generating an answer.

The idea is simple:

Don't just ask the AI what it knows. Give it somewhere useful to look.

How ContextGuide Works

              👤 USER
                 │
                 │ asks a question
                 ↓
        ┌─────────────────┐
        │  ContextGuide   │
        │                 │
        │ Understand the  │
        │ question        │
        └────────┬────────┘
                 ↓
        ┌─────────────────┐
        │ Sanity Context  │
        │                 │
        │ Find relevant   │
        │ knowledge       │
        └────────┬────────┘
                 ↓
        ┌─────────────────┐
        │  KNOWLEDGE BASE │
        │                 │
        │ Docs • Guides   │
        │ References      │
        └────────┬────────┘
                 ↓
        📚 Relevant Context
                 │
                 ↓
        🤖 Agent Reasoning
                 │
                 ↓
        💬 Answer + Sources
Enter fullscreen mode Exit fullscreen mode

The important part is that the agent doesn't immediately jump from:

Question → Answer

There is a middle step:

Question → Context → Answer

And that middle step is the whole point.

Why Sanity?

Let's say I ask:

“Which authentication method should I use here?”

A basic search might find ten pages containing the word authentication.

Great.

Except... which one actually answers my question? 😅

That's where structured content becomes useful.

With Sanity, information can be organized into meaningful content instead of being treated as one giant pile of text.

ContextGuide can then retrieve the relevant information through Sanity Context and access it through MCP.

So the agent isn't just matching words.

It's trying to find the right context for the question.

The Part That Interests Me Most

What happens when the knowledge base contains conflicting information?

Imagine:

📄 Guide A
"Use Method X."

        +

📄 Guide B
"Method X is outdated."

        ↓

      Agent

"These sources disagree."
Enter fullscreen mode Exit fullscreen mode

That's actually more interesting to me than an agent that confidently picks one answer.

Because sometimes the honest answer isn't:

“Here's the answer.”

Sometimes it's:

“Here's what the sources say and here's where they disagree.”

That is information I can actually work with.

Where Each Piece Fits

Sanity
   ↓
Organizes the knowledge

Sanity Context
   ↓
Makes that knowledge queryable

MCP
   ↓
Connects the agent to it

ContextGuide
   ↓
Uses the retrieved context

User
   ↓
Gets an answer backed by the relevant content
Enter fullscreen mode Exit fullscreen mode

Each piece has a job.

Sanity isn't there just because the challenge says to use Sanity.

It's part of the reason the agent can work this way.

What I Wanted to Build

I wasn't trying to build an AI that knows everything.

Honestly, that sounds exhausting. 😭

I wanted to build an AI that knows when it should look something up.

Because maybe the future of useful AI isn't just:

“I know the answer.”

Maybe it's:

“Let me check the right information first.”

And that's the idea behind ContextGuide.

Top comments (0)