Back to Blog
Tutorial10 min read

Build an AI Customer Support Bot in 30 Minutes

By AgentBackend Team

You have product docs scattered across Notion, a FAQ page nobody updates, and a support inbox that grows faster than your team. What if you could spin up an AI agent that pulls answers from your docs, looks up customer orders in real time, and escalates the hard stuff to a human — all in about 30 minutes?

TL;DR: Create a working AI support agent with RAG, live data access, and escalation in ~30 minutes using AgentBackend's SDK. Upload docs, set up a Data Store, enable tools, and deploy via API or Telegram.

That's what we're building today. No toy demo. A working support agent with knowledge retrieval, live data access, and a deploy-ready API endpoint.

What You'll Build

By the end of this tutorial, you'll have a support agent that:

  1. Answers product questions from your docs — Upload PDFs, markdown files, or plain text. The agent uses retrieval-augmented generation (RAG) to find relevant passages and compose accurate answers.
  2. Looks up customer data in real time — Order status, account details, subscription info. The agent queries your Data Store directly.
  3. Escalates complex issues — When the agent isn't confident or the customer asks for a human, it flags the conversation for your team.

The whole thing runs on AgentBackend's infrastructure. You don't manage servers, vector databases, or webhook endpoints.

Prerequisites

  • An AgentBackend account — sign up here if you haven't. Every account starts with $3 in free credits, which is enough to follow this tutorial and run a few hundred test conversations.
  • Python 3.8+ or Node.js 18+ installed locally.
  • A few product docs to upload (PDFs, markdown, or text files). If you don't have any handy, a README or FAQ page works fine.

Install the SDK before we start:

bash
# Python
pip install agentbackend

# JavaScript / TypeScript
npm install agentbackend

Step 1: Create the Agent

Head to the AgentBackend Console and start a new agent. The console uses a chat-based builder — you describe what you want, and it configures the agent for you.

Try something like:

"Create a customer support agent for an e-commerce store. It should answer questions about products and shipping, look up order status, and escalate billing disputes to a human."

The builder will set up your agent's system instructions, select a model (Gemini 2.5 Flash is a good default for support — fast and cheap), and suggest tools to enable.

You can also create the agent via the SDK if you prefer working in code:

python
from agentbackend import AgentBackend

ab = AgentBackend("ak_YOUR_API_KEY")

agent = ab.agents.create(
    name="Support Bot",
    instructions="""You are a customer support agent for Acme Store.
Answer questions about products, shipping, and orders using the knowledge base and data store.
If a customer asks about billing disputes, refunds over $100, or expresses frustration, escalate to a human agent.
Always be helpful, concise, and honest. If you don't know something, say so.""",
    model="gemini-2.5-flash",
)

print(f"Agent created: {agent.agent_id}")
javascript
import { AgentBackend } from "agentbackend";

const ab = new AgentBackend({ apiKey: "ak_YOUR_API_KEY" });

const agent = await ab.agents.create({
  name: "Support Bot",
  instructions: `You are a customer support agent for Acme Store.
Answer questions about products, shipping, and orders using the knowledge base and data store.
If a customer asks about billing disputes, refunds over $100, or expresses frustration, escalate to a human agent.
Always be helpful, concise, and honest. If you don't know something, say so.`,
  model: "gemini-2.5-flash",
});

console.log(`Agent created: ${agent.agentId}`);

Tip: Good system instructions make or break a support bot. Be specific about what it should and shouldn't do. "Be helpful" is vague. "Answer shipping questions using the knowledge base, and escalate billing disputes" gives the model clear boundaries.

Step 2: Upload Knowledge

This is where your agent gets smart about your product. Upload your docs — FAQs, product guides, return policies, anything a support agent would reference.

python
from agentbackend import AgentBackend

ab = AgentBackend("ak_YOUR_API_KEY")

# Upload a single document
doc = ab.knowledge.upload("agent_xxx", "product-faq.pdf")
print(f"Uploaded: {doc.filename} ({doc.chunk_count} chunks)")

