Let an agent count and filter a spreadsheet
What you'll do: give the Trip planner agent the agency's bookings as a table, so it can answer questions such as "how many travellers booked the Lapland trip, and from how many countries?"
Search cannot answer that question. A search returns the few passages closest to the
query, and a count needs every row. A tables knowledge base holds CSV files and Excel
sheets as tables instead. The agent gets a SQL tool for it, writes one SELECT, and reads
the exact result.
This guide builds on the agent from Run an agent with a knowledge base and a tool. The bookings file is in the repository:
bookings.csv— 60 bookings of the three trips
Each row is one booking: booking_id, trip, country, travellers, total_eur,
booked_on and status, which is confirmed or cancelled.
1. Create a tables knowledge base from the agent
Open Agents → Trip planner and click Attach knowledge base. The dialog lists the team's bases that this agent does not use yet. Click New knowledge base to create one without leaving the agent:
- Kind: Tables. A tables base has no embedding model, and its files are not split into chunks.
- Name:
Trip bookings. The agent's SQL tool is named after it:query_trip_bookings. - Description:
Every booking of the agency's trips: trip name, the traveller's country, number of travellers, total price in EUR, booking date and status (confirmed or cancelled).The model reads this text, with each table's columns and a few sample rows, to decide when to query and how to write the SQL.

Click Create. The base is attached to the agent as a new card. Click Save on the agent.
2. Upload the CSV and try a query
On the Trip bookings card, click Open base, then Choose files and pick
bookings.csv. The file becomes a table named after it, bookings, with 60 rows and 7
columns. A base takes .csv and .xlsx files up to 10 MB each. Each sheet of an Excel
workbook becomes its own table, named after the file and the sheet.
Try a query runs one SELECT the same way the agent does. Paste this and click
Run query:
SELECT trip, count(*) AS bookings, sum(travellers) AS travellers,
count(DISTINCT country) AS countries
FROM bookings
WHERE status = 'confirmed'
GROUP BY trip
ORDER BY travellers DESC

The query runs on a read-only copy of the base's tables, with no file or network access.
Anything other than one SELECT is refused, and at most 200 rows come back. You can also
click a table's name to read its rows, and add, change or delete rows.
Do this in code
knowledge_bases.create with kind="tables" creates the base. upload_files adds the
CSV, and the table can be queried as soon as the call returns. agents.update attaches the
base; its knowledge base list replaces the agent's whole list, so the snippet sends the
bases already attached as well.
- Python (SDK)
- Node (SDK)
bookings = await hub.knowledge_bases.create(
"Trip bookings",
kind="tables",
description="Every booking of the agency's trips: trip name, the traveller's country, number of "
"travellers, total price in EUR, booking date and status (confirmed or cancelled).",
)
await hub.knowledge_bases.upload_files(bookings.id, ["data/bookings.csv"])
result = await hub.knowledge_bases.query(
bookings.id,
"SELECT trip, count(*) AS bookings, sum(travellers) AS travellers, "
"count(DISTINCT country) AS countries FROM bookings "
"WHERE status = 'confirmed' GROUP BY trip ORDER BY travellers DESC",
)
print([c["name"] for c in result.columns])
for row in result.rows:
print(row)
agent = next(a for a in await hub.agents.list() if a.name == "Trip planner")
attached = [
{"knowledge_base_id": k.id, "top_k": k.top_k, "rerank_model_id": k.rerank_model_id,
"decider_model_id": k.decider_model_id, "decider_threshold": k.decider_threshold}
for k in agent.knowledge_bases
]
agent = await hub.agents.update(agent.id, knowledge_bases=attached + [{"knowledge_base_id": bookings.id}])
print([k.tool_name for k in agent.knowledge_bases])
import { readFile } from 'node:fs/promises';
const bookings = await hub.knowledgeBases.create({
kind: 'tables',
name: 'Trip bookings',
description: "Every booking of the agency's trips: trip name, the traveller's country, number of travellers, total price in EUR, booking date and status (confirmed or cancelled).",
});
await hub.knowledgeBases.uploadFiles(bookings.id, [{ filename: 'bookings.csv', data: await readFile('data/bookings.csv') }]);
const result = await hub.knowledgeBases.query(
bookings.id,
"SELECT trip, count(*) AS bookings, sum(travellers) AS travellers, count(DISTINCT country) AS countries FROM bookings WHERE status = 'confirmed' GROUP BY trip ORDER BY travellers DESC",
);
console.log(result.columns.map((c) => c.name));
for (const row of result.rows) console.log(row);
const agent = (await hub.agents.list()).find((a) => a.name === 'Trip planner');
const attached = agent.knowledgeBases.map((k) => ({
knowledgeBaseId: k.id, topK: k.topK, rerankModelId: k.rerankModelId, deciderModelId: k.deciderModelId, deciderThreshold: k.deciderThreshold,
}));
const updated = await hub.agents.update(agent.id, { knowledgeBases: [...attached, { knowledgeBaseId: bookings.id }] });
console.log(updated.knowledgeBases.map((k) => k.toolName));
['trip', 'bookings', 'travellers', 'countries']
['Lapland northern lights', 26, 63, 11]
['Lisbon and the Atlantic coast', 19, 39, 9]
['Kyoto autumn colours', 6, 14, 5]
['search_trip_itineraries', 'query_trip_bookings']
3. Check the agent's tools
Back on the agent's page, the Trip bookings card says the model calls it as
query_trip_bookings. A tables card has no search settings, because SQL returns exact
rows and has nothing to rerank.

4. Ask a counting question
Click Chat and ask:
How many confirmed bookings does the Lapland trip have, how many travellers,
from how many countries, and what do they pay in total?
The agent answers in one step. Steps shows the query_trip_bookings call with its SQL
and the start of the result. The answer gives 26 confirmed bookings, 63 travellers, 11
countries and 91,350 EUR, the same numbers as the query in step 2.

5. Read the query in the trace
Click View trace and open the numbered query Trip bookings step. Arguments
holds the SQL the model wrote. Output holds the rows that came back, in the order of
the columns in the SELECT. The step's attributes show the row count and whether the
result was cut at 200 rows.

When the SQL is wrong, the step fails and the model gets the error message, so it can fix the query and try again in the next step. The trace shows each attempt.
Next steps
- Rerank and filter an agent's search results tunes the agent's searches of the itineraries.
- Build a help-desk agent from documents and a spreadsheet builds an agent with both kinds of base from scratch.