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.
 
 
 
 
 
 

91 lines
5.9 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 / ast-translate)已下线:agent 只用来配「对话对象」,
// 翻译能力由通话翻译规则(CallTranslateRule)那套按语言选路,不再做成 agent。
// 两个常量保留,只为读得懂库里可能存在的历史行——新建/改存不再接受它们。
// Agent 类型取值(与前端一致)。
const (
AgentTypeChat = "chat"
AgentTypeStsChat = "sts-chat"
// 下面两个已下线,仅用于识别历史数据,勿用于新建。
AgentTypeTranslate = "translate"
AgentTypeAstTranslate = "ast-translate"
)
// AgentTypeSelectable 当前允许新建/保存的 agent 类型。
func AgentTypeSelectable(t string) bool {
return t == AgentTypeChat || t == AgentTypeStsChat
}
// 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"`
}