How To Build a RAG Agent Step by Step

How To Build a RAG Agent Step by Step

Sep 9, 2025

Inbox chaos is a real issue. Most teams have a shared mailbox where everything lands — RFPs, customer questions, long threads with attachments… and then someone has to dig for deadlines, requirements, or that one PDF line everyone keeps asking about.

Good news: with Stack AI, you can turn that inbox into a RAG agent that actually helps. An agent that searches the emails and files and gives you the answer you are looking for in seconds.

And you might think building something like this would take weeks or that you’d need to be some kind of AI expert. Well, you don’t! With Stack AI it’s surprisingly easy to set up. Let me show you step by step how to do it.

What is a RAG agent?

A RAG agent is basically RAG with a little initiative. So basically an AI agent that grounds answers in your data but it can also decide what to do next — search first, summarize a thread, extract a list, maybe run a quick calculation — and then return a clear answer.

This decision-making is often guided by something called the ReAct pattern (Reason + Act). Here’s how it works in practice:

  • Reasoning step: the agent thinks through the user’s question. “They’re asking about the deadline — that probably means I need to check the latest email or PDF attachment.”

  • Action step: the agent takes an action based on that reasoning. For example, it might retrieve from the knowledge base, pull context from memory, or use a tool like a calculator.

  • Observation: it sees the result of that action (e.g., retrieved rows from the spreadsheet, or a chunk of text from an attachment).

  • Loop: it reasons again: Okay, I now have the text with the deadline — I can answer.

The ReAct pattern is what lets agents combine RAG retrieval with tools and memory in a structured way. Instead of guessing, the agent works step by step: reason, act, observe, repeat — until it has everything it needs to answer clearly and confidently.

Let’s illustrate this with a real scenario.

Imagine you’re part of a business development team, and you’ve got a shared inbox like rfp@company.com. Every week it fills up with new requests for proposals: deadlines, compliance requirements, attachments with scope documents, and endless clarification emails.

Now, instead of scrolling through all those threads, you could just ask an agent: “What’s the submission deadline for the Acme Logistics RFP?” The agent would go though the following steps:

  1. Reasoning: “The user wants a deadline. That will probably be in the most recent email or in an attachment.”

  2. Action: The agent searches the knowledge base (emails + PDFs) for “Acme Logistics” + “deadline.”

  3. Observation: It retrieves a PDF chunk that says: “Submission deadline: 12 June 2025.”

  4. Reasoning: “I now have the deadline. I can answer directly.”

  5. Action: It generates a reply: “The submission deadline for the Acme Logistics RFP is 12 June 2025.”

That’s what makes a RAG agent different from a RAG pipeline. It doesn’t just pull a chunk of text. It reasons through the problem, takes the right actions, and grounds the answer in real evidence.

How RAG and AI Agents are combined

When we talk about RAG agents, it helps to break things down into two layers: the RAG layer and the Agent layer.

  • The RAG layer is all about making sure answers are grounded in the right data.

  • The Agent layer is where the “initiative” comes in — deciding what to do with that data and how to present it back to the user.

Here’s a side-by-side view of what each layer does in practice:

Layer

What it does

Example in our RFP inbox

RAG layer

Finds the right bits in your private data (emails, PDFs, DOCX, CSVs).

Agent retrieves the latest Acme Logistics RFP email and extracts the deadline from the attached PDF.

Agent layer

Adds autonomy — decides what to do next (search inbox, use a tool, pull from memory), keeps short memory for follow-ups, and formats the final response.

Agent reasons: “This is a deadline question → search inbox.” Then answers: “The submission deadline is 12 June 2025.”

How does a RAG agent work?

When you send a question to a RAG agent, the first thing it does is decide what action to take. That’s the “agent” part. It looks at your query and figures out:

  • Do I need to retrieve information from a knowledge base?

    → That’s the RAG step: it searches the indexed emails, documents, or databases for the most relevant chunks of information.

  • Do I need to bring in context from memory?

    → For example, remembering that the user was already asking about the Acme RFP in the last turn.

  • Do I need to use a tool?

    → This could mean doing a calculation, calling an API, searching a database, or even looking something up on the web.