# Upload multiple docs
files = ["shipping-policy.md", "return-guide.pdf", "product-catalog.txt"]
for f in files:
    ab.knowledge.upload("agent_xxx", f)
    print(f"Uploaded: {f}")
javascript
import { AgentBackend } from "agentbackend";

const ab = new AgentBackend({ apiKey: "ak_YOUR_API_KEY" });

// Upload a single document
const doc = await ab.knowledge.upload("agent_xxx", "product-faq.pdf");
console.log(`Uploaded: ${doc.filename} (${doc.chunkCount} chunks)`);

// Upload multiple docs
const files = ["shipping-policy.md", "return-guide.pdf", "product-catalog.txt"];
for (const f of files) {
  await ab.knowledge.upload("agent_xxx", f);
  console.log(`Uploaded: ${f}`);
}

Behind the scenes, AgentBackend chunks your documents, generates embeddings, and indexes them for retrieval. When a customer asks a question, the agent searches this index to find relevant passages before generating an answer. You can read more about how this works in the Knowledge documentation.

Upload takes a few seconds per document. Once it's done, your agent can answer questions about anything in those files.

Step 3: Set Up Data Store

A support bot that can only search docs is limited. The real power comes when it can look up live customer data — order status, account details, subscription plans.

AgentBackend's Data Store gives your agent a structured database it can query directly. You set up the schema using a conversational flow — describe your tables and the platform creates them.

In the console, open your agent's Data Store tab and describe your schema:

"Create a customers table with fields: customer_id (text, primary key), name (text), email (text), plan (text), created_at (timestamp). Then create an orders table with: order_id (text, primary key), customer_id (text), status (text), total (number), shipping_address (text), created_at (timestamp)."

The database agent will create both tables and confirm the schema. You can then insert sample data to test with:

"Insert a customer: customer_id 'cust_001', name 'Jane Smith', email 'jane@example.com', plan 'pro'. Then insert an order: order_id 'order_4521', customer_id 'cust_001', status 'shipped', total 89.99, shipping_address '123 Main St, Portland OR'."

For production, you'll populate the Data Store via the API or set up a sync from your application database. But sample data is enough to test the flow end-to-end.

Step 4: Configure Tools

Your agent needs tools enabled to actually use the knowledge base and Data Store. In the console, go to your agent's configuration and enable:

  • tenant_query — Lets the agent run SQL queries against your Data Store tables
  • tenant_schema_info — Lets the agent inspect table schemas so it knows what data is available

The knowledge base search is enabled automatically when you upload documents.

Your agent's tool configuration should look something like this:

json
{
  "tools": [
    {
      "name": "tenant_query",
      "description": "Query the data store for customer and order information"
    },
    {
      "name": "tenant_schema_info",
      "description": "Get the schema of available data store tables"
    }
  ]
}

With these tools active, the agent can: search your uploaded docs for product info, query the customers table to pull up account details, and query the orders table to check shipping status — all within a single conversation.

Step 5: Test It

Time to see if it actually works. Let's run a test conversation.

python
from agentbackend import AgentBackend

ab = AgentBackend("ak_YOUR_API_KEY")

conv = ab.agent("agent_xxx").conversation()

# Ask about product info (should use knowledge base)
response = conv.send("What's your return policy for electronics?")
print(f"Bot: {response.output}")

# Ask about a specific order (should query Data Store)
response = conv.send("Where is order #4521?")
print(f"Bot: {response.output}")

# Trigger an escalation
response = conv.send("I want to dispute a charge on my account. This is unacceptable.")
print(f"Bot: {response.output}")
javascript
import { AgentBackend } from "agentbackend";

const ab = new AgentBackend({ apiKey: "ak_YOUR_API_KEY" });

const conv = ab.agent("agent_xxx").conversation();

// Ask about product info (should use knowledge base)
let response = await conv.send("What's your return policy for electronics?");
console.log(`Bot: ${response.output}`);

// Ask about a specific order (should query Data Store)
response = await conv.send("Where is order #4521?");
console.log(`Bot: ${response.output}`);

// Trigger an escalation
response = await conv.send(
  "I want to dispute a charge on my account. This is unacceptable.",
);
console.log(`Bot: ${response.output}`);

