126 lines
5.8 KiB
Go
126 lines
5.8 KiB
Go
package ctxmgr
|
|
|
|
import (
|
|
"time"
|
|
|
|
"chat-agent-system/internal/storage"
|
|
)
|
|
|
|
// CommunicationStyle 用户沟通风格
|
|
type CommunicationStyle string
|
|
|
|
const (
|
|
StyleConciseStructured CommunicationStyle = "concise_structured" // 结构精炼、结论先行、拒绝冗长
|
|
StyleDetailedAnalytical CommunicationStyle = "detailed_analytical" // 详尽论证、全面对比、深挖细节
|
|
StyleExecutiveSummary CommunicationStyle = "executive_summary" // 高管要点、商业决策导向
|
|
)
|
|
|
|
// UserPreference 用户工作习惯与产出偏好画像
|
|
type UserPreference struct {
|
|
UserID int64 `json:"user_id"`
|
|
AccountID string `json:"account_id"`
|
|
Name string `json:"name"`
|
|
Role string `json:"role"`
|
|
CommunicationStyle CommunicationStyle `json:"communication_style"`
|
|
FocusAreas []string `json:"focus_areas"` // 关注维度,如 "reg_compliance", "cost_budget", "timeline", "optical_quality"
|
|
OutputFormatPref string `json:"output_format_pref"` // 报告格式要求,如 "standard_report", "bilingual_brief", "ppt_bullets"
|
|
CustomInstructions string `json:"custom_instructions"` // 用户直接指定的定制要求
|
|
MemoryFacts map[string]string `json:"memory_facts"` // 异步蒸馏出的长期事实记忆 (如 "预算通常按千万级申报", "偏好使用迈瑞作为对标竞品")
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// ActivityItem 项目活动记录 (操作、决策、上传、下载)
|
|
type ActivityItem struct {
|
|
ID int64 `json:"id"`
|
|
ProjectID int64 `json:"project_id"`
|
|
UserID int64 `json:"user_id"`
|
|
UserName string `json:"user_name"`
|
|
ActivityType string `json:"activity_type"` // decision, operation, upload, download, stage_advance, chat
|
|
Title string `json:"title"`
|
|
Detail map[string]any `json:"detail,omitempty"`
|
|
RawWeight float64 `json:"raw_weight"` // 初始权重
|
|
DecayedWeight float64 `json:"decayed_weight"`// 时间衰减后当前有效权重
|
|
IsMilestone bool `json:"is_milestone"` // 里程碑事件不衰减
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// TimeDecayConfig 时间权重衰减配置
|
|
type TimeDecayConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
HalfLifeDays float64 `json:"half_life_days"` // 半衰期天数 (如 7.0 天)
|
|
MinWeightFloor float64 `json:"min_weight_floor"` // 权重衰减下限 (如 0.10,防止被完全抹除)
|
|
MilestoneExempt bool `json:"milestone_exempt"` // 里程碑事件是否豁免衰减 (默认 true)
|
|
}
|
|
|
|
// DefaultTimeDecayConfig 默认时间衰减配置
|
|
func DefaultTimeDecayConfig() TimeDecayConfig {
|
|
return TimeDecayConfig{
|
|
Enabled: true,
|
|
HalfLifeDays: 7.0,
|
|
MinWeightFloor: 0.15,
|
|
MilestoneExempt: true,
|
|
}
|
|
}
|
|
|
|
// SingleUserContext 单用户私有上下文
|
|
type SingleUserContext struct {
|
|
UserID int64 `json:"user_id"`
|
|
AccountID string `json:"account_id"`
|
|
Name string `json:"name"`
|
|
Role string `json:"role"`
|
|
Preference *UserPreference `json:"preference"`
|
|
SessionID string `json:"session_id"`
|
|
RecentChats []ChatMessageRecord `json:"recent_chats"`
|
|
MyActivities []ActivityItem `json:"my_activities"`
|
|
MyFiles []*storage.FileReference `json:"my_files"`
|
|
AssembledAt time.Time `json:"assembled_at"`
|
|
}
|
|
|
|
// ProjectCollectiveContext 项目级多方协同上下文
|
|
type ProjectCollectiveContext struct {
|
|
ProjectID int64 `json:"project_id"`
|
|
ProjectCode string `json:"project_code"`
|
|
ProjectName string `json:"project_name"`
|
|
CurrentStage string `json:"current_stage"`
|
|
BlackboardFacts map[string]string `json:"blackboard_facts"`
|
|
AllActivities []ActivityItem `json:"all_activities"`
|
|
MilestoneDecisions []ActivityItem `json:"milestone_decisions"`
|
|
SharedFiles []*storage.FileReference `json:"shared_files"`
|
|
ParticipatingUsers []UserSummary `json:"participating_users"`
|
|
AssembledAt time.Time `json:"assembled_at"`
|
|
}
|
|
|
|
// UserSummary 参与项目的用户摘要
|
|
type UserSummary struct {
|
|
UserID int64 `json:"user_id"`
|
|
Name string `json:"name"`
|
|
Role string `json:"role"`
|
|
}
|
|
|
|
// ChatMessageRecord 结构化会话消息
|
|
type ChatMessageRecord struct {
|
|
ID int64 `json:"id"`
|
|
SessionID string `json:"session_id"`
|
|
UserID int64 `json:"user_id"`
|
|
Role string `json:"role"`
|
|
Content string `json:"content"`
|
|
Intent string `json:"intent,omitempty"`
|
|
Branch string `json:"branch,omitempty"`
|
|
Metadata map[string]any `json:"metadata,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// BlendedSquadContext 智能体小队混合上下文 (用于注入到 Agent Prompt 中)
|
|
type BlendedSquadContext struct {
|
|
ProjectName string `json:"project_name"`
|
|
CurrentStage string `json:"current_stage"`
|
|
TaskKey string `json:"task_key"`
|
|
AgentRole string `json:"agent_role"`
|
|
BlackboardFacts map[string]string `json:"blackboard_facts"`
|
|
KeyDecisions []string `json:"key_decisions"`
|
|
RelevantFiles []string `json:"relevant_files"`
|
|
TriggerUserPreference *UserPreference `json:"trigger_user_preference,omitempty"`
|
|
PersonalizedGuidance string `json:"personalized_guidance"` // 针对当前用户偏好生成的注入指导语
|
|
AssembledAt time.Time `json:"assembled_at"`
|
|
}
|