feat: Agent 任务名与对话标题双能力自动生成

新增 task_auto_title_enabled / chat_auto_title_enabled(默认关)、
共享 GenerateAutoTitle、spawn_task 同步写 name、对话首条先截断再异步 AI,
设置页「自动标题」双 Switch。closes #55
This commit is contained in:
artex-bot committed 2026-10-27 12:33:53 +08:00
1 parent e740334b90
commit 6c781f21f4
11 files changed
+310 -1

No files matched your search

+16 -1
View File
@@ -251,7 +251,7 @@ func (s *Server) toolSpawnTask() actool.CoreTool {
"plan_heartbeat_seconds": map[string]any{"type": "integer", "description": "可选:planner 心跳触发间隔(秒)。距上轮规划结束/任务开始满该值且期间无触发 → 触发一轮规划(兜底死锁 + 唤醒去监督飞行中的 worker)。留空或 0 = 默认 600(10min);"},
"seed_first_intent": map[string]any{"type": "boolean", "description": "可选:对于简单任务可开启,创建时直接下发一条种子意图(内容=描述+目标)让 worker 免等首轮 planner 直接开跑测试;默认 false(走标准先规划再执行)。"},
}, "description", "goal"),
func(_ context.Context, in json.RawMessage) (actool.Result, error) {
func(ctx context.Context, in json.RawMessage) (actool.Result, error) {
var a struct {
Description string `json:"description"`
Goal string `json:"goal"`
@@ -305,7 +305,22 @@ func (s *Server) toolSpawnTask() actool.CoreTool {
if pin != nil {
llmIDs = []int64{*pin}
}
name := ""
if s.m.pg.GetBool(db.SettingTaskAutoTitle, false) {
if active, activeErr := s.m.pg.ActiveProfile(); activeErr == nil && active != nil {
if prov, _, providerOK := s.providerForProfile(active.ID); providerOK {
if generated, titleErr := agent.GenerateAutoTitle(ctx, prov, a.Description+"\n"+a.Goal); titleErr == nil {
name = generated
} else {
log.Printf("[auto-title] task %s: %v", a.Description, titleErr)
}
} else {
log.Printf("[auto-title] task provider unavailable for active profile %d", active.ID)
}
}
}
t, err := s.m.CreateTaskWithOptions(a.Description, a.Goal, db.TaskCreateOptions{
Name: name,
SourceTaskIDs: sourceIDs,
LLMProfileIDs: llmIDs,
TimeoutSeconds: a.TimeoutSeconds,