目录

Rules

Writing a Rule#

Rules for the Conversation Start#

Rules with Conditions#

Skip Waiting for User Input at the End of a Rule#

Rules and Forms#


Rules

规则是一种训练数据,用于训练助手的对话管理模型。规则描述的是应该始终遵循相同路径的简短对话。

不要过度使用规则。规则非常适合处理小型的特定对话模式,但与故事不同的是,规则没有能力概括出看不见的对话路径。将规则和故事结合起来,使您的助手健壮并能够处理真实的用户行为。

如果您不能决定是编写故事还是编写规则来实现特定的行为,请参阅编写对话数据的最佳实践。

有关在Rasa助手中实现规则的其他示例,请参阅我们的规则示例bot。

Writing a Rule#

Before you start writing rules, you have to make sure that the Rule Policy is added to your model configuration:

policies:
- ... # Other policies
- name: RulePolicy

Rules can then be added to the rules section of your training data.

To indicate that a rule can apply at any point in a conversation, start with the intent which starts the conversation and then add the actions which your assistant should perform in response to that.

rules:

- rule: Say `hello` whenever the user sends a message with intent `greet`
  steps:
  - intent: greet
  - action: utter_greet

This example rule applies at the start of conversation as well as when the user decides to a send a message with an intent greet in the middle of an ongoing conversation.

Rules for the Conversation Start#

要写一条只在对话开始时使用的规则,在你的规则后面加上aconversation_start: true:

rules:

- rule: Say `hello` when the user starts a conversation with intent `greet`
  conversation_start: true
  steps:
  - intent: greet
  - action: utter_greet

如果用户在稍后的对话中发送带有greet意图的消息,则规则将不匹配。

Rules with Conditions#

Conditions describe requirements which have to be fulfilled for a rule to be applicable. To do so, add any information about the prior conversation under the condition key:

rules:

- rule: Only say `hello` if the user provided a name
  condition:
  - slot_was_set:
    - user_provided_name: true
  steps:
  - intent: greet
  - action: utter_greet

Possible information that you can include under condition includes slot_was_set events and active_loop events.

Skip Waiting for User Input at the End of a Rule#

By default, rules will wait for the next user message when finished with the last step:

rules:

- rule: Rule which will wait for user message when it was applied
  steps:
  - intent: greet
  - action: utter_greet
  # - action: action_listen
  # Every rule implicitly includes a prediction for `action_listen` as last step.
  # This means that Rasa Open Source will wait for the next user message.

If you want to hand over the next action prediction to another story or rule, add wait_for_user_input: false to your rule:

rules:

- rule: Rule which will not wait for user message once it was applied
  steps:
  - intent: greet
  - action: utter_greet
  wait_for_user_input: false

This indicates that the assistant should execute another action before waiting for more user input.

Rules and Forms#

When a Form is active, the bot will make predictions based on how the form is defined, ignoring rules. Rules become applicable again if:

  • the form fills all required slots
  • the form rejects its execution (see Handling Unhappy Paths for more details)

更多推荐

Rasa原文--Rules