Skip to main content

Build a help-desk agent from documents and a spreadsheet

What you'll build: the help desk of an outdoor-gear web shop. It answers "can I return a used tent?" by searching the shop's policy files, and "how many orders are still waiting to ship?" by running SQL on a CSV of 120 orders. AcruxCore runs the whole agent: the model calls, the search, the SQL and the loop between them. Your code sends a question and gets the answer back.

The two questions need two kinds of knowledge base. A policy answer sits in one paragraph, so a search that returns the closest passages finds it. A count needs every row of the orders, and a search returns only a few passages, so the orders go in a tables base that the model queries with one SQL SELECT. Each base you attach to the agent becomes one tool the model can call.

GitHub

Before you start​

You need an AcruxCore account, an API key, and two models registered under Gateway → Models: a chat model and an embedding model. This page uses an OpenAI credential with the public names gpt-4o-mini and text-embedding-3-small. Route calls through the gateway shows how to add a credential and register a model.

Nothing to install. Download the data folder, because step 1 copies the prompt from it and step 5 uploads its files.

How each step is shown​

Steps 1 to 5 build the agent, and each one shows two routes in one set of tabs. Dashboard is the click path in the agent builder. curl, Python and Node do the same thing from code. Both routes call the same endpoints and store the same objects, so you can build the agent in the dashboard and run it from code, or the other way round.

In the dashboard you create both knowledge bases from the agent's page, while the agent is still unsaved. Code follows the same order: the bases first, then the agent, then the files.

The data​

The data folder holds three things:

  • policies/: four Markdown files, returns.md, shipping.md, warranty.md and product-care.md. Each ## heading starts one rule, such as "Used items" under "Returns".
  • orders.csv: 120 orders, one row each, with the columns order_id, ordered_on, country, product, category, quantity, total_eur, status, shipped_on and delivered_on. A status is processing, shipped, delivered or returned.
  • system-prompt.txt: the agent's instructions, which step 1 stores as a prompt.
system-prompt.txt
You are the help desk of an outdoor-gear web shop. Answer customers in a friendly, short way.

- For questions about returns, shipping, warranty or product care, search the shop policies and answer only from what you find. Quote the exact number of days, the percentage or the price.
- For questions about an order, or about counts and totals of orders, query the orders table with SQL. Never guess an order's status.
- If neither the policies nor the orders answer the question, say you do not know and offer to pass it to a colleague.

The prompt tells the model which tool fits which question. The model also reads each base's description, which steps 2 and 3 write, so the two texts should agree.

1. Write the system prompt​

An agent follows a stored prompt, so its instructions are versioned like any other prompt. The agent runs the version that the production alias points to, and the first version you commit gets that alias.

Open Prompts and click New prompt. Name it help-desk and click Create prompt. Paste system-prompt.txt into the System message, then click Commit new version.

The prompt editor for help-desk with the system message filled in and the Commit new version button

2. Create the policies base​

A documents base splits each file into chunks and stores an embedding of each chunk, so a search can find the chunks closest in meaning to a question. The policies are short rules under headings, so split them with Markdown headings: each chunk is then one whole rule, with its headings in front, such as Returns > Used items.

Open Agents and click New agent. Fill in the top of the form:

  • Name: Help desk
  • Description: Answers customers from the shop policies and the orders table. Only your team sees it; the model does not.
  • Prompt: help-desk. Alias then shows production (v1).
  • Model: gpt-4o-mini

Leave the page open and unsaved. Under Knowledge, click Attach knowledge base. The dialog lists the bases that already exist in your team. Click New knowledge base to make one without leaving the agent:

  • Kind: Documents
  • Name: Help desk policies. The model calls the base's tool search_help_desk_policies, after this name.
  • Description: The shop's policies: returns and refunds, shipping and delivery times, warranty, and product care. The model reads this text to decide when to search.
  • Embedding model: text-embedding-3-small
  • Chunking method: Markdown headings

The New knowledge base dialog over the agent page: Documents selected, the name Help desk policies, its description, the embedding model text-embedding-3-small and the chunking method Markdown headings

Click Create. The base is created at once and attached to the agent as a card.

3. Create the orders base​

A tables base holds CSV files and Excel sheets as tables. It has no embedding model and no chunks. The agent gets a SQL tool for it instead, which runs one SELECT on a read-only copy of the tables and returns at most 200 rows.

Click Attach knowledge base again, then New knowledge base:

  • Kind: Tables
  • Name: Help desk orders. The tool is called query_help_desk_orders.
  • Description: Every web-shop order since October: order id, order date, country, product, category, quantity, total in EUR, status (processing, shipped, delivered or returned), ship date and delivery date. The model reads this text, together with the table's columns and a few sample rows, to write its SQL.

Click Create. The agent now has two cards.

4. Save the agent​

The agent ties the prompt, the model and both bases together. Each base's card also holds how this agent searches it. Another agent that attaches the same base keeps its own settings.

This agent searches the policies with Results to return set to 4, so each search gives the model the four closest rules. Reranker and Decision model stay off for now. Rerank and filter an agent's search results turns them on.

Set Results to return to 4 and click Create agent. The page reloads as the saved agent. The Tools panel on the right lists search_help_desk_policies and query_help_desk_orders.

