Skip to main content
0 reactions

Rasa Tutorial — Part 4: Tools: Let Your Agent Run Python

Featured card for Rasa Tutorial Part 4, Tools: Let Your Agent Run Python, with a terminal window ticking off tools.py, @tool, find_branches(town) and ToolResult, and the JD Bots logo.
Rasa Tutorial, Part 4: Tools: Let Your Agent Run Python.

Instructions tell your agent what to say. Tools let it do things: look something up, check a status, place an order. In this part of the Rasa Tutorial, you give your Rasa Mantle agent its first tool, a short Python function that finds the bank’s branches in a town.

By the end, the agent from Part 3 will have a third skill, find_branch. You’ll see in the Rasa Inspector what Claude passed to your tool and what the tool sent back.

This is Part 4 of the Rasa Tutorial. The parts in Module B, Building Skills:

  • Part 3: Write a Skill’s Instructions
  • Part 4: Tools: Let Your Agent Run Python (you are here)
  • Part 5: Memory: Remember What Matters
  • Part 6: References: Answer from Your Documents
  • Part 7: Responses: Control the Exact Wording
All parts of the Rasa Tutorial

Module A: Start Here

Module B: Building Skills

Module C: Progressive Control

  • Part 8: Tool Constraints
  • Part 9: Scoped Instructions
  • Part 10: Ordered Blocks
  • Part 11: Sub-skills and Composition

Module D: Orchestration

  • Part 12: The Runtime Loop: How Mantle Handles a Turn
  • Part 13: Guarantees and Guardrails
  • Part 14: Skills and Routing
  • Part 15: Context Management

Module E: Agent Setup

  • Part 16: agent.yml: Identity, Persona and Rules
  • Part 17: integrations.yml: Claude, Model Groups and Routing
  • Part 18: MCP Tools
  • Part 19: Hooks

Module F: Testing

  • Part 20: Simulate and Evaluate Your Agent
  • Part 21: Scenarios and Assertions
  • Part 22: Build Faster with the Rasa Copilot

Module G: Voice

  • Part 23: Talk to Your Agent in the Browser
  • Part 24: Designing for Voice
  • Part 25: Connect a Phone Line
  • Part 26: Test and Monitor Voice

Module H: Channels

  • Part 27: The REST Channel and a Website Chat Widget
  • Part 28: Microsoft Teams

Module I: Observability

  • Part 29: Tracing with Langfuse
  • Part 30: Metrics and Conversation Events

Module J: Deploy

  • Part 31: Run Your Agent with Docker
  • Part 32: CI/CD for a Rasa Agent
  • Part 33: Deploy to Kubernetes with Rasa’s Helm Chart
  • Part 34: Load Testing
  • Part 35: Deploy on AWS
  • Part 36: Deploy on Azure
  • Part 37: Deploy on Google Cloud

Module K: Rasa Studio

  • Part 38: Rasa Studio with a Mantle Agent

Module L: Wrap-up

  • Part 39: Final Project, Cheat Sheet and What to Learn Next

Cost: Rasa’s Developer Edition licence is free. Claude is pay-per-use: Claude Sonnet 5.5, the model this series uses, costs $2 per million input tokens and $10 per million output tokens (Claude pricing (opens in a new tab)). In this part you send two messages. With the greeting, they make six calls to Claude, which cost about $0.04. That’s an estimate: in Part 2, eight calls cost $0.05 on the Claude Console.

Prerequisites

Step 1: Create a Folder for the Skill

Open Terminal, go to your project folder and turn on its virtual environment:

TerminalBash
cd my-rasa-agent
source .venv/bin/activate

Create a folder for the new skill:

TerminalBash
mkdir skills/find_branch

This skill gets two files: tools.py with the tool, and skill.md with the instructions that say when to use it.

Step 2: Write the Tool in tools.py

In your text editor, create a file named tools.py in the skills/find_branch folder. Start with two imports from Rasa Pro:

skills/find_branch/tools.py (excerpt)Python
from rasa.mantle.tools.decorator import ToolContext, tool
from rasa.mantle.tools.result import ToolResult

tool marks a function as a tool, ToolContext gives a tool access to the conversation, and ToolResult carries what the tool sends back to Claude.

Next comes the data the tool searches. A real agent would ask your bank’s systems. This demo keeps a few fictional branches in a list:

skills/find_branch/tools.py (excerpt)Python
BRANCHES = [
    {"town": "Riverton", "name": "Riverton High Street", "address": "14 High Street, Riverton"},
    {"town": "Riverton", "name": "Riverton Station", "address": "2 Station Road, Riverton"},
    {"town": "Lakeside", "name": "Lakeside", "address": "8 Harbour Lane, Lakeside"},
    {"town": "Northbridge", "name": "Northbridge Market", "address": "31 Market Square, Northbridge"},
]

Then the tool itself:

skills/find_branch/tools.py (excerpt)Python
@tool(description="Branch locations - list our branches in a town, with their addresses")
async def find_branches(town: str, context: ToolContext = None) -> ToolResult:
    wanted = town.strip().lower()
    found = [branch for branch in BRANCHES if branch["town"].lower() == wanted]
    return ToolResult(llm_response={"town": town, "branches": found})
  • @tool(description=...) turns the function into a tool. Claude reads the description to decide when to call it, so write it like a skill’s description: the subject first.
  • The function’s name, find_branches, is the tool’s name. Its typed inputs, here town: str, are what Claude must fill in when it calls the tool.
  • Rasa fills in context itself and never shows it to Claude. A tool must be async, and this input must be named exactly context.
  • The body removes spaces and capitals from the town name, so “Riverton” and “riverton” both match. Then it keeps the branches in that town.
  • llm_response is what Claude reads as the tool’s result. Return only what the reply needs: everything in it goes to Claude.

