Skip to main content

Run an agent with a knowledge base and a tool

What you'll build: a trip planner for a small travel agency. It answers from the agency's three itinerary files and checks the live weather in a trip's base city.

An agent is three things you already have or can make in the dashboard: a prompt, the tools bound to that prompt, and the knowledge bases attached to the agent. AcruxCore runs the whole loop, not your app. It calls the model, runs each search and each tool call, and feeds the results back until the model has an answer. Your app sends one message and gets the answer back. Every step lands in one trace.

Each step below is done in the dashboard. Under each one, Do this in code shows the same step with the Python and Node SDKs.

Before you start​

You need two models registered under Gateway → Models: a chat model that can call tools, and an embedding model. Set each model's Kind to match, Chat or Embedding: the agent's Model list shows only chat models, and the knowledge base's Embedding model list shows only embedding models. This guide uses gpt-4o-mini and text-embedding-3-small from OpenAI. Route calls through the gateway shows how to add a provider key and a model.

Do this in code

Create an API key under Account & keys, then install the SDK and set two environment variables:

pip install acruxcore
export ACRUXCORE_API_KEY=acx_sk_...
export ACRUXCORE_BASE_URL=https://api.acruxcore.com/api/v1

The API takes a model's id, but the dashboard shows only the model's name. models.list() returns both, so the snippets below look each id up by name:

from acruxcore import AcruxCore

async with AcruxCore() as hub:
model_ids = {m.public_name: m.id for m in await hub.models.list()}

1. Create the knowledge base​

Open Knowledge and click New knowledge base.

  • Kind: keep Documents. A documents base is searched by meaning. A Tables base holds CSV and Excel files that the agent queries with SQL instead; see Let an agent count and filter a spreadsheet.
  • Name: Trip itineraries. The agent's search tool is named after it: search_trip_itineraries.
  • Description: The agency's trip itineraries: destination, season, price and day-by-day plan. The model reads this text to decide when to search, so say what is inside.
  • Embedding model: text-embedding-3-small. Before saving, AcruxCore embeds one test text with the model, so a model that cannot embed is rejected here.
  • Chunking method: keep Paragraphs and sentences, with Chunk size 500 and Overlap 50. Each document is split at paragraph and sentence breaks into chunks of about 500 tokens, and neighbouring chunks share 50 tokens.

The New knowledge base dialog with Documents selected, the name Trip itineraries, its description and the text-embedding-3-small model

Click Create. You can change the embedding model later only while the knowledge base has no documents, because every chunk is embedded with that model.

Do this in code
kb = await hub.knowledge_bases.create(
"Trip itineraries",
embedding_model_id=model_ids["text-embedding-3-small"],
description="The agency's trip itineraries: destination, season, price and day-by-day plan.",
)

Download the three itinerary files from data/itineraries. Each is a short Markdown file with a trip's season, base city, price and daily plan.

On the knowledge base's page, click Choose files and pick all three. You can also drop files on the page, or click Paste text to add text without a file. A knowledge base takes .txt, .md, .pdf and .docx files of up to 10 MB each.

Each file is chunked and embedded in the background. Its status goes from Queued to Processing to Ready within a few seconds. A file whose processing fails shows Failed with the reason, and a Retry button.

Under Test a search, type a trip with snow and click Search. You get the chunks the agent would get for that query, closest first:

Three itinerary files marked Ready, and a test search for "a trip with snow" that returns the Lapland itinerary with score 0.418

The score is 1 − cosine distance between the query and the chunk, so higher means closer. The Lapland trip comes first although its text never says "snow". It says "winter", "husky safari" and "-20 C", and the embeddings of those words are close to the query's.

Do this in code

upload_files takes file paths. Processing runs in the background, so wait until every document is ready before you search:

import asyncio
from pathlib import Path

await hub.knowledge_bases.upload_files(kb.id, sorted(Path("data/itineraries").glob("*.md")))

while not all(d.status == "ready" for d in await hub.knowledge_bases.list_documents(kb.id)):
await asyncio.sleep(1)

hits = await hub.knowledge_bases.search(kb.id, "a trip with snow", top_k=1)
print(hits[0].filename, round(hits[0].score, 2)) # lapland-northern-lights.md 0.42

A document whose status is failed has its reason in error. The full setup script stops on one.

