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

Google Assistant SDK双自定义命令仅随机触发单个的技术问询

问题分析与解决方案

你遇到的核心问题是JSON文件存在重复的顶级键,这违反了JSON语法规范——同一层级下不允许出现重复键,解析器处理时通常只会保留最后出现的那组配置,这就是为什么两个命令只能随机触发一个的原因。

我们需要把重复的manifest、actions、types字段合并成单一合法结构,具体修正如下:

修正后的完整actions.json代码

{
  "manifest": {
    "displayName": "Test & Lane Controller",
    "invocationName": "test controller",
    "category": "PRODUCTIVITY"
  },
  "actions": [
    {
      "name": "com.example.actions.StartTest",
      "availability": {
        "deviceClasses": [
          {
            "assistantSdkDevice": {}
          }
        ]
      },
      "intent": {
        "name": "com.example.intents.StartTest",
        "parameters": [
          {
            "name": "testname",
            "type": "SchemaOrg_Number"
          }
        ],
        "trigger": {
          "queryPatterns": [
            "prepare test ($SchemaOrg_Number:testname)",
            "start test ($SchemaOrg_Number:testname)"
          ]
        }
      },
      "fulfillment": {
        "staticFulfillment": {
          "templatedResponse": {
            "items": [
              {
                "simpleResponse": {
                  "textToSpeech": "Preparing to start test $testname"
                }
              },
              {
                "deviceExecution": {
                  "command": "com.example.commands.StartTest",
                  "params": {
                    "testname": "$testname"
                  }
                }
              }
            ]
          }
        }
      }
    },
    {
      "name": "com.example.actions.SelectLane",
      "availability": {
        "deviceClasses": [
          {
            "assistantSdkDevice": {}
          }
        ]
      },
      "intent": {
        "name": "com.example.intents.SelectLane",
        "parameters": [
          {
            "name": "lanename",
            "type": "SchemaOrg_Number"
          }
        ],
        "trigger": {
          "queryPatterns": [
            "select lane ($SchemaOrg_Number:lanename)",
            "choose lane ($SchemaOrg_Number:lanename)"
          ]
        }
      },
      "fulfillment": {
        "staticFulfillment": {
          "templatedResponse": {
            "items": [
              {
                "simpleResponse": {
                  "textToSpeech": "Selected lane $lanename"
                }
              },
              {
                "deviceExecution": {
                  "command": "com.example.commands.SelectLane",
                  "params": {
                    "lanename": "$lanename"
                  }
                }
              }
            ]
          }
        }
      }
    }
  ],
  "types": [
    {
      "name": "$testname",
      "entities": [
        {
          "key": "5",
          "synonyms": [
            "Test5"
          ]
        }
      ]
    },
    {
      "name": "$lanename",
      "entities": [
        {
          "key": "5",
          "synonyms": [
            "Lane5"
          ]
        }
      ]
    }
  ]
}

关键修正点说明

  • 合并顶级字段:把原本重复的manifest、actions、types合并为单一顶级键,确保JSON结构合法。其中manifest设置了通用调用名(invocationName),用户可以通过"Hey Google, talk to test controller"触发你的自定义命令。
  • 分离Intent触发词:确保两个action的queryPatterns清晰区分,避免触发混淆。我额外添加了几个备选触发词,你可以根据需求调整。
  • 统一类型定义:把两个参数的类型定义合并到同一个types数组中,确保每个参数的实体映射都能被正确识别。

额外注意事项

  1. 验证JSON格式:可以用在线JSON校验工具检查修正后的文件是否存在语法错误。
  2. 重新部署配置:修改完成后,需要重新将配置部署到Google Assistant SDK对应的项目中,确保新配置生效。
  3. 测试触发逻辑:分别用"prepare test 5"和"select lane 5"(或对应的同义词)测试两个命令,确认都能正常触发对应的设备执行指令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 10:00:02