Rasa - Cheatsheet del Framework di IA Conversazionale
Rasa è un framework open-source per costruire assistenti conversazionali contestuali. A differenza dei chatbot solo prompt, Rasa ti dà il controllo esplicito sul dialogo: definisci intenti, entità e flussi e l”assistente segue la logica di business che specifichi piuttosto che ciò che il modello improvvisa. Tutto viene eseguito sulla tua infrastruttura, che è importante per i domini regolamentati. Il Rasa moderno (CALM) miscela la comprensione basata su LLM con l”esecuzione del flusso deterministica — il modello interpreta, i tuoi flussi decidono.
Installation
| Method | Command |
|---|
| pip | pip install rasa |
| New project | rasa init |
| Requirements | Python 3.9–3.11 (check current support) |
| Verify | rasa --version |
Project Structure
| Path | Contains |
|---|
domain.yml | Intenti, entità, slot, risposte, azioni |
data/nlu.yml | Esempi di training per intento |
data/stories.yml | Percorsi di conversazione di esempio |
data/rules.yml | Regole deterministiche |
data/flows.yml | Flussi di logica di business CALM |
config.yml | Pipeline NLU/policy |
actions/actions.py | Azioni Python personalizzate |
Core CLI
| Command | Description |
|---|
rasa init | Forma una nuova scaffolding un assistente |
rasa train | Allena il modello |
rasa shell | Chatta con esso nel terminale |
rasa run | Avvia il server |
rasa run actions | Avvia il server di azioni personalizzate |
rasa test | Esegui test su storie di test |
rasa interactive | Correzione/training interattivo |
rasa data validate | Verifica la coerenza dei dati |
Defining Intents & Responses
# 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 type | Does |
|---|
collect | Chiedi e riempi uno slot |
action | Esegui un”azione personalizzata o utter |
link | Salta a un altro flusso |
set_slots | Assegna valori slot |
next with if | Branching condizionale |
I flussi sono deterministici: l”LLM decide quale flusso l”utente vuole, ma il flusso stesso viene eseguito esattamente come scritto.
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 []
Esegui con rasa run actions (porta predefinita 5055).
Testing
rasa test # end-to-end tests
rasa test nlu --cross-validation
rasa data validate # catch domain/data mismatches
| Test type | Checks |
|---|
| NLU tests | Accuratezza di intento/entità |
| Story tests | Percorsi di conversazione completi |
| Cross-validation | Generalizzazione di NLU |
Channels & Deployment
| Channel | Note |
|---|
| REST | Endpoint HTTP predefinito |
| Web widget | Chat incorporabile |
| Slack / Teams / Telegram | Connettori integrati |
| Voice | Via integrazioni telefoniche |
| Deployment | Docker, Kubernetes/Helm, self-hosted |
Rasa vs LLM-Only Chatbots
| Aspect | Rasa | Prompt-only LLM bot |
|---|
| Control | Flussi/logica di business espliciti | Emergente, difficile da vincolare |
| Predictability | Alto | Variabile |
| Compliance | Percorsi verificabili | Difficile |
| Hosting | Completamente self-hosted | Di solito dipendente da API |
| Best for | Assistenti regolati e task-oriented | Conversazione aperta |
Per agenti aperti vedi LangGraph o Mastra; la forza di Rasa è i flussi di task deterministici e verificabili.
Resources