Agent Manager
Component registry: espressif/brookesia_agent_manager
Helper header:
#include "brookesia/service_helper/agent/manager.hpp"Helper class:
esp_brookesia::service::helper::Manager
Overview
brookesia_agent_manager is the core agent framework:
Lifecycle: Plugin-based init, activate, start, stop, sleep, wake, and dynamic switching.
State machine: Correct, consistent transitions.
Control: Pause/resume, interrupt, status queries.
Dialog modes: RealTime and Manual (manual listen start/stop).
Events: Operations, state, speech/listen, text, emotes—decoupled from apps.
Extensions: Function calling, text, interrupt, emotes via agent properties.
AFE (optional): Wake begin/end handling.
Services: Audio service and Device time-sync integration.
Persistence: Optional brookesia_service_storage for active agent and mode.
State Machine Architecture
The manager uses a state machine for agent lifecycle.
State Diagram
flowchart TD
A["**TimeSyncing**<br/>· Waits for time sync<br/>· Can be skipped by config"]
B["**Ready**<br/>· Base environment is ready<br/>· Waits for activation"]
C["**Activating**<br/>· Initializes plugin resources<br/>· Prepares agent context"]
D["**Activated**<br/>· Plugin is activated<br/>· Session can start"]
E["**Starting**<br/>· Starts session flow<br/>· Opens required services"]
F["**Started**<br/>· Agent is running<br/>· Handles interactions"]
G["**Sleeping**<br/>· Enters sleep flow<br/>· Pauses active interaction"]
H["**Slept**<br/>· Agent is sleeping<br/>· Waits for wake or stop"]
I["**WakingUp**<br/>· Restores session resources<br/>· Returns to running state"]
J["**Stopping**<br/>· Stops session<br/>· Releases runtime resources"]
A -->|"time synced / skipped"| B
B -->|"Activate"| C
C -->|"activated"| D
D -->|"Start"| E
E -->|"started"| F
F -->|"Sleep"| G
G -->|"slept"| H
H -->|"Wake"| I
I -->|"woke"| F
F -->|"Stop"| J
H -->|"Stop"| J
J -->|"stopped"| D
State Descriptions
State |
Type |
Description |
|---|---|---|
TimeSyncing |
Transient |
Waiting for time sync. |
Ready |
Stable |
Time OK (or skipped); waiting for activate. |
Activating |
Transient |
Activating agent. |
Activated |
Stable |
Activated; waiting for start. |
Starting |
Transient |
Starting agent. |
Started |
Stable |
Running; audio in/out enabled. |
Sleeping |
Transient |
Entering sleep. |
Slept |
Stable |
Asleep; can wake or stop. |
WakingUp |
Transient |
Waking from sleep. |
Stopping |
Transient |
Stopping agent. |
Standard Include / Helper Class
Standard include:
#include \"brookesia/service_helper/agent/manager.hpp\"Helper class:
esp_brookesia::service::helper::Manager
Service Interfaces
Functions
SetAgentInfo
Description
Set agent info.
Execution
Requires scheduler: Not required
Parameters
NameType:
StringRequired: required
Description: Agent name.
InfoType:
ObjectRequired: required
Description: Agent info as a JSON object. Example: {"api_key":"api_key_value","model":"model_name"}
Schema JSON
Show raw JSON
{
"name": "SetAgentInfo",
"description": "Set agent info.",
"require_scheduler": false,
"default_timeout_ms": null,
"parameters": [
{
"name": "Name",
"description": "Agent name.",
"type": "String",
"required": true,
"default_value": null
},
{
"name": "Info",
"description": "Agent info as a JSON object. Example: {\"api_key\":\"api_key_value\",\"model\":\"model_name\"}",
"type": "Object",
"required": true,
"default_value": null
}
],
"return_value": null
}
CLI Command
svc_call AgentManager SetAgentInfo {"Name":null,"Info":null}
SetChatMode
Description
Set chat mode.
Execution
Requires scheduler: Required
Parameters
ModeType:
StringRequired: required
Description: Chat mode. Allowed values: [Manual, RealTime]
Schema JSON
Show raw JSON
{
"name": "SetChatMode",
"description": "Set chat mode.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [
{
"name": "Mode",
"description": "Chat mode. Allowed values: [Manual, RealTime]",
"type": "String",
"required": true,
"default_value": null
}
],
"return_value": null
}
CLI Command
svc_call AgentManager SetChatMode {"Mode":null}
SetTargetAgent
Description
Set target agent. The agent will be activated by triggering Activate action.
Execution
Requires scheduler: Required
Parameters
NameType:
StringRequired: required
Description: Agent name to set as target.
Schema JSON
Show raw JSON
{
"name": "SetTargetAgent",
"description": "Set target agent. The agent will be activated by triggering `Activate` action.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [
{
"name": "Name",
"description": "Agent name to set as target.",
"type": "String",
"required": true,
"default_value": null
}
],
"return_value": null
}
CLI Command
svc_call AgentManager SetTargetAgent {"Name":null}
GetTargetAgent
Description
Get target agent name.
Execution
Requires scheduler: Required
Parameters
No parameters.
Return Value
Type:
StringDescription: Example: "Coze"
Schema JSON
Show raw JSON
{
"name": "GetTargetAgent",
"description": "Get target agent name.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": {
"type": "String",
"description": "Example: \"Coze\""
}
}
CLI Command
svc_call AgentManager GetTargetAgent
GetAgentNames
Description
Get agent names.
Execution
Requires scheduler: Required
Parameters
No parameters.
Return Value
Type:
ArrayDescription: Example: ["Agent1", "Agent2"]
Schema JSON
Show raw JSON
{
"name": "GetAgentNames",
"description": "Get agent names.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": {
"type": "Array",
"description": "Example: [\"Agent1\", \"Agent2\"]"
}
}
CLI Command
svc_call AgentManager GetAgentNames
GetAgentAttributes
Description
Get agent attributes.
Execution
Requires scheduler: Not required
Parameters
NameType:
StringRequired: optional
Default:
""Description: Agent name (optional). Returns all agents when omitted.
Return Value
Type:
ArrayDescription: Example: [{"name":"Agent","operation_timeout":{"activate":1000,"start":1000,"sleep":1000,"wake_up":1000,"stop":1000},"support_general_functions":[],"support_general_events":[],"require_time_sync":false}]
Schema JSON
Show raw JSON
{
"name": "GetAgentAttributes",
"description": "Get agent attributes.",
"require_scheduler": false,
"default_timeout_ms": null,
"parameters": [
{
"name": "Name",
"description": "Agent name (optional). Returns all agents when omitted.",
"type": "String",
"required": false,
"default_value": ""
}
],
"return_value": {
"type": "Array",
"description": "Example: [{\"name\":\"Agent\",\"operation_timeout\":{\"activate\":1000,\"start\":1000,\"sleep\":1000,\"wake_up\":1000,\"stop\":1000},\"support_general_functions\":[],\"support_general_events\":[],\"require_time_sync\":false}]"
}
}
CLI Command
svc_call AgentManager GetAgentAttributes {"Name":null}
GetChatMode
Description
Get chat mode.
Execution
Requires scheduler: Required
Parameters
No parameters.
Return Value
Type:
StringDescription: Allowed values: [Manual, RealTime]. Example: "Manual"
Schema JSON
Show raw JSON
{
"name": "GetChatMode",
"description": "Get chat mode.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": {
"type": "String",
"description": "Allowed values: [Manual, RealTime]. Example: \"Manual\""
}
}
CLI Command
svc_call AgentManager GetChatMode
GetActiveAgent
Description
Get active agent name.
Execution
Requires scheduler: Required
Parameters
No parameters.
Return Value
Type:
StringDescription: Example: "Coze"
Schema JSON
Show raw JSON
{
"name": "GetActiveAgent",
"description": "Get active agent name.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": {
"type": "String",
"description": "Example: \"Coze\""
}
}
CLI Command
svc_call AgentManager GetActiveAgent
TriggerGeneralAction
Description
Trigger a general action.
Execution
Requires scheduler: Required
Parameters
ActionType:
StringRequired: required
Description: General action. Allowed values: [TimeSync, Activate, Start, Stop, Sleep, WakeUp]
Schema JSON
Show raw JSON
{
"name": "TriggerGeneralAction",
"description": "Trigger a general action.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [
{
"name": "Action",
"description": "General action. Allowed values: [TimeSync, Activate, Start, Stop, Sleep, WakeUp]",
"type": "String",
"required": true,
"default_value": null
}
],
"return_value": null
}
CLI Command
svc_call AgentManager TriggerGeneralAction {"Action":null}
Suspend
Description
Suspend the agent.
Execution
Requires scheduler: Required
Parameters
No parameters.
Schema JSON
Show raw JSON
{
"name": "Suspend",
"description": "Suspend the agent.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": null
}
CLI Command
svc_call AgentManager Suspend
Resume
Description
Resume the agent.
Execution
Requires scheduler: Required
Parameters
No parameters.
Schema JSON
Show raw JSON
{
"name": "Resume",
"description": "Resume the agent.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": null
}
CLI Command
svc_call AgentManager Resume
InterruptSpeaking
Description
Interrupt speaking; the agent stops and keeps listening.
Execution
Requires scheduler: Required
Parameters
No parameters.
Schema JSON
Show raw JSON
{
"name": "InterruptSpeaking",
"description": "Interrupt speaking; the agent stops and keeps listening.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": null
}
CLI Command
svc_call AgentManager InterruptSpeaking
ManualStartListening
Description
Manually start listening. Only in Manual mode.
Execution
Requires scheduler: Required
Parameters
No parameters.
Schema JSON
Show raw JSON
{
"name": "ManualStartListening",
"description": "Manually start listening. Only in `Manual` mode.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": null
}
CLI Command
svc_call AgentManager ManualStartListening
ManualStopListening
Description
Manually stop listening. Only in Manual mode.
Execution
Requires scheduler: Required
Parameters
No parameters.
Schema JSON
Show raw JSON
{
"name": "ManualStopListening",
"description": "Manually stop listening. Only in `Manual` mode.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": null
}
CLI Command
svc_call AgentManager ManualStopListening
GetGeneralState
Description
Get general state.
Execution
Requires scheduler: Required
Parameters
No parameters.
Return Value
Type:
StringDescription: Allowed values: [TimeSyncing, Ready, Activating, Activated, Starting, Stopping, Started, Sleeping, WakingUp, Slept]. Example: "Started"
Schema JSON
Show raw JSON
{
"name": "GetGeneralState",
"description": "Get general state.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": {
"type": "String",
"description": "Allowed values: [TimeSyncing, Ready, Activating, Activated, Starting, Stopping, Started, Sleeping, WakingUp, Slept]. Example: \"Started\""
}
}
CLI Command
svc_call AgentManager GetGeneralState
GetSuspendStatus
Description
Get suspend status.
Execution
Requires scheduler: Required
Parameters
No parameters.
Return Value
Type:
BooleanDescription: Example: false
Schema JSON
Show raw JSON
{
"name": "GetSuspendStatus",
"description": "Get suspend status.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": {
"type": "Boolean",
"description": "Example: false"
}
}
CLI Command
svc_call AgentManager GetSuspendStatus
GetSpeakingStatus
Description
Get speaking status.
Execution
Requires scheduler: Required
Parameters
No parameters.
Return Value
Type:
BooleanDescription: Example: true
Schema JSON
Show raw JSON
{
"name": "GetSpeakingStatus",
"description": "Get speaking status.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": {
"type": "Boolean",
"description": "Example: true"
}
}
CLI Command
svc_call AgentManager GetSpeakingStatus
GetListeningStatus
Description
Get listening status.
Execution
Requires scheduler: Required
Parameters
No parameters.
Return Value
Type:
BooleanDescription: Example: true
Schema JSON
Show raw JSON
{
"name": "GetListeningStatus",
"description": "Get listening status.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": {
"type": "Boolean",
"description": "Example: true"
}
}
CLI Command
svc_call AgentManager GetListeningStatus
LoadData
Description
Load persisted manager data.
Execution
Requires scheduler: Required
Parameters
No parameters.
Schema JSON
Show raw JSON
{
"name": "LoadData",
"description": "Load persisted manager data.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": null
}
CLI Command
svc_call AgentManager LoadData
ResetData
Description
Reset manager and agent data.
Execution
Requires scheduler: Required
Parameters
No parameters.
Schema JSON
Show raw JSON
{
"name": "ResetData",
"description": "Reset manager and agent data.",
"require_scheduler": true,
"default_timeout_ms": null,
"parameters": [],
"return_value": null
}
CLI Command
svc_call AgentManager ResetData
Events
GeneralActionTriggered
Description
Emitted when a general action is triggered.
Execution
Requires scheduler: Required
Items
ActionType:
StringDescription: General action. Allowed values: [TimeSync, Activate, Start, Stop, Sleep, WakeUp]
Schema JSON
Show raw JSON
{
"name": "GeneralActionTriggered",
"description": "Emitted when a general action is triggered.",
"require_scheduler": true,
"items": [
{
"name": "Action",
"description": "General action. Allowed values: [TimeSync, Activate, Start, Stop, Sleep, WakeUp]",
"type": "String"
}
]
}
CLI Command
svc_subscribe AgentManager GeneralActionTriggered
GeneralEventHappened
Description
Emitted when a general event occurs.
Execution
Requires scheduler: Required
Items
EventType:
StringDescription: General event. Allowed values: [TimeSynced, Activated, Started, Stopped, Slept, Awake]
IsUnexpectedType:
BooleanDescription: Whether the event was unexpected.
Schema JSON
Show raw JSON
{
"name": "GeneralEventHappened",
"description": "Emitted when a general event occurs.",
"require_scheduler": true,
"items": [
{
"name": "Event",
"description": "General event. Allowed values: [TimeSynced, Activated, Started, Stopped, Slept, Awake]",
"type": "String"
},
{
"name": "IsUnexpected",
"description": "Whether the event was unexpected.",
"type": "Boolean"
}
]
}
CLI Command
svc_subscribe AgentManager GeneralEventHappened
SuspendStatusChanged
Description
Emitted when suspend status changes.
Execution
Requires scheduler: Required
Items
IsSuspendedType:
BooleanDescription: Whether the agent is suspended.
Schema JSON
Show raw JSON
{
"name": "SuspendStatusChanged",
"description": "Emitted when suspend status changes.",
"require_scheduler": true,
"items": [
{
"name": "IsSuspended",
"description": "Whether the agent is suspended.",
"type": "Boolean"
}
]
}
CLI Command
svc_subscribe AgentManager SuspendStatusChanged
SpeakingStatusChanged
Description
Emitted when speaking status changes.
Execution
Requires scheduler: Required
Items
IsSpeakingType:
BooleanDescription: Whether the agent is speaking.
Schema JSON
Show raw JSON
{
"name": "SpeakingStatusChanged",
"description": "Emitted when speaking status changes.",
"require_scheduler": true,
"items": [
{
"name": "IsSpeaking",
"description": "Whether the agent is speaking.",
"type": "Boolean"
}
]
}
CLI Command
svc_subscribe AgentManager SpeakingStatusChanged
ListeningStatusChanged
Description
Emitted when listening status changes.
Execution
Requires scheduler: Required
Items
IsListeningType:
BooleanDescription: Whether the agent is listening.
Schema JSON
Show raw JSON
{
"name": "ListeningStatusChanged",
"description": "Emitted when listening status changes.",
"require_scheduler": true,
"items": [
{
"name": "IsListening",
"description": "Whether the agent is listening.",
"type": "Boolean"
}
]
}
CLI Command
svc_subscribe AgentManager ListeningStatusChanged
AgentSpeakingTextGot
Description
Emitted when the agent speaks text.
Execution
Requires scheduler: Required
Items
TextType:
StringDescription: Spoken text.
Schema JSON
Show raw JSON
{
"name": "AgentSpeakingTextGot",
"description": "Emitted when the agent speaks text.",
"require_scheduler": true,
"items": [
{
"name": "Text",
"description": "Spoken text.",
"type": "String"
}
]
}
CLI Command
svc_subscribe AgentManager AgentSpeakingTextGot
UserSpeakingTextGot
Description
Emitted when the user speaks text.
Execution
Requires scheduler: Required
Items
TextType:
StringDescription: User text.
Schema JSON
Show raw JSON
{
"name": "UserSpeakingTextGot",
"description": "Emitted when the user speaks text.",
"require_scheduler": true,
"items": [
{
"name": "Text",
"description": "User text.",
"type": "String"
}
]
}
CLI Command
svc_subscribe AgentManager UserSpeakingTextGot
EmoteGot
Description
Emitted when the agent shows an emote.
Execution
Requires scheduler: Required
Items
EmoteType:
StringDescription: Emote name.
Schema JSON
Show raw JSON
{
"name": "EmoteGot",
"description": "Emitted when the agent shows an emote.",
"require_scheduler": true,
"items": [
{
"name": "Emote",
"description": "Emote name.",
"type": "String"
}
]
}
CLI Command
svc_subscribe AgentManager EmoteGot
API Reference
Agent Base Class
Public header: #include "brookesia/agent_manager/base.hpp"
Header File
Classes
-
class Base : public esp_brookesia::service::ServiceBase
Common base class for all agent implementations.
The class extends
service::ServiceBasewith agent lifecycle hooks, audio pipeline coordination, and shared state tracked byManagerandStateMachine.Subclassed by esp_brookesia::agent::Coze, esp_brookesia::agent::Openai, esp_brookesia::agent::XiaoZhi
Public Functions
-
inline const AgentAttributes &get_attributes() const
Get immutable metadata describing the agent.
- Returns
const AgentAttributes& Agent attributes passed at construction time.
-
inline const AudioConfig &get_audio_config() const
Get the audio configuration used by the agent.
- Returns
const AudioConfig& Current encoder and decoder configuration.
-
inline const AgentAttributes &get_attributes() const
Agent Manager
Public header: #include "brookesia/agent_manager/manager.hpp"