Files
Agent-System-Backend/internal/profiles/profiles.go
T
weichenandCursor cd74434b4f Stream tool progress and drop hard agent limits
Why: Tool calls stayed invisible until execution finished, and turn, tool, timeout, and output caps stopped long tasks early.
Evidence: go test ./internal/runtime/ ./internal/tools/ ./internal/prompts/ ./internal/squadadapter/ ./internal/runmgr/ ./internal/app/ ./internal/settings/
Impact: tool.call.delta and tool.output reach the client; default profile, subagents, and squad no longer cap turns or tool calls; exec timeout defaults to 600s with no hard ceiling. A profile or subagent maxTurns above 0 still applies.
Refs: feature/stream-display-overhaul
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-02 02:17:02 +00:00

80 lines
2.8 KiB
Go
Raw 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 profiles 管理智能体画像(4.7):数据化、可导入导出;内置默认画像(T0 基线)。
package profiles
import (
"reflect"
"agent-system-backend/internal/store"
core "agent-system-core"
)
// 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) }