The Knowledge section of the saved agent: the Help desk policies card with 4 results to return and the reranker and decision model off, and the Help desk orders card, queried with SQL as query_help_desk_orders

Each code route prints the agent's two tool names, search_help_desk_policies and query_help_desk_orders.

5. Add the files​

The bases are attached but still empty. A CSV becomes a table as soon as its upload returns. The policy files are chunked and embedded in the background, which takes a few seconds, and each file's status changes from processing to ready.

On the Help desk policies card, click Open base. Click Choose files and pick the four files in policies/. When all four show Ready, type Can I return a tent I have used? into Test a search and click Search. The first result is the "Used items" rule from returns.md, which is what the agent will get for the same question.

The Help desk policies base: four documents ready, and a test search whose first result is returns.md, Returns > Used items

Go back to the agent and click Open base on the Help desk orders card. Click Choose files and pick orders.csv. The table orders appears with 120 rows and 10 columns. Try a query runs one SELECT the same way the agent does:

SELECT status, count(*) AS orders
FROM orders
GROUP BY status
ORDER BY orders DESC

The Help desk orders base: the orders table with 120 rows and 10 columns, and the query result delivered 88, shipped 15, returned 10, processing 7

The agent is ready. The setup scripts in the repository run steps 1 to 5 in one go.

6. Ask the agent​

Ask three questions in one conversation: one about a policy, one about a single order, and one that needs counts. The first question starts the conversation. The next two pass its id, so the agent reads the earlier turns as history.

On the agent's page, click Chat and send each question in turn:

I bought a Trail 2 tent three weeks ago and used it once. Can I still return it, and how much do I get back?
Where is my order 20401?
Which product category was returned most often, and how many orders are still waiting to ship?

Under each answer, Steps lists each tool call with its arguments and the start of its result. For order 20401, the model wrote a SELECT on orders and answered from the row it got back.

The chat: the question about order 20401, the query_help_desk_orders step with its SQL and the answer that the Ridge 45 backpack was delivered on November 25, 2026

The answers match the data. A used tent can be returned within 30 days for 80% of the price. Order 20401 was delivered on November 25, 2026. cooking has the most returns, 4, and 7 orders are still processing.

7. Read the trace​

Click View trace under the third answer. The trace has one row per step. Each LLM row is one model call, and the numbered rows under it are the tool calls that model call asked for.

The trace of the third answer: three LLM steps, and three query Help desk orders tool calls numbered 1 to 3, where call 2 is marked red

In this run, the first model call asked for two queries at once, and the second one failed. Click that row to see why: the model added stray characters after the SQL, and DuckDB refused it with a parser error. The model got the error message back as the tool's result, wrote that query again in the next step, and answered from its result.

The failed query Help desk orders call: the error Parser Error: syntax error at or near "}", rowCount 0, and the SQL argument with stray characters after 'processing'

The model writes its SQL again on every run, so your run may have no failed call. When a call does fail, the trace shows the failed call and the retry. The trace's status says Error as soon as any one of its steps failed, even when the run recovered and answered. The run's own status, succeeded, says whether the agent answered.

Run it​

The scripts run steps 1 to 6 for you. Run the setup once, then ask as often as you like:

cd scripts/tutorials/build-a-help-desk-agent
bash bash/setup_help_desk.sh
bash bash/ask_help_desk.sh
Agent Help desk (a67dc20d-df5d-4aa9-b6bb-6fd38446f117)
search_help_desk_policies
query_help_desk_orders
Q: I bought a Trail 2 tent three weeks ago and used it once. Can I still return it, and how much do I get back?
model calls search_help_desk_policies({"query":"returns"})
A: You can return your Trail 2 tent since you are within the 30-day return window. Since the tent was used, you'll get back 80% of the price. Please ensure it's clean, dry, and undamaged for the return. If you need assistance with the return process, just let me know!
status=succeeded cost=$0.000232 trace=b20eab4c-47ee-4ef7-a359-8bcac1cdff9a

Q: Where is my order 20401?
model calls query_help_desk_orders({"sql":"SELECT * FROM orders WHERE order_id = 20401"})
A: Your order #20401 for the Ridge 45 backpack has been delivered on November 25, 2026. If you have any further questions, feel free to ask!
status=succeeded cost=$0.000312 trace=b3daf96b-0732-4898-94e6-1a93d0826998

Q: Which product category was returned most often, and how many orders are still waiting to ship?
model calls query_help_desk_orders({"sql": "SELECT category, COUNT(*) as count FROM orders WHERE status = 'returned' GROUP BY category ORDER BY count DESC LIMIT 1;"})
model calls query_help_desk_orders({"sql": "SELECT COUNT(*) as count FROM orders WHERE status = 'processing';"})
A: The product category that was returned most often is "cooking," with 4 returns. Additionally, there are currently 7 orders still waiting to ship. If you need more information, just let me know!
status=succeeded cost=$0.000273 trace=b5dca4df-9753-4c77-aa3e-11d0b3778f9e

The setup reads the model names from CHAT_MODEL and EMBED_MODEL, which default to gpt-4o-mini and text-embedding-3-small. Set RERANK_MODEL and DECISION_MODEL to the names of a rerank model and a decision model to rerank and filter the policy search as well. To start again, run the teardown script, which deletes the agent, the prompt and both bases.

What's next​