设计 — 后端改动

Section 2/4:Go 后端 — 标签解析 + 事件发射

改动范围

文件 改动
agent.go emotionPromptSuffixbehaviorPromptSuffix ~5 行
emotion.go EmotionParserBehaviorParser,支持解析 action 字段 ~40 行
app_chat.go emit chat:behavior 替代 chat:emotion ~10 行

system prompt 改动

旧:
在每条回复的第一行必须输出情绪标签,格式严格为 [情绪:emotion/intensity],其中 emotion ∈ {joy, sad, surprised, angry, neutral},intensity ∈ [0.0, 1.0]
新:
在每条回复的第一行必须输出行为标签,格式严格为 [表现:emotion/intensity] 或 [表现:emotion/intensity,动作:action],其中 emotion ∈ {joy, sad, surprised, angry, neutral},intensity ∈ [0.0, 1.0],action ∈ {wave, nod, celebrate, surprised_react, sad_pose, angry_pose} 为可选项

BehaviorParser 改动

// 新正则
行为标签Re = `^\[表现:(\w+)/([\d.]+)(?:,动作:(\w+))?\]\n?`

// Feed() 返回值
func (p *BehaviorParser) Feed(tok string) (
  text string, // 正文(剔除标签后)
  emotion string, // joy/sad/surprised/angry/neutral
  intensity float64, // 0.0-1.0
  action string, // wave/nod/celebrate/... 或空字符串
)

// buffer 上限从 30 字节提到 80 字节(容纳 action 字段)

事件协议

// 旧:chat:emotion(保留兼容,Live2D 暂时还用)
emit "chat:emotion", {emotion, intensity}

// 新:chat:behavior(VRM 使用)
emit "chat:behavior", {emotion, intensity, action}
// action 为空字符串时即纯情绪,非空时前端播一次性手势