feat: set_goals 升级为受管领域工具(可 web 管理,默认绑 goals+mainagent)+ 主 agent 加目标复活任务
- set_goals 从目标拆解器内联提交工具,改为入 tools 目录的领域工具:直接写 goal 节点、 连任务根(RelSpawns)、notify 唤醒 planner;支持单条/批量;origin 按来源区分 (拆解器=goals、主 agent 运行时=human)。新 key 走 SeedTool 首插入,旧库无需迁移。 - 默认绑定 goals + mainagent:目录 seed 新增 goals 项并入 order,MainAgentTools 纳入; DecomposeGoals 统一改用同一受管工具直接落库,createGoals 只保留无产出兜底。 - 主 agent 通过 set_goals 新增目标时,把终态(done/failed/timeout)/暂停的任务拉回 running 继续跑:新增 ToolSet.resumeTask 回调(仅 mainagent 接线),经 resumeTaskForGoal 置 running + engine.Run(幂等/重启后重起循环)+ 解除暂停。拆解器/worker 不触发。 - mainagent 提示词补充 set_goals 用法。
This commit is contained in:
1 parent
1029c4a84c
commit
2ac176b96a
7 files changed
+184
-45
No files matched your search
+28
-27
@@ -72,43 +72,30 @@ type GoalSpec struct {
|
||||
//
|
||||
// as + taskID, when non-nil/positive, wire the add_task_scope tool so the
|
||||
// decomposer can register the explicit asset scope it extracts from the goal.
|
||||
func DecomposeGoals(ctx context.Context, c Config, dataDir, goalText, desc string, as *db.AssetStore, taskID int64, emit func(db.Activity)) []GoalSpec {
|
||||
//
|
||||
// ts is the task's exploration store: set_goals writes the decomposed goal nodes
|
||||
// straight into it (the same managed tool the main agent uses to add goals at
|
||||
// runtime). The returned specs are read back from the store so callers can emit
|
||||
// per-goal activity and detect the "LLM produced nothing" case for their fallback.
|
||||
func DecomposeGoals(ctx context.Context, c Config, dataDir, goalText, desc string, as *db.AssetStore, ts *db.ExplorationStore, taskID int64, emit func(db.Activity)) []GoalSpec {
|
||||
prov, err := c.NewProvider()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var out struct {
|
||||
Goals []GoalSpec `json:"goals"`
|
||||
}
|
||||
captured := false
|
||||
submitTool := actool.Build(actool.Spec{
|
||||
Name: "set_goals",
|
||||
Description: "提交拆分后的目标列表。",
|
||||
Schema: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"goals": map[string]any{"type": "array", "items": map[string]any{
|
||||
"type": "object", "properties": map[string]any{
|
||||
"text": map[string]any{"type": "string", "description": "一个独立可验证的目标"},
|
||||
"vulnclass": map[string]any{"type": "string", "description": "对应漏洞类(若明确),如 SQLi/IDOR;业务逻辑目标可留空"},
|
||||
}, "required": []string{"text"},
|
||||
}},
|
||||
}, "required": []string{"goals"}},
|
||||
Permissions: func(context.Context, json.RawMessage, acperm.Context) acperm.Decision { return acperm.Allowed() },
|
||||
Run: func(_ context.Context, in json.RawMessage, _ *actool.ToolContext) (actool.Result, error) {
|
||||
_ = json.Unmarshal(in, &out)
|
||||
captured = true
|
||||
return actool.Text("ok"), nil
|
||||
},
|
||||
})
|
||||
// worker="goals" tags the goal nodes' provenance; ts/taskID let set_goals link
|
||||
// each goal under the task root. This is the catalog's real set_goals tool, so a
|
||||
// web-edited description/schema on it applies here too.
|
||||
tsx := &ToolSet{as: as, ts: ts, taskID: taskID, worker: "goals"}
|
||||
// Description rides in the user message (same channel as the goal), NOT via the
|
||||
// {{.EngagementDescription}} template var — else a prompt that references the var
|
||||
// would inject the description twice. System prompt stays pure static instructions.
|
||||
sys := renderSystem("goals", goalsDefaultTmpl, GoalsVars{DataDir: dataDir, Now: nowStr()})
|
||||
tools := []actool.CoreTool{submitTool}
|
||||
tools := []actool.CoreTool{tsx.setGoals()}
|
||||
// Wire add_task_scope only when we have a real asset store + task to write to.
|
||||
// The scope-extraction tail is appended in lockstep so the prompt never asks for
|
||||
// a tool that isn't present.
|
||||
if as != nil && taskID > 0 {
|
||||
tools = append(tools, (&ToolSet{as: as, taskID: taskID}).addTaskScope())
|
||||
tools = append(tools, tsx.addTaskScope())
|
||||
sys += goalsScopeTail
|
||||
}
|
||||
userMsg := "任务目标:\n" + goalText
|
||||
@@ -131,8 +118,22 @@ func DecomposeGoals(ctx context.Context, c Config, dataDir, goalText, desc strin
|
||||
DisableBackgroundTasks: true,
|
||||
MaxTurns: 6,
|
||||
}, userMsg, captureEmit)
|
||||
if !captured {
|
||||
// set_goals persisted the goals directly; read them back so the caller sees what
|
||||
// was written (empty slice ⇒ the LLM produced nothing ⇒ caller falls back).
|
||||
if ts == nil {
|
||||
return nil
|
||||
}
|
||||
return out.Goals
|
||||
nodes, _ := ts.ListByKind(db.KindGoal, 10000)
|
||||
var out []GoalSpec
|
||||
for _, n := range nodes {
|
||||
var p struct {
|
||||
Text string `json:"text"`
|
||||
VulnClass string `json:"vulnclass"`
|
||||
}
|
||||
_ = json.Unmarshal(n.Payload, &p)
|
||||
if strings.TrimSpace(p.Text) != "" {
|
||||
out = append(out, GoalSpec{Text: p.Text, VulnClass: p.VulnClass})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in new issue
Block a user