3. Create the weather tool​

The agent gets the weather from wttr.in, which needs no API key. You describe the HTTP request once, and AcruxCore makes it each time the model calls the tool.

Open Tools and click New tool:

  • Name: get_trip_weather.
  • Description: Get the current weather and a three-day forecast for one city.
  • Parameters: one row, city, type string, marked req, described as City name, e.g. 'Rovaniemi'. Tick Reject arguments not listed above.
  • Executor: HTTP — AcruxCore calls a URL for you, method GET, URL https://wttr.in/{{arg.city}}. The {{arg.city}} placeholder is replaced with the city the model passes.
  • Query params: one row, format = j1, which asks wttr.in for JSON.

The New tool dialog with the HTTP executor, the wttr.in URL and the format=j1 query param

wttr.in returns about 40 KB of JSON. Paste this Response transform so the model gets only the current conditions and the daily highs and lows:

function transform(input) {
const now = input.body.current_condition[0];
return {
temp_c: Number(now.temp_C),
feels_like_c: Number(now.FeelsLikeC),
conditions: now.weatherDesc[0].value,
forecast: input.body.weather.map((d) => ({ date: d.date, max_c: Number(d.maxtempC), min_c: Number(d.mintempC) })),
};
}

Click Create tool. Create a tool covers every field in this dialog.

An agent runs HTTP tools only

An agent runs on AcruxCore, so it can only call tools that AcruxCore can run: HTTP tools and knowledge-base searches. A prompt with a Client tool bound to it cannot run as an agent, and the agent's page says so.

Do this in code

A tool is created in two calls: the tool itself, then its first version with the parameters and the executor. The transform above is saved as data/weather_transform.js.

from pathlib import Path

tool = await hub.tools.create("get_trip_weather")
await hub.tools.commit_version(
tool.id,
description="Get the current weather and a three-day forecast for one city.",
parameters_schema={
"type": "object",
"required": ["city"],
"properties": {"city": {"type": "string", "description": "City name, e.g. 'Rovaniemi'."}},
"additionalProperties": False,
},
executor={
"type": "http", "method": "GET", "url": "https://wttr.in/{{arg.city}}",
"query": [{"name": "format", "value": "j1"}],
"responseTransform": Path("data/weather_transform.js").read_text(),
},
)

4. Create the prompt and connect the tool​

The prompt holds the agent's instructions. Open Prompts, click New prompt, name it trip-planner and click Create prompt. In the System message, write:

You are a trip planner for a small travel agency.
Only recommend trips that exist in the agency's itineraries: search them before answering.
When the traveller asks about current conditions, check the weather for the trip's base city.
Quote the trip's name, season and price exactly as the itinerary states them.

The trip-planner prompt editor with the system message filled in

Click Commit new version. The first version gets the production and staging aliases, and the agent will run whichever version production points to. Leave Default model empty, because the agent sets its own model in step 5.

Open the prompt's Tools tab, click + Connect a tool from the catalog and pick get_trip_weather. It saves straight away and follows the tool's production alias:

The prompt's Tools tab with get_trip_weather connected and following production v1

The knowledge base is not connected here. You attach it to the agent in the next step, and the agent turns the knowledge base into a search tool.

Do this in code
SYSTEM_PROMPT = Path("data/system-prompt.txt").read_text()

prompt = await hub.prompts.create("trip-planner")
await hub.prompts.commit_version(prompt.id, [{"role": "system", "content": SYSTEM_PROMPT}])
await hub.prompts.set_tool_binding(prompt.id, tool.id, tool_alias="production")

data/system-prompt.txt holds the system message above.

5. Create the agent​

Open Agents and click New agent:

  • Name: Trip planner. Your code can run the agent by this name or by its id.
  • Prompt: trip-planner, Alias: production (v1).
  • Model: gpt-4o-mini. If you choose Prompt's default model instead, the agent uses the model bound to the prompt version.
  • Max steps: keep 8. That is the most model calls one message may take, so a model that keeps calling tools stops there. Each step runs at most 10 tool calls.
  • Knowledge: click Attach knowledge base and pick Trip itineraries. It appears as a card that names the tool the model calls, search_trip_itineraries. Set Results to return to 3, the number of chunks one search returns. An agent can use up to five knowledge bases, and New knowledge base in the same dialog creates one without leaving the agent.

