Skip to main content

SingleStepLLMCommandGenerator

The SingleStepLLMCommandGenerator is deprecated and no longer recommended for use in Rasa 3.x. It will be removed in Rasa 4.0.0.
To interpret the user’s message in context, the current implementation of the SingleStepLLMCommandGenerator uses in-context learning, information about the current state of the conversation, and flows defined in your assistant. Descriptions and slot definitions of each flow are included in the prompt as relevant information. However, to scale to a large number of flows, the LLM-based command generator includes only the flows that are relevant to the current state of the conversation, see flow retrieval.

Prompt Template

The default prompt template serves as a dynamic framework enabling the SingleStepLLMCommandGenerator to render prompts. The template consists of a static component, as well as dynamic components that get filled in when rendering a prompt:
  • Current state of the conversation - This part of the template captures the ongoing dialogue.
  • Defined flows and slots - This part of the template provides the context and structure for the conversation. It outlines the overarching theme, guiding the model’s understanding of the conversation’s purpose.
  • Active flow and slot - Active elements within the conversation that require the model’s attention.
The prompt template for the SingleStepLLMCommandGenerator is as follows:

Customization

You can customize the SingleStepLLMCommandGenerator as much as you wish. General customization options that are available for both LLMCommandGenerators are listed in the section General Customizations.
Customizing the Prompt Template
If you cannot get something to work via editing the flow and slot descriptions (see section customizing the prompt), you can go one level deeper and customise the prompt template used to drive the SingleStepLLMCommandGenerator. To do this, write your own prompt as a jinja2 template and provide it to the component as a file:
config.yml
Deprecation WarningThe former LLMCommandGenerator’s prompt configuration is replaced by SingleStepLLMCommandGenerator’s prompt_template in version 3.9.0. The prompt configuration variable is now deprecated and will be removed in version 4.0.0.
The prompt template also allows the utilization of variables to incorporate dynamic information. You can access the comprehensive list of available variables here to use in your custom prompt template.
  • Iterating over the flow_slots variable can be useful to create a prompt that lists all the slots of the current active flow,
  • Iterating over the available_flows variable can be useful to create a prompt that lists all the flows,

MultiStepLLMCommandGenerator

The MultiStepLLMCommandGenerator is deprecated and no longer recommended for use in Rasa 3.x. It will be removed in Rasa 4.0.0.
The MultiStepLLMCommandGenerator also uses in-context learning to interpret the user’s message in context, but breaks down the task into several steps to make the job of the LLM easier. The component was designed to enable cheaper and smaller LLMs, such as gpt-3.5-turbo, as viable alternatives to costlier but more powerful models such as gpt-4-0613. The steps are:
  • handling the flows (starting, ending, etc.) and
  • filling out the slots
Accordingly, instead of just a single prompt that handles everything, the MultiStepLLMCommandGenerator has two prompts:
  • handle_flows and
  • fill_slots.
The following diagram shows which prompt is used when: Prompt selection flow for the MultiStepLLMCommandGenerator If no flow is currently active, the handle_flows prompt is used to start or clarify flows. If a flow is started, next the fill_slots prompt is executed to fill any slots of the newly started flow. If a flow is currently active, the fill_slots prompt is called to fill any new slots of the currently active flow. If the user message (also) indicates that, for example, a new flow should be started or the active flow should be canceled, a ChangeFlow command is triggered. This results in calling the handle_flows prompt to start, cancel, or clarify flows. If that prompt leads to starting a flow, the fill_slots prompt is executed again to fill any slots of that new flow.

Prompt Templates

The default prompt templates serve as a dynamic framework enabling the MultiStepLLMCommandGenerator to render prompts. The templates consists of a static component, as well as dynamic components that get filled in when rendering a prompt.
  • Current state of the conversation: This part of the template captures the ongoing dialogue.
  • Defined flows: This part of the template provides the context and structure for the conversation. It outlines the overarching theme, guiding the model’s understanding of the conversation’s purpose.
  • Active flow: Displays the name of the current active flow (if any). Used within conditional statements to customize the message about the flow’s status.

Customization

You can customize the MultiStepLLMCommandGenerator as much as you wish. General customization options that are available for both LLMCommandGenerators are listed in the section General Customizations.
Customizing The Prompt Template
If you cannot get something to work via editing your flow and slot descriptions (see section customizing the prompt), you can go one level deeper and customise the prompt templates used to drive the MultiStepLLMCommandGenerator. To do this, write your own prompt as a jinja2 template and provide it to the component as a file:
config.yml
You can customize both prompts using the example configuration above, or you can choose to customize only a specific prompt. The prompt template also allows the utilization of variables to incorporate dynamic information.
handle_flows
Here is a comprehensive list of available variables to use in your custom handle_flows prompt template:
  • Iterating over the available_flows variable can be useful to create a prompt that lists all the flows,
By default following commands can be predicted in this step: StartFlow, Clarify, CancelFlow, CannotHandle.
fill_slots
Here is a comprehensive list of available variables to use in your custom fill_slots prompt template:
  • Iterating over the flow_slots or the top_user_flow_slots variable can be useful to create a prompt that lists all the slots of the current active flow (can be a pattern) or the top user flow,
  • Iterating over the available_flows variable can be useful to create a prompt that lists all the flows,
By default only SetSlot commands can be predicted in this step.
Prompt Tuning
Apart from the prompt customization proposed in the section on Customizing The Prompt, the MultiStepLLMCommandGenerator might benefit from some additional prompt tuning.
Few-shot learning
Few-shot learning is a machine learning approach in which an AI model learns to make accurate predictions by being trained on a very small number of labeled examples. Our internal experiments showed that adding some examples of user message to command pairs to the prompt template handle_flows helped to improve the performance of the LLM, especially for the Clarify command. To do so, curate a small list of user message - action list pairs of examples that are specific to the domain of your assistant. Next, you can add them to the prompt template handle_flows after line 22. Here is an example:
Language of the prompt
In our internal experiments, we have found that smaller LLMs benefit from having the complete prompt in a single language. Hence, if your assistant is built to understand and respond to a user in a language other than English and the flows descriptions as well as the collect step descriptions are in that same language, the LLM might benefit from translating the prompt template to that language as well. For example, assume users are talking in German to your assistant and the flow descriptions and collect step descriptions are also in German. To simplify the job of the LLM it might help to translate the complete prompt template to German as well. You can use strong LLMs, such as gpt-4-0613, for translating. However, we recommend to manually check the prompt templates after translating it automatically.
Formatting
In both prompt templates, handle_flows and fill_slots, we iterate over the flows and/or the slots. Depending on the descriptions you wrote for those, it might make sense to update the for loop in the prompt templates. For example, if your slot descriptions are rather long and contain a list of bullet points, the slot list in the final prompt might look like this:
As you see it is quite hard to distinguish between the description and the actual slots. To help the LLM to clearly distinguish between the slot and the description, we recommend to update the for loop in the jinja2 prompt template as follows:
This results in the following:

Current Limitations

The MultiStepLLMCommandGenerator will be able to generate the following commands:
  • in handle_flows step: StartFlow, Clarify, CancelFlow, CannotHandle.
  • in fill_slots step: SetSlot. The CannotHandle command will be triggered from the handle_flows prompt when the scope of the user message is beyond starting, canceling, or clarifying a flow. The command will trigger the cannot handle pattern to indicate that the user message can not be treated as expected.