Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements. Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate. Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable. Refs: Versioned dependencies U1/U3; feature/dependency-workspace
80 lines
2.8 KiB
Go
80 lines
2.8 KiB
Go
// Package profiles 管理智能体画像(4.7):数据化、可导入导出;内置默认画像(T0 基线)。
|
||
package profiles
|
||
|
||
import (
|
||
"reflect"
|
||
|
||
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/store"
|
||
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
|
||
)
|
||
|
||
// OwnerDefault 与 store 保持一致的默认租户(内置画像共享,owner=”)。
|
||
const OwnerDefault = store.OwnerDefault
|
||
|
||
const DefaultProfileID = "default"
|
||
|
||
// defaultSystemPrompt 默认画像不再携带常驻提示词:基座(身份/行为/谨慎/工具/风格)
|
||
// 与环境段由提示词库组装(prompts 库 base.*/env.*);文档任务输出要求已技能化
|
||
// (task.doc-minutes 等,按触发注入)。SystemPrompt 留空 = 完全走库。
|
||
const defaultSystemPrompt = ""
|
||
|
||
func DefaultProfile() core.AgentProfile {
|
||
return core.AgentProfile{
|
||
ID: DefaultProfileID,
|
||
Name: "通用助手",
|
||
Description: "内置默认画像:全部工具可用,HTTP 工具执行前确认(T0 基线)。",
|
||
Builtin: true,
|
||
Source: "builtin",
|
||
SystemPrompt: defaultSystemPrompt,
|
||
Model: core.ModelRoute{},
|
||
Tools: core.ToolPolicy{Allow: []string{"*"}, Confirm: []string{"http."}},
|
||
Context: core.ContextPolicy{MaxHistoryMessages: 40, MaxToolResultChars: 20000},
|
||
HITL: core.HITLPolicy{AskOnAmbiguity: true},
|
||
// 空预算 = 不限制轮次、工具调用数和输出 token。用户自建画像可以自行设上限。
|
||
Budget: core.RunBudget{},
|
||
}
|
||
}
|
||
|
||
type Service struct{ st *store.Store }
|
||
|
||
func New(st *store.Store) *Service { return &Service{st: st} }
|
||
|
||
// EnsureDefault 幂等写入内置画像;内置画像只读(Save 拒绝编辑),库中与内置定义
|
||
// 有差异的行只可能来自更早版本的内置定义,因此差异时升级为当前内置定义。
|
||
func (s *Service) EnsureDefault() error {
|
||
if cur, err := s.st.GetProfile(OwnerDefault, DefaultProfileID); err == nil {
|
||
if reflect.DeepEqual(cur, DefaultProfile()) {
|
||
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) }
|