Skip to main content

Skill Processing

ai_skills interprets the structured skill data the AI returns and turns it into device behavior — showing an emotion, playing music or a story, handling playback control, and reacting to cloud events. The AI Agent delivers the skill data; this module decides what the device does with it.

How skills arrive

A skill is structured JSON the cloud sends alongside the conversation. The AI Agent hands every text payload to ai_text_process, which dispatches it by type:

OPERATE_RET ai_text_process(AI_TEXT_TYPE_E type, cJSON *root, bool eof);
ParameterMeaning
typeThe payload type: AI_TEXT_ASR, AI_TEXT_NLG, AI_TEXT_SKILL, or AI_TEXT_CLOUD_EVENT.
rootThe JSON payload.
eoftrue when this is the last chunk of the payload.

Returns OPERATE_RET (OPRT_OK on success). When type is AI_TEXT_SKILL, the module parses the skill JSON and routes it to the matching skill family below; AI_TEXT_CLOUD_EVENT goes to the cloud-event handler.

Skill families

The module ships three skill families. Each has its own header and entry function.

FamilyHeaderKey functionsDoes
Emotionskill_emotion.hai_skill_emo_process, ai_agent_play_emo, ai_emoji_unicode_to_utf8Show an emotion on the display.
Music / storyskill_music_story.hai_skill_parse_music, ai_skill_parse_playcontrol, ai_skill_playcontrol_musicPlay music or a story and handle playback control.
Cloud eventskill_cloudevent.hai_parse_cloud_eventReact to a cloud-pushed event.

Emotion

The emotion skill maps an emotion name (HAPPY, SAD, THINKING, SLEEP, and more — defined as EMOJI_* macros in skill_emotion.h) to an expression on the display. An emotion is described by an AI_AGENT_EMO_T:

typedef struct {
const char *emoji; // emoji code point, e.g. "U+1F636"
const char *name; // emotion name, e.g. "NEUTRAL"
} AI_AGENT_EMO_T;
FunctionParametersPurpose
ai_skill_emo_processjson — emotion skill JSONParse an emotion skill payload and play it.
ai_agent_play_emoemo — pointer to the emotionShow one emotion on the display.
ai_emoji_unicode_to_utf8unicode_str"U+XXXX"; utf8_buf — output (≥ 5 bytes); buf_size — buffer sizeConvert a Unicode code point to UTF-8 bytes. Returns the byte count, or -1 on error.

ai_skill_emo_process and ai_agent_play_emo return OPERATE_RET.

Music and story

The music/story skill parses what to play and how to control playback, working over the player's AI_AUDIO_MUSIC_T. These functions are built only when ENABLE_COMP_AI_AUDIO is set; the Audio Player does the actual playback.

FunctionParametersPurpose
ai_skill_parse_musicjson; music — receives the parsed structureParse a music/story payload into an AI_AUDIO_MUSIC_T.
ai_skill_parse_music_freemusicFree a parsed music structure.
ai_skill_parse_music_dumpmusicPrint a music structure for debugging.
ai_skill_parse_playcontroljson; music — receives the parsed structureParse a playback-control payload (play, pause, next, and so on).
ai_skill_playcontrol_musicmusicExecute the parsed playback-control command.

ai_skill_parse_music and ai_skill_parse_playcontrol return OPERATE_RET; the others return void.

warning

Pair every ai_skill_parse_music or ai_skill_parse_playcontrol call with ai_skill_parse_music_free once you finish with the structure, or the device leaks the parsed payload.

Cloud event

The cloud-event skill handles events the cloud pushes outside the normal reply stream, such as a TTS playback command.

FunctionParametersPurpose
ai_parse_cloud_eventjson — cloud-event JSONParse and process a cloud event. Returns OPERATE_RET.

See also