Files
DESKTOP-72TV0V4\caoxiaozhu 31f0feafb5 feat: 增强会话管理和 Agent 服务
- 优化 session_handler 会话处理逻辑
- 增强 agent_service Agent 服务功能
- 新增 chat_repository 仓储方法
- 更新 agent_handler 和 chat_group_handler
- 更新数据模型 agent 和 chat_session

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 19:49:27 +08:00

132 lines
5.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import (
"time"
)
// SecurityLevel 安全等级
type SecurityLevel string
const (
SecurityLevelSafe SecurityLevel = "safe"
SecurityLevelReview SecurityLevel = "review"
SecurityLevelDanger SecurityLevel = "danger"
)
// Agent 智能体
type Agent struct {
ID string `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"size:100;not null"`
Description string `json:"description" gorm:"type:text"`
OwnerID string `json:"owner_id" gorm:"size:50;not null;index"`
Avatar string `json:"avatar" gorm:"size:50"` // 头像 (emoji)
// 技能列表(JSON数组)
Skills []string `json:"skills" gorm:"type:text;serializer:json"`
// 角色描述和模型配置
RoleDescription string `json:"role_description" gorm:"type:text"` // 角色描述 (System Prompt)
ModelProvider string `json:"model_provider" gorm:"size:50"` // 模型提供商: openai/anthropic
ModelName string `json:"model_name" gorm:"size:100"` // 模型名称
// 协作模式
IsSupervisor bool `json:"is_supervisor" gorm:"default:false"` // 是否为主智能体
// 状态
IsActive bool `json:"is_active" gorm:"default:true"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// AgentSkill 智能体-技能绑定
type AgentSkill struct {
ID string `json:"id" gorm:"primaryKey"`
AgentID string `json:"agent_id" gorm:"size:191;index"`
SkillID string `json:"skill_id" gorm:"size:191;index"`
SkillConfig string `json:"skill_config" gorm:"type:text"` // JSON 配置
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// AgentKnowledgeBase 智能体-知识库绑定
type AgentKnowledgeBase struct {
ID string `json:"id" gorm:"primaryKey"`
AgentID string `json:"agent_id" gorm:"size:191;index"`
KnowledgeBaseID string `json:"knowledge_base_id" gorm:"size:191;index"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// AgentMemory 长期记忆
type AgentMemory struct {
ID string `json:"id" gorm:"primaryKey"`
AgentID string `json:"agent_id" gorm:"size:191;index"`
UserID string `json:"user_id" gorm:"size:191;index"`
Content string `json:"content" gorm:"type:text"`
MemoryType string `json:"memory_type" gorm:"size:20"` // experience/preference/conversation/fact
Category string `json:"category" gorm:"size:50;index"` // 记忆分类
Tags string `json:"tags" gorm:"size:500"` // 标签JSON数组格式
Keywords string `json:"keywords" gorm:"size:500"` // 关键词,用于搜索
Importance int `json:"importance" gorm:"default:5;index"` // 重要性等级 1-10
IsPinned bool `json:"is_pinned" gorm:"default:false"` // 是否置顶
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (AgentMemory) TableName() string {
return "agent_memories"
}
// ImportItem 导入记忆项
type ImportItem struct {
Content string `json:"content"`
MemoryType string `json:"memory_type"`
Category string `json:"category"`
Tags string `json:"tags"`
Keywords string `json:"keywords"`
Importance int `json:"importance"`
}
// AgentTeam 多智能体协作配置
type AgentTeam struct {
ID string `json:"id" gorm:"primaryKey"`
SupervisorAgentID string `json:"supervisor_agent_id" gorm:"size:191;index"`
MemberAgentID string `json:"member_agent_id" gorm:"size:191;index"`
DispatchStrategy string `json:"dispatch_strategy" gorm:"size:20;default:'parallel'"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// AgentTask 任务记录
type AgentTask struct {
ID string `json:"id" gorm:"primaryKey"`
AgentID string `json:"agent_id" gorm:"size:191;index"`
UserID string `json:"user_id" gorm:"size:191;index"`
UserInput string `json:"user_input" gorm:"type:text"`
AgentResponse string `json:"agent_response" gorm:"type:text"`
Status string `json:"status" gorm:"size:20"` // pending/running/completed/failed
TokensUsed int `json:"tokens_used" gorm:"default:0"`
DurationMs int `json:"duration_ms"`
SessionID string `json:"session_id" gorm:"size:191;index"`
CreatedAt time.Time `json:"created_at"`
CompletedAt time.Time `json:"completed_at"`
}
// AgentRequest 聊天请求
type AgentRequest struct {
AgentID string `json:"agent_id" binding:"required"`
Message string `json:"message" binding:"required"`
SessionID string `json:"session_id"`
ModelID string `json:"model_id"`
Context map[string]interface{} `json:"context"`
}
// AgentResponse 聊天响应
type AgentResponse struct {
Reply string `json:"reply"`
SessionID string `json:"session_id"`
ToolsUsed []string `json:"tools_used"`
Metadata map[string]interface{} `json:"metadata"`
}