Here’s the complete file. Save it:

skills/find_branch/tools.pyPython
"""Branch lookup for the find_branch skill."""

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

# Fictional branches for this demo.
BRANCHES = [
    {"town": "Riverton", "name": "Riverton High Street", "address": "14 High Street, Riverton"},
    {"town": "Riverton", "name": "Riverton Station", "address": "2 Station Road, Riverton"},
    {"town": "Lakeside", "name": "Lakeside", "address": "8 Harbour Lane, Lakeside"},
    {"town": "Northbridge", "name": "Northbridge Market", "address": "31 Market Square, Northbridge"},
]


@tool(description="Branch locations - list our branches in a town, with their addresses")
async def find_branches(town: str, context: ToolContext = None) -> ToolResult:
    wanted = town.strip().lower()
    found = [branch for branch in BRANCHES if branch["town"].lower() == wanted]
    return ToolResult(llm_response={"town": town, "branches": found})

Step 3: Tell the Skill When to Use the Tool

Create a file named skill.md in the same folder, with a description and instructions as in Part 3:

skills/find_branch/skill.mdPlain text
---
name: Find a Branch
description: Branch locations - addresses of our branches in a town or city
---

Help the customer find a branch.

1. If they haven't said which town or city, ask them.
2. Look it up with @tool.find_branches.
3. Give the name and address of each branch it returns, and only those. If it
   returns none, say we have no branch there and mention that the mobile app
   works around the clock.
  • There’s nothing to register: Mantle finds the tools in a skill’s tools.py by itself, and offers them to Claude while that skill is active.
  • @tool.find_branches names the tool in the instructions. The steps are numbered because each one needs the one before it.
  • “And only those” keeps Claude to the branches your tool returned, so it doesn’t make up an address.

Step 4: Train Your Agent

TerminalBash
rasa train
Output (the lines that matter)Plain text
2026-11-19 09:14:00 INFO     rasa.mantle.model_archive.snapshot  - [info     ] Mantle model package saved at 'models/20261119-091400-compact-membership.tar.gz'.

Training loads your tools.py. If Python can’t load it, for example because of a typo in an import, training fails instead of saving a model.

Step 5: Ask Your Agent for a Branch

TerminalBash
rasa inspect

When the Rasa Inspector opens in your browser, type Is there a branch in Riverton? and press Enter. When the reply arrives, type What about Westford?:

A conversation in the Rasa Inspector: the greeting lists branch locations among the things the agent can help with; the user asks if there is a branch in Riverton, and the agent lists Riverton High Street and Riverton Station with their addresses; then the user asks about Westford, and the agent says there is no branch there and mentions the mobile app.
The agent answers from what the find_branches tool returned.

Riverton has two branches in the tool’s list, so the agent named both. Westford has none, so the agent said so and mentioned the mobile app, as the instructions say.

Click Inspect at the top of the page. Under your first question, Tool call: find_branches shows that Claude called your tool:

Inspect mode in the Rasa Inspector under the question Is there a branch in Riverton: an LLM call, the Find a Branch skill activated, another LLM call, Tool call find_branches, and a final LLM call.
Claude called find_branches after the Find a Branch skill started.

Click Tool call: find_branches to see the call’s details:

The Tool executed panel of the Rasa Inspector: the tool find_branches, source local, the arguments with town set to Riverton, and the result listing the Riverton branches.
The arguments Claude chose, and the result your tool returned.
  • Source: local means the tool came from the skill’s own tools.py.
  • Arguments is what Claude filled in from the customer’s words: "town": "Riverton".
  • Result is what your tool returned. Claude wrote its reply from it.

When you’re done, go back to Terminal and press Ctrl+C to stop the agent.

Clean Up

If the agent is still running, press Ctrl+C in Terminal to stop it. Claude charges only when your agent calls it, so a stopped agent costs nothing. Keep the my-rasa-agent folder: the next part builds on it.

Common Mistakes

MistakeDo this instead
Writing def instead of async defA tool must be async.
Naming the last input something other than contextName it exactly context, so Rasa fills it in.
Changing tools.py without training againRun rasa train, then start rasa inspect again, after every change.
Returning more than the reply needs, such as internal idsReturn only what Claude needs to answer. Everything in llm_response goes to Claude.
Putting API keys in tools.pyKeep keys in .env, and read them in the tool.

Troubleshooting

ProblemFix
rasa train fails after you add tools.pyPython couldn’t load the file. Check the imports, spelling and indentation, then train again.
Inspect mode shows no Tool call: find_branchesCheck that the file is at skills/find_branch/tools.py and that the instructions name the tool, then train again.
The agent names a branch that isn’t in your listKeep “and only those” in the instructions, and compare the reply with the tool call’s Result.

FAQ

Does Claude see my tool’s code?

No. Claude sees the tool’s name, description and inputs, and then the result it returns. Your code runs on your computer.

Can a tool call my company’s systems?

Yes. A tool is Python, so it can call an API or a database instead of reading a list. Part 18 shows another way: tools that run on an MCP server.

Can several skills share one tool?

Yes. Put the tool in a tools folder at the project root, and list it under import_tools in the frontmatter of each skill that uses it.

Conclusion

You wrote your first Mantle tool: an async Python function with the @tool decorator in a skill’s tools.py, which Mantle found by itself. The skill’s instructions told Claude when to call it, and the Inspector showed the arguments Claude chose and the result your tool sent back.

← Previous: Part 3: Write a Skill’s Instructions

Coming next: Part 5: Memory: Remember What Matters.

Additional Resources

Rasa, Claude and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by Rasa Technologies or Anthropic.

0 comments