The New agent form with the trip-planner prompt, gpt-4o-mini, and the Trip itineraries card under Knowledge, called search_trip_itineraries

The card's Reranker and Decision model stay Off in this guide. Rerank and filter an agent's search results turns them on.

Click Create agent. The Tools panel lists every tool the model will see: the weather tool from the prompt, and search_trip_itineraries from the knowledge base.

The agent's Tools panel listing get_trip_weather as an HTTP tool and search_trip_itineraries as a search tool

Do this in code
agent = await hub.agents.create(
"Trip planner",
prompt_id=prompt.id,
model_id=model_ids["gpt-4o-mini"],
knowledge_bases=[{"knowledge_base_id": kb.id, "top_k": 3}],
)
print([k.tool_name for k in agent.knowledge_bases] + [t["name"] for t in agent.tools])
# ['search_trip_itineraries', 'get_trip_weather']

6. Chat with the agent​

On the agent's page, click Chat and ask:

I'd like a winter trip with snow. Which one do you have, what does it cost,
and what is the weather like there right now?

The agent answers in two tool calls. First the model searches the itineraries for winter trip with snow and gets the Lapland trip. Then it calls get_trip_weather for Rovaniemi, the trip's base city. Steps shows each call with its arguments and the result the model received:

The chat page with the question, the two steps: a search of Trip itineraries and a get_trip_weather call for Rovaniemi, and the answer: the Lapland trip, its season, its price and the weather in Rovaniemi

Below the steps comes the answer: the Lapland northern lights trip, winter, 1,450 EUR per person, and the current temperature in Rovaniemi. View trace opens the run's trace, with a span for each model call, search and tool call. The agent's Runs tab lists every run with its status.

Do this in code

agents.stream runs the agent and yields each step as it happens. agents.run waits and returns the finished run instead.

QUESTION = "I'd like a winter trip with snow. Which one do you have, what does it cost, and what is the weather like there right now?"

async for event in hub.agents.stream("Trip planner", message=QUESTION):
if event.type == "step.llm":
for call in event.data.get("toolCalls") or []:
print(f" step {event.data['step']}: model calls {call['name']}({call.get('arguments')})")
elif event.type == "run.failed" and event.run is None:
# A run that fails before it is recorded carries only the error.
raise SystemExit(f"The run failed: {event.data['error']['message']}")
elif event.run is not None:
print(event.run.output)

Run every step from code​

The three scripts below do everything on this page. setup_trip_agent creates the knowledge base, the tool, the prompt and the agent. ask_trip_agent asks the question and prints each step. teardown_trip_agent deletes all four, so you can run the setup again.

The setup script uses the models gpt-4o-mini and text-embedding-3-small. If yours have other names, set CHAT_MODEL and EMBED_MODEL. Then run the scripts from the folder that holds python/, typescript/ and data/:

export CHAT_MODEL=gpt-4o-mini EMBED_MODEL=text-embedding-3-small # your gateway's model names
python python/setup_trip_agent.py
python python/ask_trip_agent.py
Search 'a trip with snow': lapland-northern-lights.md (score 0.42)
Agent Trip planner (c6ba3e90-eae7-4bdd-a5a5-2f9fa766e84d)
Tools the model sees: ['search_trip_itineraries', 'get_trip_weather']
Q: I'd like a winter trip with snow. Which one do you have, what does it cost, and what is the weather like there right now?

step 1: model calls search_trip_itineraries({"query":"winter trip with snow"})
step 1: search_trip_itineraries -> ok=True
step 2: model calls get_trip_weather({"city":"Rovaniemi"})
step 2: get_trip_weather -> ok=True

A: I recommend the **Lapland northern lights** trip. Here are the details:

- **Season:** winter (December to March)
- **Price:** 1,450 EUR per person

**Current Weather in Rovaniemi:**
- Temperature: -9°C (feels like -13°C)
- Conditions: Light snow

Enjoy a magical winter experience!

status=succeeded trace=bf6b6798-2dc0-4939-9e94-bcc4bd716a27

The Node scripts take the same steps and print the same lines: node typescript/setup_trip_agent.mjs, then node typescript/ask_trip_agent.mjs.

Next steps​