Often, it’s not just one — it can combine these: retrieve data, check memory, run a calculation, and then compose the answer. Finally, it generates a grounded response and keeps the conversation flowing naturally.

Step-by-Step: building a RAG agent in Stack AI

Before we dive in, here’s the plan: we’re going to turn our RFP inbox into a working RAG agent you can actually use. We’ll start from scratch in Stack AI, connect Gmail as the knowledge base, pick an LLM, give it a tight system prompt, add memory, test it with real questions (deadlines, mandatory docs, version changes) and finish by publishing a simple app the team can use. Ready? Let’s build it!

Step 1: Start a New Project

So the first thing we’re going to do is head over to the Stack AI dashboard and click on Workflow Builder, then hit Create.

For this example, we will use the New Project Template.

I’m going to call mine RFP Intelligence Agent and then just click Create Project.

The reason we’re starting from scratch here is simple: we want to build this agent specifically for our use case: answering RFP questions straight from emails and their attachments.

Step 2: Set up the Workflow Canvas

When the project opens, you’ll see the blank canvas with three basic blocks:

  • User Message (the question people will ask).

  • AI Assistant (where the model processes the query).

  • Output (what the user sees as the answer).

This is our starting point. We’re now going to wire this up with Gmail so the assistant can actually search through RFP-related emails.

Step 3: Connect to Gmail

Next, we’re going to bring in Gmail as our knowledge base. On the left side sidebar, just click Knowledge Bases and choose Gmail.

Click the Gmail node and select create new connection to Gmail.


It’ll prompt you to set up a new connection — I just called mine “Ana’s Gmail connection” .

Click Create connection and once that’s done, you can pick which emails or threads you actually want the agent to look at.

For our demo, we picked a handful of RFP-related emails and attachments:

  • Clarification Requests Round 1.

  • Mandatory Attachments for Proposal.

  • MedTech Digital Health RFP Questions.

  • Submission Deadlines & Requirements.

  • Updated Scope Document v2.

Now the agent knows where to look when a user asks a question.

Step 4: Choose the Model & Write the System Prompt

Okay, now it’s time to choose our LLM — that’s basically the brain of our agent. The LLM is the part that takes the user’s question, looks at the retrieved context, and then generates the final answer.

In Stack AI you’ve got a choice here, because different providers offer different models. The important thing is to pick the one that makes sense for your project — and that usually comes down to the trade-off between performance and cost. If you need deep reasoning, you might go for one of the larger models. But in this case, we just need short, factual answers grounded in emails and attachments, so we don’t need anything overly heavy.

That’s why, inside the AI Assistant block, I’m going to set the provider to OpenAI and choose GPT-4o Mini. It’s quick, cost-efficient, and perfect for this kind of task.

Once you’ve chosen your model, the next thing to set up is the system prompt. Think of the system prompt as the job description for your assistant — it tells the LLM how it should behave, what it can and can’t do, and what style of answers you want. Without this, the model will just answer however it likes, which usually means long-winded or sometimes even made-up answers.

For this project, here’s the system prompt I’ve chosen:

You are the RFP Intelligence Agent for the business development team.

Your role is to provide concise answers using only content from the connected email inbox and its attachments.

- Summarize long email threads, highlighting deadlines, mandatory requirements, and any changes.

- Extract and format lists when questions require them (e.g., required documents).

- Keep responses brief (2–4 sentences) and use bullet points when appropriate.

- If information is not available in the inbox, respond with: “I can’t find this in the inbox.

I’ve also toggled memory on, so the agent can remember past conversations — this is useful for follow-up questions, like say asking “And what about CityNet?” right after checking Acme’s deadline, without needing to repeat the full query.

Step 5: Configure Knowledge Base Settings

Now that we’ve set the system prompt, we need to make sure the agent actually knows where to look for the answers. That means connecting it to Gmail.

So in the Knowledge Base section of the AI Assistant block, just select the Gmail connection we set up earlier. This step is really important, because without it, the agent won’t have access to the inbox — it’ll just be answering based on the model’s training data.

