Skip to content
RasaGet a free license
Menu

tutorial

Chapter 5 of 10

Conditional instructions in Rasa skills

by Rod Rivera Published

Choose the flight-status instructions sent to the model for delayed, cancelled or on-time flights.

Goal

Choose different instructions for delayed, cancelled and on-time flights. Rasa includes only the matching text in the instructions sent to the model. This chooses between branches rather than prescribing a fixed sequence of steps.

Teach

Scoped instructions use if: markers in the skill body. When a categorical memory value is set, the runtime strips non-matching paragraphs from the prompt. The LLM cannot follow the wrong branch because that text is not in context.

An if: marker takes the same condition expression as requires from the previous chapter, so memory is namespaced the same way:

if: session.flight_status.flight_status == "delayed"
Tell them the delay in minutes and the gate if available.

if: session.flight_status.flight_status == "cancelled"
Apologize briefly and offer a booking change.

if: session.flight_status.flight_status == "on_time" or session.flight_status.flight_status == "boarding"
Confirm the status, scheduled time, and gate.

Two boundary rules to remember. An if: marker scopes only the paragraph immediately following it, up to the next blank line, and unmarked paragraphs stay always visible. There is no else: or elif: in prose — write a separate if: paragraph for each case, or reach for an ordered block when you need true if/else control flow.

Declare the categorical in memory.yml:

flight_status:
  type: categorical
  enum_values: [on_time, delayed, cancelled, boarding]
  llm_settable: true

Paste

Paste set: tutorial/snippets/step-04-scoped/

Replace skills/flight_status/ with the scoped version (includes the if: branches).

Train and try

make train
make inspect

Try booking HT12345 (delayed outbound) and HT67890 (cancelled return).

Verify: Delayed path mentions minutes and gate; cancelled path offers change or handoff.

Talking point

Frontmatter can stay the same as Chapter 4. Only the body annotations and memory enum change. Zero ordered blocks required for branching.

Next

Chapter 6 — Verbatim responses