Here's what you should see:

  1. Return policy question — The agent pulls the relevant section from your uploaded docs and summarizes it.
  2. Order status — The agent queries the orders table, finds order #4521, and reports that it's shipped to 123 Main St, Portland OR.
  3. Dispute escalation — The agent recognizes this as a billing dispute (matching your system instructions) and responds with something like "I understand your frustration. Let me connect you with a team member who can help resolve this."

If the responses aren't quite right, tweak the system instructions. Support bots improve dramatically with specific, clear instructions.

Step 6: Deploy

Your agent is working. Now let's make it accessible to real users.

Option A: API endpoint — Every agent gets an API endpoint out of the box. Point your frontend, mobile app, or existing support widget at it:

bash
curl -X POST https://api.agentbackend.ai/v1/agents/agent_xxx/run \
  -H "Authorization: Bearer ak_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Where is my order #4521?",
    "session_id": "session_abc123"
  }'

The session_id maintains conversation context across multiple requests from the same user.

Option B: Connect a channel — If you want the agent live on Telegram, you can connect it in a few lines. See our full Telegram bot tutorial for the walkthrough, or check the Channels documentation for all supported platforms.

Step 7: Add Guardrails

Before you point real customers at your bot, set up basic safety nets.

Input validation catches prompt injection attempts and off-topic queries before they reach the model. In your agent's configuration, you can define rules like:

  • Block messages that attempt to override system instructions
  • Flag messages in languages you don't support
  • Reject messages that exceed a character limit

Output validation checks the agent's responses before they reach the customer:

  • Ensure responses don't contain competitor recommendations
  • Flag responses that promise specific refund amounts
  • Catch hallucinated URLs or phone numbers

You configure these in the agent's settings in the console. The guardrails run as a lightweight check on every message — they add a few milliseconds of latency, not seconds.

Going Further

You have a working support agent. Here are a few things to explore next:

  • Scheduling — Set up the agent to run periodic tasks, like checking for overdue orders and sending proactive updates.
  • More channels — Deploy the same agent to Telegram, or embed it in your web app.
  • Agent orchestration — Chain multiple agents together. For example, a triage agent that routes to specialized support agents for billing, shipping, or technical issues.
  • Data Store sync — Connect your production database so the agent always has up-to-date customer information.

If you want to understand the cost math behind running a support bot at scale, check out our guide on how to reduce support costs by 80% with AI agents.

Frequently Asked Questions

How long does it take for uploaded documents to become searchable?

Most documents are indexed within 5–15 seconds. Large PDFs (100+ pages) may take up to a minute. You can check the indexing status in the console or via the API — the document status changes from processing to ready once it's searchable.

Can the bot handle images or file attachments from customers?

Currently, the agent processes text-based conversations. If a customer sends an image (like a screenshot of an error), you'll want to handle that in your frontend and either convert it to text or route it to a human agent. Image understanding support is on the roadmap.

What about hallucination? How do I prevent the bot from making things up?

Three things help significantly. First, strong system instructions that tell the agent to say "I don't know" when it can't find an answer in the knowledge base. Second, high-quality docs — the better your uploaded content, the less the model needs to fill gaps. Third, output guardrails that flag responses containing information not grounded in your documents. RAG-based answers with good source material hallucinate far less than pure generation.

How do I handle escalation to a human agent?

Define escalation triggers in your system instructions (billing disputes, frustrated customers, questions outside the bot's scope). When the agent decides to escalate, it can output a structured flag in its response that your application logic catches and routes to your support queue. If you're using a channel like Telegram, you can configure the agent to send a notification to a staff group.

What does it cost to run this for 1,000 support tickets per month?

Rough estimate: using Gemini 2.5 Flash, each conversation costs about $0.03–$0.08 depending on length. For 1,000 tickets, that's $30–$80/month in LLM costs plus your AgentBackend plan. Compare that to $5,250/month for a human agent handling the same volume. Check our pricing page for current rates.

Ready to build your support bot? Create a free AgentBackend account and follow along — you'll have a working agent before your coffee gets cold. If you get stuck, our documentation covers every step in detail.

Related Posts