You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
6.6 KiB
105 lines
6.6 KiB
package comm
|
|
|
|
// yunyan 自管 Agent 配置数据模型(表 TableAgentConfig,存 console 共享库 postgres)。
|
|
//
|
|
// 与 svcpool.go 的 ThirdSvcConfig 同一模式:console 后台读写(modules/console 用 type alias 引用),
|
|
// 业务服务(home 的 user 模块)运行时直读、下发客户端。
|
|
// agent 在 console 编排已配置的第三方服务(ThirdSvcConfig),配置最终「下发客户端」,由客户端调
|
|
// 各服务完成对话/翻译等能力。
|
|
//
|
|
// 类型与其引用的服务(均引用 ThirdSvcConfig.Id):
|
|
// chat 对话: SttSvcId + LlmSvcId + TtsSvcId
|
|
// sts-chat 端到端对话: StsSvcId
|
|
// translate 三段式翻译: SttSvcId + MtSvcId + TtsSvcId
|
|
// ast-translate 端到端翻译: AstSvcId
|
|
//
|
|
// 两类用途、两条下发链路,别混:
|
|
// 对话类(chat / sts-chat) = 「对话对象」,由 user_getagents_v3 下发成客户端的 agent 列表。
|
|
// 翻译类(translate / ast-translate) = 通话翻译的服务编排载体,本身不进 agent 列表,
|
|
// 只被通话翻译规则(CallTranslateRule.AgentId)按语言选路引用。
|
|
// 翻译类一度下线过(翻译只留规则、不留 agent),但规则里「命中后走哪套 asr/mt/tts」仍得有地方配,
|
|
// 于是恢复:规则负责选路,翻译 agent 负责编排。
|
|
|
|
// Agent 类型取值(与前端一致)。
|
|
const (
|
|
AgentTypeChat = "chat"
|
|
AgentTypeStsChat = "sts-chat"
|
|
AgentTypeTranslate = "translate"
|
|
AgentTypeAstTranslate = "ast-translate"
|
|
)
|
|
|
|
// AgentTypeSelectable 允许新建/保存的 agent 类型。
|
|
func AgentTypeSelectable(t string) bool {
|
|
return AgentTypeIsChat(t) || AgentTypeIsTranslate(t)
|
|
}
|
|
|
|
// AgentTypeIsChat 是否「对话对象」类:只有这类才下发进客户端的 agent 列表。
|
|
func AgentTypeIsChat(t string) bool {
|
|
return t == AgentTypeChat || t == AgentTypeStsChat
|
|
}
|
|
|
|
// AgentTypeIsTranslate 是否翻译类:只被通话翻译规则引用,不进 agent 列表。
|
|
func AgentTypeIsTranslate(t string) bool {
|
|
return t == AgentTypeTranslate || t == AgentTypeAstTranslate
|
|
}
|
|
|
|
// AgentVariable agent 的变量项:客户端在拼 system_prompt / 开场白时做占位替换,
|
|
// 形如 {{key}}。运营在后台维护「有哪些变量、默认值是什么」,具体取值由客户端按
|
|
// 运行时上下文(用户昵称、设备名等)填,没填就用 DefValue。
|
|
type AgentVariable struct {
|
|
Key string `json:"key"` // 变量名,占位符 {{key}}
|
|
Label string `json:"label"` // 展示名/用途说明
|
|
DefValue string `json:"def_value"` // 默认值(客户端没有对应上下文时用它)
|
|
Description string `json:"description"` // 备注
|
|
}
|
|
|
|
// AgentVoice 音色覆盖项(语言+性别 → 具体音色名,覆盖所引用 TTS 服务的默认音色)。
|
|
type AgentVoice struct {
|
|
Language string `json:"language"` // BCP-47,如 zh-CN
|
|
Gender int32 `json:"gender"` // 1 男 2 女(0 不限)
|
|
Voice string `json:"voice"` // provider 特定音色名,如 zh-CN-XiaoxiaoNeural
|
|
}
|
|
|
|
// AgentConfig console 自管的 agent 配置(表 agent_config,按应用分离)。一行 = 某应用作用域下一个可下发客户端的智能体。
|
|
// voice_map 借助 gorm serializer:json 存 jsonb 列;support_langs 逗号分隔 BCP-47(同第三方服务 languages 约定)。
|
|
//
|
|
// 按应用分离:AppName=”为全局默认、'X'为应用X覆盖;业务字符串 Id 改用代理主键 RowId + 唯一索引(app_name,id)。
|
|
// 引用的第三方服务(SttSvcId 等)在同一应用作用域内解析、无则回退全局。
|
|
type AgentConfig struct {
|
|
RowId uint64 `gorm:"primaryKey;autoIncrement;column:row_id" json:"row_id"`
|
|
AppName string `gorm:"column:app_name;size:64;uniqueIndex:uidx_agent_config,priority:1" json:"app_name"` // ''=全局默认
|
|
Id string `gorm:"column:id;size:64;uniqueIndex:uidx_agent_config,priority:2" json:"id"`
|
|
Name string `gorm:"column:name;size:64" json:"name"`
|
|
Type string `gorm:"column:type;size:32" json:"type"` // chat|translate|sts-chat|ast-translate
|
|
Description string `gorm:"column:description" json:"description"`
|
|
AvatarUrl string `gorm:"column:avatar_url" json:"avatar_url"`
|
|
Enable bool `gorm:"column:enable" json:"enable"`
|
|
// 服务编排:均引用 ThirdSvcConfig.Id,按 Type 用其中若干(见文件头映射)。
|
|
SttSvcId string `gorm:"column:stt_svc_id;size:64" json:"stt_svc_id"`
|
|
LlmSvcId string `gorm:"column:llm_svc_id;size:64" json:"llm_svc_id"`
|
|
TtsSvcId string `gorm:"column:tts_svc_id;size:64" json:"tts_svc_id"`
|
|
MtSvcId string `gorm:"column:mt_svc_id;size:64" json:"mt_svc_id"`
|
|
StsSvcId string `gorm:"column:sts_svc_id;size:64" json:"sts_svc_id"`
|
|
AstSvcId string `gorm:"column:ast_svc_id;size:64" json:"ast_svc_id"`
|
|
// 逻辑配置
|
|
SystemPrompt string `gorm:"column:system_prompt" json:"system_prompt"`
|
|
Gender int32 `gorm:"column:gender" json:"gender"` // 0 未定 1 男 2 女
|
|
GreetingEnabled bool `gorm:"column:greeting_enabled" json:"greeting_enabled"`
|
|
GreetingText string `gorm:"column:greeting_text" json:"greeting_text"`
|
|
SupportLangs string `gorm:"column:support_langs;size:255" json:"support_langs"` // 逗号分隔 BCP-47
|
|
DefaultLang string `gorm:"column:default_lang;size:32" json:"default_lang"`
|
|
VoiceMap []AgentVoice `gorm:"column:voice_map;type:jsonb;serializer:json" json:"voice_map"`
|
|
// McpSvcIds 绑定的 MCP 服务(引用 ThirdSvcConfig.Id,类别须含 SvcCatMCP)。
|
|
// 空=不给该 agent 挂工具。MCP 服务本身的 url/工具白名单在第三方服务配置里,这里只存引用。
|
|
McpSvcIds []string `gorm:"column:mcp_svc_ids;type:jsonb;serializer:json" json:"mcp_svc_ids"`
|
|
// McpTools 每个已绑定 MCP 服务「这个 agent 能用哪些工具」:key=MCP 服务 id,value=工具名列表。
|
|
// 缺 key 或列表为空 = 该服务的工具全放开(与服务侧 tools 白名单再取交集)。
|
|
// 一个 agent 挂多个 MCP 时,工具名会互相干扰(同名工具、用不上的工具挤占模型注意力),
|
|
// 所以按 agent 再收一次口,而不是只有服务级一份白名单。
|
|
McpTools map[string][]string `gorm:"column:mcp_tools;type:jsonb;serializer:json" json:"mcp_tools"`
|
|
// Variables 提示词/开场白里的变量占位({{key}}),见 AgentVariable。
|
|
Variables []AgentVariable `gorm:"column:variables;type:jsonb;serializer:json" json:"variables"`
|
|
Sort int32 `gorm:"column:sort" json:"sort"`
|
|
Createtime int64 `gorm:"column:createtime" json:"createtime"`
|
|
Updatetime int64 `gorm:"column:updatetime" json:"updatetime"`
|
|
}
|
|
|