Command Generator | Rasa Documentation

Build your first agent in just a few minutes with Rasa Copilot.

At the heart of CALM’s dialogue understanding is a component called the Command Generator.

Whenever a new user message arrives, this component takes the entire conversation context—such as active flows on the dialogue stack, previously filled slots, relevant patterns, and the user’s conversation history—and generates a list of high-level commands.

Commands can:

By framing user intent as commands rather than single-label “intents,” you can handle more complex scenarios—like when a user answers a question and requests a new flow simultaneously.

Tip
For more details on all command generator types, advanced configurations, and usage examples, see the LLM Command Generators reference.

What Is the CompactLLMCommandGenerator?

The CompactLLMCommandGenerator is the simplest LLM-based approach for converting user messages into commands. It operates on a single prompt that encapsulates:

  1. Conversation History: The full or partial conversation so far, including user and assistant messages.
  2. Active Flow and Slots: Which flow is currently on top of the dialogue stack and which slot (if any) is currently being asked for.
  3. Relevant Flows: A subset of the flows in your assistant that are likely relevant to the user’s request (handled automatically by CALM’s flow retrieval mechanism).
  4. Patterns / Repairs: Predefined flows or patterns that can “interrupt” if the user changes their mind, wants to cancel, or triggers some other conversation repair scenario.

This single in-context prompt is passed to the underlying LLM (e.g., GPT-5.1) whenever the assistant needs to interpret the user’s latest message. The LLM’s response is turned into a list of commands, which the system executes in a single step.

Flow Retrieval

By default, CALM does not include all possible flows in the LLM prompt. Instead, it matches the incoming user message to each flow and includes only the top matching flows in the prompt. This keeps the prompt size manageable (and your costs lower). If you do want to disable or tweak flow retrieval, or always include certain flows, you can adjust that in your assistant configuration. For more details, see the Flow Retrieval reference.

Customizing the Prompt Template

One of the main benefits of an LLM-based approach is in-context learning—that is, the ability to guide the model through instructions and context in the prompt. By default, the CompactLLMCommandGenerator uses a built-in prompt template that dynamically assembles relevant flows, the current conversation, and other context. However, you can override and customize this template to further tailor the model’s behavior.

When Should You Customize?

  1. Flow Descriptions Aren’t Enough
    Usually, you can steer the LLM by enriching your flows with clear, unambiguous descriptions and step-by-step instructions. But if you find the model still isn’t producing the commands you expect, or if you have domain-specific language the model often confuses, you may want to go further and rewrite the template.

  2. You Want Specific Formatting or Additional Examples
    Suppose you need to show the LLM a set of few-shot examples or domain-specific instructions that can’t be captured solely in the flow/slot descriptions. A custom prompt template gives you full control over how that context appears.

How to Customize

  1. Create a Jinja2 Template
    You’ll provide a custom .jinja2 file that contains the static text you want plus references to dynamic variables (like {{ current_flow }}, {{ flow_slots }}, etc.).

  2. Reference That File in Your config.yml
    Under CompactLLMCommandGenerator, set the prompt_template property:

pipeline:
  - name: CompactLLMCommandGenerator
    prompt_template: prompts/my_custom_generator.jinja2
  1. Leverage Available Variables
    In your Jinja2 file, you have access to multiple variables, such as:
Variable Description
current_conversation A readable transcript of the conversation so far.
user_message The latest user message.
available_flows A list of all flows potentially relevant to this conversation.
current_flow The name of the currently active flow.
flow_slots The slots associated with the current flow (name, value, etc.).

You can iterate over lists to print out details about flows or slots. For example:

{% for flow in available_flows %}
{{ flow.name }}: {{ flow.description }}
{% endfor %}
  1. Make Your Template Clear and Consistent
    • If your slot descriptions are long or bullet-pointed, consider adjusting how you render them. Use numbered lists or add separators so the LLM easily distinguishes the slot’s name from its instructions.
    • Keep the entire prompt in one language if your assistant is multilingual or works in a language other than English. Smaller LLMs often do better if the entire prompt is consistently in a single language.

Reference: Find the complete list of variables and more advanced ways to structure your prompt in the Reference section on the command generator.

Important Note on Customizing the Command Set

For more technical details on configuration parameters, advanced prompt tuning, or combining multiple Command Generators, head over to the Command Generators reference.

While CALM’s Command Generator is designed to be flexible, the Rasa team actively tests and maintains a fixed set of built-in commands (e.g., StartFlowCommand, CancelFlowCommand, SetSlotCommand, etc.) to ensure the highest level of performance and accuracy. If you override or replace these built-in commands:

How to customize existing commands

If a use case still requires customization of commands, then here is the recommended way:

  1. Override an existing command class
    Identify the existing command you want to change. Define a new Python class inheriting from the corresponding command class. Override the following methods:

All custom commands must inherit from the Command abstract class and adhere to the PromptCommand protocol.

For example, to customize the name of the HumanHandoffCommand class used in your prompt, create the following:

from __future__ import annotations

import re
from dataclasses import dataclass
from typing import Any, Dict

from rasa.dialogue_understanding.commands import HumanHandoffCommand

dataclass
class CustomHumanHandoffCommand(HumanHandoffCommand):
    """A custom human handoff command."""

# Optionally you can define the command arguments
    new_command_arg: str

@classmethod
    def command(cls) -> str:
        """Returns the command type."""
        return "custom human handoff"

@classmethod
    def from_dict(cls, data: Dict[str, Any]) -> CustomHumanHandoffCommand:
        """Converts the dictionary to a command.

Returns:
            The converted dictionary.
        """
        return CustomHumanHandoffCommand(
            new_command_arg=data["new_command_arg"]
        )

@classmethod
    def from_dsl(cls, match: re.Match, **kwargs: Any) -> CustomHumanHandoffCommand:
        ...

def to_dsl(self) -> str:
        ...

@staticmethod
    def regex_pattern() -> str:
        ...

def __eq__(self, other: object) -> bool:
        return isinstance(other, CustomHumanHandoffCommand)
  1. Override the existing command behavior
    If you also want to update the command behavior, override the run_command_on_tracker method within your class.
dataclass
class CustomHumanHandoffCommand(HumanHandoffCommand):
       ...
       def run_command_on_tracker(
           self,
           tracker: DialogueStateTracker,
           all_flows: FlowsList,
           original_tracker: DialogueStateTracker,
       ) -> List[Event]:
           ...
  1. Create custom command generator
    Create a custom command generator class by extending Rasa's default command generator. Override its parse_commands method as follows to handle your customized commands:
# Import the utility method under a different name  
from rasa.dialogue_understanding.generator.command_parser import (
       parse_commands as parse_commands_using_command_parsers,
)

# Define logger
structlogger = structlog.get_logger()

class CustomCommandGenerator(CompactLLMCommandGenerator):
       ...
  1. Update the prompt template
    Create the custom prompt template that uses your new command name explicitly.

  2. Update the config.yml to utilize the custom command generator and the new prompt template

pipeline:
  - name: path.to.custom_command_generator.CustomCommandGenerator
    prompt_template: path/to/custom_prompt_template.jinja2