You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rasa框架非示例名称槽位无法填充及规则失效问题咨询

Rasa新手问题解决指南

核心问题

  • 仅当用户输入nlu.yml示例中存在的姓名时,name槽位才能正常填充;输入非示例姓名则槽位为空(响应显示none),即便添加20+示例仍无法解决。
  • rules.yml配置的规则完全不生效,只有stories.yml里的故事流程能触发对应响应,没法通过规则实现单次问询的响应逻辑。

相关配置文件

rules.yml

# ask name confirmation
- rule: ask name confirmation
  steps:
  - intent: inform_name
  - action: utter_greet_with_name

# respond with name
- rule: respond with name
  steps:
  - action: utter_respond_with_name

# respond without name
- rule: respond without name
  condition:
  - slot_was_set:
      - name: null
  steps:
  - action: utter_respond_without_name

nlu.yml

- intent: inform_name
  examples: |
    - I'm [Sarah](name).
    - Hi, my name is [Chris](name).
    - You can call me [Alex](name).

stories.yml

stories:

- story: path 1
  steps:
  - intent: greet
  - action: utter_greet
  - intent: inform_name
  - action: utter_greet_with_name
  - intent: ask_name
  - action: utter_respond_with_name

- story: path 2
  steps:
  - intent: greet
  - action: utter_greet
  - intent: ask_name
  - action: utter_respond_without_name

domain.yml(部分)

entities:
  - name

# Define the 'name' slot with the 'from_text' mapping
slots:
  name:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: name

解决方案

问题1:非示例姓名无法填充槽位

问题出在当前用from_entity映射槽位,完全依赖Rasa的实体识别模型。但模型只能识别训练示例里出现过的姓名模式,没见过的姓名大概率识别不出来,导致槽位空值。

直接改槽位映射为from_text,限定仅在inform_name意图触发时提取文本内容作为姓名,这样不管用户输入什么姓名都能提取:

slots:
  name:
    type: text
    influence_conversation: true
    mappings:
      - type: from_text
        intent: inform_name
        not_intent:
          - greet
          - ask_name

如果想保留实体识别逻辑,也可以在nlu.yml里加正则表达式辅助提取姓名:

- regex: name
  examples: |
    - [A-Z][a-z]+

然后在domain.yml的实体配置中关联这个正则:

entities:
  - name:
      regex: name

不过from_text的方式更直接,适配任意姓名输入。

问题2:rules.yml规则不生效

主要原因有两个:要么是config.yml没启用RulePolicy,要么是规则写法不符合Rasa版本要求。

  1. 检查并修改config.yml,确保包含RulePolicy:
policies:
  - name: RulePolicy
    core_fallback_threshold: 0.3
    core_fallback_action_name: "action_default_fallback"
    enable_fallback_prediction: True
  - name: TEDPolicy
    max_history: 5
    epochs: 100
  1. 调整规则的触发条件,保证逻辑合理:
    • 第二个规则respond with name没有触发条件,会被模型忽略,要加上槽位和意图条件:
      - rule: respond with name
        condition:
          - slot_was_set:
              - name: "!None"
        steps:
          - intent: ask_name
          - action: utter_respond_with_name
      
    • 第三个规则里的name: null要改成Rasa识别的name: None:
      - rule: respond without name
        condition:
          - slot_was_set:
              - name: None
        steps:
          - intent: ask_name
          - action: utter_respond_without_name
      
  2. 最后重新运行rasa train,确保训练时加载了rules文件。

内容的提问来源于stack exchange,提问作者aimen alt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 19:42:50