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

Vue对接Rasa自定义Action时JSON响应异常求助

问题定位与解决方案

核心问题是Action Server收到的请求缺失action字段,导致无法识别要执行的动作,进而触发前端的错误提示。以下是针对性排查步骤:

1. 检查中间Webhook转发的请求格式

Action Server要求请求体必须包含action字段,中间转发层可能在转发时丢失或篡改了这个字段:

  • 直接在转发层打印接收到的完整请求体,对比Rasa Core发送给Action Server的标准格式:
    {
      "next_action": "action_your_custom_action",
      "tracker": {...},
      "domain": {...}
    }
    
  • 确认转发层没有过滤掉next_action字段,且正确将其映射为Action Server期望的action字段(部分转发逻辑可能误改字段名)。

2. 检查Vue前端发送的消息格式

前端发送的payload不符合Rasa API要求时,会导致Rasa Core无法生成正确的Action调用请求:

  • 前端调用Rasa /webhooks/rest/webhook接口时,必须发送包含message和sender的JSON体:
    {
      "message": "你的问题",
      "sender": "user123"
    }
    
  • 确认前端没有添加多余字段或遗漏必要字段,避免Rasa Core处理异常。

3. 检查Rasa配置文件的Action端点设置

确认endpoints.yml里的action_endpoint配置正确,指向Action Server地址,路径无误:

action_endpoint:
  url: "http://localhost:5055/webhook"
  • 注意:Action Server默认接口是/webhook,如果转发层修改了路径,必须同步更新这里的配置。

4. 直接验证Action Server可用性

绕过前端和转发层,手动构造请求调用Action Server的/webhook接口:

curl -X POST http://localhost:5055/webhook \
  -H "Content-Type: application/json" \
  -d '{
    "action": "action_your_custom_action",
    "tracker": {"sender_id": "test", "slots": {}, "latest_message": {}},
    "domain": {"actions": ["action_your_custom_action"]}
  }'
  • 如果Action Server正常响应,说明问题出在前端或转发层;如果仍报错,检查自定义Action代码的name属性是否正确:
    class ActionYourCustomAction(Action):
        def name(self) -> Text:
            return "action_your_custom_action"  # 必须和domain.yml里的动作名完全一致
    

5. 检查中间转发层的请求头与跨域设置

若转发层未正确传递请求头(比如Content-Type: application/json),会导致Action Server无法解析请求体:

  • 确认转发层保留了原始请求头,尤其是Content-Type;
  • 若存在跨域配置,确保未拦截或修改请求体内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 18:01:01