From f80ed0b7fec368eb87db743c6e688391d2d75725 Mon Sep 17 00:00:00 2001 From: Autumn-27 <53844290+Autumn-27@users.noreply.github.com> Date: Sat, 8 Aug 2026 12:40:26 -0400 Subject: [PATCH] =?UTF-8?q?feat(worker):=20=E6=84=8F=E5=9B=BE=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E8=B5=84=E4=BA=A7=E5=8E=9F=E5=A7=8B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=20+=20=E8=A6=86=E7=9B=96=E5=BA=A6=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E5=96=82=E7=BB=99=20worker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Execute 启动指令后附上意图 asset_ids 对应资产的原始 JSON(GetByIDs), 省去 worker 开场再查一次 list_assets;查不到/为空/无 store 则不加 - 新增 intentAssetIDs 从意图 payload 解析 asset_ids - renderWorkerGraphOverview 删除 coverage 键:覆盖度是规划者信号, 与 worker「只做领到那条意图」的边界相悖,不再进 worker 提示词 Co-Authored-By: Claude Opus 4.8 --- agent/worker.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/agent/worker.go b/agent/worker.go index 2370ce7..8e37699 100644 --- a/agent/worker.go +++ b/agent/worker.go @@ -170,6 +170,22 @@ func workerSystem(proxyAddr, workDir string) string { // renderIntentTask formats the claimed intent for the worker's SYSTEM prompt: the // intent is the worker's whole job, so — like the planner's situational block — it // belongs in system, where compaction can never drop it during a long run. +// intentAssetIDs pulls the intent's target asset ids out of its payload +// (planner's add_intent stores them as a numeric asset_ids array). nil on absence +// or malformed payload. +func intentAssetIDs(intent *db.Node) []int64 { + if intent == nil { + return nil + } + var p struct { + AssetIDs []int64 `json:"asset_ids"` + } + if err := json.Unmarshal(intent.Payload, &p); err != nil { + return nil + } + return p.AssetIDs +} + func renderIntentTask(intent *db.Node) string { return fmt.Sprintf("\n\n【你领到的意图(本次唯一任务:只做这一条、只产生事实、做完即停)】:\n%s\n意图 id: %d(写回 record_fact / report_finding 时传它)", string(intent.Payload), intent.ID) } @@ -180,6 +196,10 @@ func renderIntentTask(intent *db.Node) string { // purpose is letting the worker read context (existing facts/assets/hints) // so it avoids redundant work and doesn't re-derive what others already found. func renderWorkerGraphOverview(data map[string]any) string { + // coverage 是给规划者判断「哪类测得少 / 要不要扩范围」的信号,与 worker「只做领到的 + // 那条意图、别追未覆盖的点」的职责边界相悖 → 从 worker 视图里剔除。data 是本次 worker + // 专属的新 map,删键不影响 planner。 + delete(data, "coverage") b, err := json.Marshal(data) if err != nil { return "" // fall back silently: the worker just won't have the global context @@ -278,8 +298,18 @@ func (w *Worker) Execute(ctx context.Context, name string, taskID int64, as *db. emit(r) } } - // 意图已在 system 里。user 输入只放启动指令。 + // 意图已在 system 里。user 输入只放启动指令 + 意图锚定资产的原始数据(供 worker 直接 + // 用,省去开场再查一次 list_assets)。原始 JSON 直接附上,不做提取/格式化。 input := "开始执行 system 提示里的这条意图:只做它、只产生事实、做完即停。" + if as != nil { + if ids := intentAssetIDs(intent); len(ids) > 0 { + if assets, err := as.GetByIDs(ids); err == nil && len(assets) > 0 { + if b, err := json.Marshal(assets); err == nil { + input += "\n\n本意图 asset_ids 对应的目标资产:\n" + string(b) + } + } + } + } s := agentcore.NewSession(opts) defer s.Close() // release the session's background-task manager (temp dir + processes)