Rasa - Conversational AI Framework Cheatsheet
Rasa ist ein Open-Source-Framework zum Bauen von kontextuellen Conversational Assistants. Anders als Prompt-only Chatbots gibt dir Rasa explizite Kontrolle über Dialogue: du definierst Intents, Entities und Flows, und der Assistant folgt Business Logic, die du spezifizierst, anstatt was auch immer das Modell improvisiert. Alles läuft auf deiner eigenen Infrastruktur, was in regulierten Domains wichtig ist. Modernes Rasa (CALM) mischt LLM-gesteuertes Verstehen mit deterministischer Flow-Ausführung — das Modell interpretiert, deine Flows entscheiden.
Installation
| Methode | Befehl |
|---|
| pip | pip install rasa |
| New Project | rasa init |
| Anforderungen | Python 3.9–3.11 (prüfe aktuelle Unterstützung) |
| Verifikation | rasa --version |
Projekt-Struktur
| Path | Enthält |
|---|
domain.yml | Intents, Entities, Slots, Responses, Actions |
data/nlu.yml | Training Examples pro Intent |
data/stories.yml | Beispiel Conversation Paths |
data/rules.yml | Deterministische Rules |
data/flows.yml | CALM Business-Logic Flows |
config.yml | NLU/Policy Pipeline |
actions/actions.py | Custom Python Actions |
Core CLI
| Befehl | Beschreibung |
|---|
rasa init | Scaffold ein neues Assistants |
rasa train | Train das Modell |
rasa shell | Chat damit im Terminal |
rasa run | Starte den Server |
rasa run actions | Starte den Custom Action Server |
rasa test | Führe Tests gegen Test Stories aus |
rasa interactive | Interactive Training/Correction |
rasa data validate | Prüfe Data Consistency |
Intents & Responses definieren
# domain.yml
intents:
- greet
- check_balance
responses:
utter_greet:
- text: "Hi! How can I help?"
slots:
account_id:
type: text
mappings:
- type: from_entity
entity: account_id
actions:
- action_fetch_balance
# data/nlu.yml
nlu:
- intent: check_balance
examples: |
- what's my balance
- how much money do I have
- show account [12345](account_id)
Flows (CALM)
# data/flows.yml
flows:
check_balance:
description: Look up the user's account balance
steps:
- collect: account_id
- action: action_fetch_balance
- action: utter_balance
| Step-Typ | Tut |
|---|
collect | Frag nach und fülle einen Slot |
action | Führe eine Custom oder Utter Action aus |
link | Jump zu einem anderen Flow |
set_slots | Assigned Slot-Werte |
next mit if | Conditional Branching |
Flows sind deterministisch: das LLM entscheidet, welcher Flow der User will, aber der Flow selbst führt genau wie geschrieben aus.
Custom Actions
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
class ActionFetchBalance(Action):
def name(self) -> str:
return "action_fetch_balance"
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain):
account = tracker.get_slot("account_id")
balance = lookup_balance(account)
dispatcher.utter_message(text=f"Your balance is ${balance}")
return []
Führe mit rasa run actions aus (Standard-Port 5055).
Testing
rasa test # end-to-end tests
rasa test nlu --cross-validation
rasa data validate # catch domain/data mismatches
| Test-Typ | Prüft |
|---|
| NLU Tests | Intent/Entity Accuracy |
| Story Tests | Volle Conversation Paths |
| Cross-validation | Generalization der NLU |
Channels & Deployment
| Channel | Notiz |
|---|
| REST | Standard HTTP Endpunkt |
| Web Widget | Embeddable Chat |
| Slack / Teams / Telegram | Built-in Connectors |
| Voice | Via Telephony Integrations |
| Deployment | Docker, Kubernetes/Helm, Self-hosted |
Rasa vs LLM-Only Chatbots
| Aspekt | Rasa | Prompt-only LLM Bot |
|---|
| Control | Explizite Flows/Business Logic | Emergent, schwer zu constrainen |
| Predictability | Hoch | Variabel |
| Compliance | Auditable Paths | Schwierig |
| Hosting | Vollständig Self-hosted | Usually API-abhängig |
| Am besten für | Regulierte, Task-orientierte Assistants | Open-ended Conversation |
Für Open-Ended Agents siehe LangGraph oder Mastra; Rasas Stärke ist deterministische, auditable Task Flows.
Ressourcen