Step 6: Test the Workflow

Now comes the fun part — testing. Let’s ask a few questions:

  • “When is the submission deadline for the Acme Logistics RFP?” → “The submission deadline for the Acme Logistics RFP is 12 June 2025 at 17:00 CET. Late submissions will not be accepted.”

  • “What documents are mandatory for the InnoTech AI RFP?” → Lists three specific docs, pulled directly from attachments.


  • “Summarize the key clarifications from the CityNet Upgrade RFP.” → Outputs a neat summary with bullet points.

  • “What changed between Globex Scope v1 and Scope v2?” → Identifies the updates in smart metering systems and corrected deadlines.

  • “What’s the evaluation scoring criteria for the CityNet Upgrade RFP?” → “I can’t find this in the inbox.”

Now, notice how the agent isn’t afraid to say “I don’t know” when we ask a question the agent does not have an answer for — that’s good behavior. It’s sticking to the source.

Step 7: Review Analytics

It’s always good practice to keep an eye on your agent’s analytics. Why? Because this is how you know whether it’s actually doing a good job. Are people getting the answers they need, is it costing too much to run, are there any errors you need to fix?

In Stack AI, this couldn’t be easier. All you need to do is click on the Analytics tab, and you’ll get a clear view of how your agent is performing. You can see things like:

  • Total runs — how many times the agent has been queried.

  • Errors — in our case, none so far 🎉.

  • Token usage — so you know exactly what it’s costing.

  • Logs — a full record of all inputs and outputs, which is super helpful for debugging or fine-tuning your system prompt.

In our case, the numbers looked solid, and it gave us confidence that the RFP Intelligence Agent was running smoothly.

💡 Pro tip: if you notice lots of fallbacks (the agent keeps saying “I can’t find this in the inbox”), that’s usually a sign your knowledge base needs updating — maybe new emails haven’t been synced, or the documents don’t actually cover what people are asking.

Step 8: Publish & Export the App

Once you’re happy with how the agent is running, the next step is to make it usable for your team. For this, head over to Export.

This is where you can create a proper front-end for your assistant — not just an API endpoint or a link buried somewhere. It means your colleagues can actually interact with it through a simple interface, without needing to know anything about Stack AI.

We set ours up with the title RFP Intelligence Agent and gave it a short description:

Ask me anything about RFPs stored in our shared inbox. I’ll search through emails and attachments to give you clear, concise answers — with citations so you know exactly where the info came from.

In this case, we’re using the web form interface but you could just as easily export it as a widget for your website, hook it up as an API, or even integrate it into other tools your team already uses.

You can also add a custom subdomain (e.g., acme.stack-ai.com) and enable PDF downloads of responses for easy sharing or audit trails.

Now you’ve got a live, shareable interface — a proper RFP Intelligence Assistant powered by RAG.

Wrap-up

And that’s it — we’ve just built a RAG agent that can search through emails and attachments, answer questions, and even admit when it doesn’t know something. No more endless scrolling through inboxes or digging through forwarded threads - yay!

What I really like about this setup is how practical it is. In real life, so many companies have an info@ inbox or a shared email where all sorts of important documents live — from RFPs to compliance forms to client questions. An agent like this saves hours of manual searching, keeps answers consistent, and makes sure the team always has the latest information.

The “RAG” part ensures everything is grounded in actual emails and files, while the “agent” part adds that little bit of initiative — summarizing, organizing, and formatting the answers in a way that’s clear and useful.

This is just one example, but the same idea could work for customer support emails, HR queries, legal correspondence, or anywhere your business relies on shared inboxes.

So next time you find yourself thinking “I know that info is in my emails somewhere…” — imagine having an agent like this doing the searching and answering for you".

And with Stack AI, you’ve got the building blocks to turn an idea into something useful.

Other related articles:

Guillem Moreso

Growth Manager

I explore how AI can make work easier and build AI Agents that tackle daily problems.

Table of Contents

Make your organization smarter with AI.

Deploy custom AI Assistants, Chatbots, and Workflow Automations to make your company 10x more efficient.