Details (original message): Add dual-tier storage (embedded SQLite + optional PostgreSQL), tenant owner scoping, API key auth, versioned dual-dialect migrations, integrity hardening, and batched event persistence
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
// Package profiles 管理智能体画像(4.7):数据化、可导入导出;内置默认画像(T0 基线)。
|
|
package profiles
|
|
|
|
import (
|
|
core "agent-system-core"
|
|
"agent-system-backend/internal/store"
|
|
)
|
|
|
|
// OwnerDefault 与 store 保持一致的默认租户(内置画像共享,owner='')。
|
|
const OwnerDefault = store.OwnerDefault
|
|
|
|
const DefaultProfileID = "default"
|
|
|
|
func DefaultProfile() core.AgentProfile {
|
|
maxTools := 40
|
|
maxTurns := 16
|
|
return core.AgentProfile{
|
|
ID: DefaultProfileID,
|
|
Name: "通用助手",
|
|
Description: "内置默认画像:全部工具可用,HTTP 工具执行前确认(T0 基线)。",
|
|
Builtin: true,
|
|
Source: "builtin",
|
|
SystemPrompt: "你是一个通用智能体助手,运行在 Agent-System 中。回答准确、简洁;需要外部信息时优先使用可用工具;产出文档时写入工件。",
|
|
Model: core.ModelRoute{},
|
|
Tools: core.ToolPolicy{Allow: []string{"*"}, Confirm: []string{"http."}},
|
|
Context: core.ContextPolicy{MaxHistoryMessages: 40, MaxToolResultChars: 20000},
|
|
HITL: core.HITLPolicy{AskOnAmbiguity: true},
|
|
Budget: core.RunBudget{MaxToolCalls: &maxTools, MaxTurns: &maxTurns},
|
|
}
|
|
}
|
|
|
|
type Service struct{ st *store.Store }
|
|
|
|
func New(st *store.Store) *Service { return &Service{st: st} }
|
|
|
|
// EnsureDefault 幂等写入内置画像。
|
|
func (s *Service) EnsureDefault() error {
|
|
if _, err := s.st.GetProfile(OwnerDefault, DefaultProfileID); err == nil {
|
|
return nil
|
|
}
|
|
return s.st.SaveProfile(DefaultProfile())
|
|
}
|
|
|
|
func (s *Service) List(owner string) ([]core.AgentProfile, error) { return s.st.ListProfiles(owner) }
|
|
|
|
func (s *Service) Get(owner, id string) (core.AgentProfile, error) {
|
|
p, err := s.st.GetProfile(owner, id)
|
|
if err == nil {
|
|
return p, nil
|
|
}
|
|
// 空或未知画像回落默认(T0 行为基线)。
|
|
return DefaultProfile(), nil
|
|
}
|
|
|
|
func (s *Service) Save(owner string, p core.AgentProfile) error {
|
|
if p.ID == DefaultProfileID {
|
|
return errReadOnly("profiles: builtin profile is read-only; duplicate and modify")
|
|
}
|
|
if p.Tools.Allow == nil {
|
|
p.Tools.Allow = []string{"*"}
|
|
}
|
|
p.Owner = owner
|
|
return s.st.SaveProfile(p)
|
|
}
|
|
|
|
func (s *Service) Delete(owner, id string) error { return s.st.DeleteProfile(owner, id) }
|
|
|
|
type errReadOnly string
|
|
|
|
func (e errReadOnly) Error() string { return string(e) }
|