小智
辅助头文件:
#include "brookesia/service_helper/agent/xiaozhi.hpp"辅助类:
esp_brookesia::service::helper::XiaoZhi
概述
brookesia_agent_xiaozhi 是为 ESP-Brookesia 生态系统提供的小智 AI 智能体实现。
功能特性
小智平台集成:基于
esp_xiaozhiSDK 实现与小智 AI 平台的通信。实时语音交互:支持 OPUS 音频编解码,16kHz 采样率,24kbps 比特率。
丰富的事件支持:支持说话/监听状态变化、智能体/用户文本、表情等事件。
手动监听控制:支持手动开始/停止监听,适用于 Manual 对话模式。
中断说话:支持中断智能体说话功能。
统一生命周期管理:基于
brookesia_agent_manager框架的统一智能体生命周期管理。
服务接口
函数
AddMCP_ToolsWithServiceFunction
描述
Add MCP tools from service functions.
执行要求
是否需要调度器: 不需要
参数
ServiceName类型:
String是否必填: 必填
描述: Service name.
FunctionNames类型:
Array是否必填: 可选
默认值:
[]描述: Function names as JSON array<string>. Empty means all functions in the service. Example: ["SetAudioPlayerVolume","GetAudioPlayerVolume"]
返回值
类型:
Array描述: Added tool names. Example: ["Service.Device.SetAudioPlayerVolume","Service.Device.GetAudioPlayerVolume"]
Schema JSON
展开查看 JSON
{
"name": "AddMCP_ToolsWithServiceFunction",
"description": "Add MCP tools from service functions.",
"require_scheduler": false,
"default_timeout_ms": null,
"parameters": [
{
"name": "ServiceName",
"description": "Service name.",
"type": "String",
"required": true,
"default_value": null
},
{
"name": "FunctionNames",
"description": "Function names as JSON array<string>. Empty means all functions in the service. Example: [\"SetAudioPlayerVolume\",\"GetAudioPlayerVolume\"]",
"type": "Array",
"required": false,
"default_value": []
}
],
"return_value": {
"type": "Array",
"description": "Added tool names. Example: [\"Service.Device.SetAudioPlayerVolume\",\"Service.Device.GetAudioPlayerVolume\"]"
}
}
CLI 命令
svc_call XiaoZhi AddMCP_ToolsWithServiceFunction {"ServiceName":null,"FunctionNames":null}
AddMCP_ToolsWithCustomFunction
描述
Add custom MCP tools.
执行要求
是否需要调度器: 不需要
参数
Tools类型:
Array是否必填: 必填
描述: Tools to add as JSON array<object>. Example: [{"description":"custom tool description 1","name":"Display.GetBrightness"},{"description":"custom tool description 2","name":"Display.SetBrightness"}]
返回值
类型:
Array描述: Added tool names. Example: ["Custom.Display.GetBrightness","Custom.Display.SetBrightness"]
Schema JSON
展开查看 JSON
{
"name": "AddMCP_ToolsWithCustomFunction",
"description": "Add custom MCP tools.",
"require_scheduler": false,
"default_timeout_ms": null,
"parameters": [
{
"name": "Tools",
"description": "Tools to add as JSON array<object>. Example: [{\"description\":\"custom tool description 1\",\"name\":\"Display.GetBrightness\"},{\"description\":\"custom tool description 2\",\"name\":\"Display.SetBrightness\"}]",
"type": "Array",
"required": true,
"default_value": null
}
],
"return_value": {
"type": "Array",
"description": "Added tool names. Example: [\"Custom.Display.GetBrightness\",\"Custom.Display.SetBrightness\"]"
}
}
CLI 命令
svc_call XiaoZhi AddMCP_ToolsWithCustomFunction {"Tools":null}
RemoveMCP_Tools
描述
Remove MCP tools.
执行要求
是否需要调度器: 不需要
参数
Tools类型:
Array是否必填: 必填
描述: Tool names to remove. Example: ["Service.Device.SetAudioPlayerVolume","Custom.Display.GetBrightness"]
Schema JSON
展开查看 JSON
{
"name": "RemoveMCP_Tools",
"description": "Remove MCP tools.",
"require_scheduler": false,
"default_timeout_ms": null,
"parameters": [
{
"name": "Tools",
"description": "Tool names to remove. Example: [\"Service.Device.SetAudioPlayerVolume\",\"Custom.Display.GetBrightness\"]",
"type": "Array",
"required": true,
"default_value": null
}
],
"return_value": null
}
CLI 命令
svc_call XiaoZhi RemoveMCP_Tools {"Tools":null}
ExplainImage
描述
Explain an image.
执行要求
是否需要调度器: 需要
参数
Image类型:
RawBuffer是否必填: 必填
描述: Image data.
Question类型:
String是否必填: 可选
默认值:
"What is in the image?"描述: Question text.
返回值
类型:
String描述: Example: "This image contains a cup on a desk."
Schema JSON
展开查看 JSON
{
"name": "ExplainImage",
"description": "Explain an image.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [
{
"name": "Image",
"description": "Image data.",
"type": "RawBuffer",
"required": true,
"default_value": null
},
{
"name": "Question",
"description": "Question text.",
"type": "String",
"required": false,
"default_value": "What is in the image?"
}
],
"return_value": {
"type": "String",
"description": "Example: \"This image contains a cup on a desk.\""
}
}
CLI 命令
svc_call XiaoZhi ExplainImage {"Image":null,"Question":null}
事件
ActivationCodeReceived
描述
Emitted when an activation code is received.
执行要求
是否需要调度器: 需要
参数
Code类型:
String描述: Activation code.
Schema JSON
展开查看 JSON
{
"name": "ActivationCodeReceived",
"description": "Emitted when an activation code is received.",
"require_scheduler": true,
"items": [
{
"name": "Code",
"description": "Activation code.",
"type": "String"
}
]
}
CLI 命令
svc_subscribe XiaoZhi ActivationCodeReceived