Skip to content

Recipe: Support Agent with a Knowledge Base (RAG)

This recipe builds a support agent that answers from your own documents instead of the model’s general knowledge: a knowledge base holding a product FAQ, an agent, and a workflow that answers every message from that FAQ. Each piece is documented on its own in the Knowledge Base Guide, the llm node, the response node and Configuring an Agent.

Every call uses a dashboard login: Authorization: Bearer <jwt> and x-huat-platform: customer (see Authentication).

mutation CreateKnowledgeBase($input: CreateKnowledgeBaseInput!) {
createKnowledgeBase(input: $input) {
id
name
}
}
{
"input": {
"name": "Product FAQ",
"description": "Frequently asked questions about the product and billing"
}
}

Assume the id is 88.

A short FAQ fits in one ingestDocument call (up to 500 KB of text), which is searchable as soon as it returns. For a PDF or DOCX, use the file upload flow instead.

mutation IngestFaq($input: IngestDocumentInput!) {
ingestDocument(input: $input)
}
{
"input": {
"knowledgeBaseId": 88,
"fileName": "product-faq.txt",
"text": "Q: How do I reset my password?\nA: Go to Settings > Account > Reset Password. A reset link is emailed within a few minutes.\n\nQ: What is your refund policy?\nA: Full refunds are available within 30 days of purchase. Contact support with your order number to start a refund.\n\nQ: Do you offer annual billing?\nA: Yes. Annual plans are billed once a year and cost 15% less than monthly billing. Switch any time in Settings > Billing."
}
}

The result is the number of passages created.

Ask the way your users will:

query TestRetrieval($knowledgeBaseId: Int!, $query: String!) {
retrieveChunks(knowledgeBaseId: $knowledgeBaseId, query: $query, topK: 5) {
chunkId
content
score
}
}
{ "knowledgeBaseId": 88, "query": "how do I get my money back" }

If the refund passage is not near the top, reword the source document before you continue.

mutation CreateAgent($input: CreateAgentInput!) {
createAgent(input: $input) {
id
}
}
{
"input": {
"name": "Product Support Assistant",
"position": "Support Agent",
"useCase": "SUPPORT",
"personaPrompt": "You are a helpful, concise product support assistant. If something is not covered by your reference material, say you do not have that information and suggest contacting human support. Never guess at policy details."
}
}

useCase: SUPPORT makes evaluations score customer satisfaction. Assume the id is 61. The workflow’s llm node does not read personaPrompt, so Step 4 puts the same instructions in the node.

The graph has no branches: every message goes to one llm node that answers from the knowledge base, then to a response node that sends the answer.

flowchart LR
start([start]) --> answer[answer_from_kb: llm with knowledgeBaseId 88] --> respond[respond: response]
mutation CreateWorkflow($input: CreateWorkflowInput!) {
createWorkflow(input: $input) {
id
}
}
{
"input": {
"name": "Product Support (RAG)",
"description": "Answers product questions from the Product FAQ knowledge base."
}
}

Assume the id is 42. Save the graph:

mutation UpdateWorkflow($input: UpdateWorkflowInput!) {
updateWorkflow(input: $input) {
id
}
}
{
"input": {
"id": 42,
"nodes": [
{
"id": "start",
"type": "start",
"label": "Start",
"config": {},
"position": { "x": 0, "y": 0 }
},
{
"id": "answer_from_kb",
"type": "llm",
"label": "Answer from the product FAQ",
"config": {
"promptTemplate": "You are a helpful, concise product support assistant. Answer the customer's question in two or three sentences. If the answer is not in your reference material, say you do not have that information and suggest contacting human support. Never guess at policy details.",
"knowledgeBaseId": 88,
"outputVar": "kbAnswer",
"streamOutput": false
},
"position": { "x": 0, "y": 100 }
},
{
"id": "respond",
"type": "response",
"label": "Send the answer",
"config": { "messageTemplate": "{{kbAnswer}}", "mood": "helpful" },
"position": { "x": 0, "y": 200 }
}
],
"edges": [
{ "id": "e1", "source": "start", "target": "answer_from_kb" },
{ "id": "e2", "source": "answer_from_kb", "target": "respond" }
]
}
}
  • respond sends kbAnswer unchanged: a second model call to rephrase it would only add latency and room to change the meaning.
  • respond has no outgoing edge, so the turn ends there and the session stays open for the next question. Add an end_session node only on a branch that should end the conversation.
mutation PublishWorkflow($id: Int!) {
publishWorkflow(id: $id) {
id
isPublished
version
}
}
{ "id": 42 }
mutation AttachWorkflow($id: ID!, $input: UpdateAgentInput!) {
updateAgent(id: $id, input: $input) {
id
workflowId
}
}
{ "id": "61", "input": { "workflowId": 42 } }

If the agent seems to ignore the graph, check that isPublished came back true; see Wiring up a workflow.

A customer asks: “How do I get a refund on my order?”

  1. The run enters at start and reaches answer_from_kb.
  2. The message is matched against knowledge base 88; the five best passages, the refund answer among them, are added to the node’s system prompt with an instruction to answer only from them.
  3. The model answers from that material and the text is stored in kbAnswer.
  4. respond sends it, for example: “Full refunds are available within 30 days of purchase. Contact support with your order number to start one.”

For a question the FAQ does not cover, the model is told to say the material does not contain the answer, and the prompt tells it to point to human support. If the search itself fails, the node answers without passages instead of failing; see Fail-open retrieval behavior. To send unanswered questions to a person instead, search with a knowledge_search node first and branch when it finds nothing.