小智
辅助头文件:
#include "brookesia/agent_helper/xiaozhi.hpp"辅助类:
esp_brookesia::agent::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. Return type: JSON array<string> of added tool names. Example: [“Service.Audio.SetVolume”,”Service.Audio.GetVolume”]
执行要求
是否需要调度器: 不需要
参数
ServiceName类型:
String是否必填: 必填
描述: Service name.
FunctionNames类型:
Array是否必填: 可选
默认值:
[]描述: Function names as JSON array<string>. Empty means all functions in the service. Example: [“SetVolume”,”GetVolume”]
Schema JSON
展开查看 JSON
{
"name": "AddMCP_ToolsWithServiceFunction",
"description": "Add MCP tools from service functions. Return type: JSON array<string> of added tool names. Example: [\"Service.Audio.SetVolume\",\"Service.Audio.GetVolume\"]",
"require_scheduler": false,
"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: [\"SetVolume\",\"GetVolume\"]",
"type": "Array",
"required": false,
"default_value": []
}
]
}
CLI 命令
svc_call AgentXiaoZhi AddMCP_ToolsWithServiceFunction {"ServiceName":null,"FunctionNames":null}
AddMCP_ToolsWithCustomFunction
描述
Add custom MCP tools. Return type: JSON array<string> of added tool names. Example: [“Custom.Display.GetBrightness”,”Custom.Display.SetBrightness”]
执行要求
是否需要调度器: 不需要
参数
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”}]
Schema JSON
展开查看 JSON
{
"name": "AddMCP_ToolsWithCustomFunction",
"description": "Add custom MCP tools. Return type: JSON array<string> of added tool names. Example: [\"Custom.Display.GetBrightness\",\"Custom.Display.SetBrightness\"]",
"require_scheduler": false,
"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
}
]
}
CLI 命令
svc_call AgentXiaoZhi AddMCP_ToolsWithCustomFunction {"Tools":null}
RemoveMCP_Tools
描述
Remove MCP tools.
执行要求
是否需要调度器: 不需要
参数
Tools类型:
Array是否必填: 必填
描述: Tool names to remove. Example: [“Service.Audio.SetVolume”,”Custom.Display.GetBrightness”]
Schema JSON
展开查看 JSON
{
"name": "RemoveMCP_Tools",
"description": "Remove MCP tools.",
"require_scheduler": false,
"parameters": [
{
"name": "Tools",
"description": "Tool names to remove. Example: [\"Service.Audio.SetVolume\",\"Custom.Display.GetBrightness\"]",
"type": "Array",
"required": true,
"default_value": null
}
]
}
CLI 命令
svc_call AgentXiaoZhi RemoveMCP_Tools {"Tools":null}
ExplainImage
描述
Explain an image. Return type: string. Example: “This image contains a cup on a desk.”
执行要求
是否需要调度器: 需要
参数
Image类型:
RawBuffer是否必填: 必填
描述: Image data.
Question类型:
String是否必填: 可选
默认值:
"What is in the image?"描述: Question text.
Schema JSON
展开查看 JSON
{
"name": "ExplainImage",
"description": "Explain an image. Return type: string. Example: \"This image contains a cup on a desk.\"",
"require_scheduler": true,
"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?"
}
]
}
CLI 命令
svc_call AgentXiaoZhi 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 AgentXiaoZhi ActivationCodeReceived