Skip to content
RasaGet a free licence

tutorial

Chapter 3 of 10

How to let a Rasa agent look up bookings

by Rod Rivera Published

Give your agent tools to retrieve bookings from a demo database.

Goal

Atlas can list Maya Chen’s bookings by calling tools — not inventing itineraries.

Teach

Tools are async Python functions. Keep a tool inside its skill unless other skills need it. Mantle discovers the skill’s tools automatically while that skill is active:

skills/<name>/tools.py

Use the project’s shared tools folder when two or more skills need the same function. Each skill must import the shared tool:

Shared folder: tools/
Skill setting: import_tools

These helpers are shared because other skills use them:

HelperOther skills that use it
load_customer_profileintro, authenticate, human_handoff
list_bookingsfind_booking, report_baggage

Later chapters keep PIN verification, flight status, cancellation and baggage submission tools inside their own skills.

from rasa.mantle.tools.decorator import ToolContext, tool
from rasa.mantle.tools.result import ToolResult

@tool(description="List the traveler's upcoming bookings and trip summaries.")
async def list_bookings(context: ToolContext = None) -> ToolResult:
    ...
    return ToolResult(llm_response={"ok": True, "bookings": bookings})
  • Function name → tool name
  • Type hints → input schema
  • context is injected by the runtime (not shown to the LLM); the parameter must be named exactly context
  • Structured data returns in ToolResult.llm_response
  • Name the tool in prose by its plain name: “call list_bookings”

Paste

Copy the following files from the prepared snippet folder:

Source: tutorial/snippets/step-02-itinerary/

Copy these files:
skills/check_itinerary/skill.md
tools/travel.py       # shared profile and booking tools
lib/database.py
lib/tool_helpers.py
data/source/*.json

The demo traveller is Maya Chen, whose customer ID is 456. Her Lisbon booking is HT12345. The introduction skill loads her profile when greeting her. The booking tools also use this demo customer ID as a fallback when reading SQLite.

make show-demo-data

Skill instructions

---
name: check_itinerary
description: >
  List the traveler's upcoming trips and booking details.
import_tools:
  - load_customer_profile
  - list_bookings
---

Help the traveler review their itinerary.
If customer details are missing, call load_customer_profile.
Then call list_bookings and summarize each trip in short spoken sentences.
Speak booking references character by character.

Train and try

make train
make inspect

Try: “What trips do I have?”

Verify: Atlas lists Lisbon and Tokyo trips with spoken booking references (for example H T one two three four five).

Talking point

Side effects and lookups belong in tools. Skills guide the conversation using the tool results. Keep a tool inside its skill unless another skill also needs it.

Next

Chapter 4 — Tool constraints