Просмотр исходного кода

目标树:支持显式编排关闭父节点级联完成

为 GoalTree.complete 和 TraceStore.update_goal 增加 cascade_completion 参数,默认保持 legacy 自动级联语义。显式任务编排可以关闭父 Goal 自动完成,使 GoalTree 只承担 Task Ledger 的兼容投影。
SamLee 4 дней назад
Родитель
Сommit
77ad59ed23
3 измененных файлов с 25 добавлено и 6 удалено
  1. 9 2
      agent/agent/trace/goal_models.py
  2. 8 1
      agent/agent/trace/protocols.py
  3. 8 3
      agent/agent/trace/store.py

+ 9 - 2
agent/agent/trace/goal_models.py

@@ -322,7 +322,13 @@ class GoalTree:
         self.current_id = goal_id
         return goal
 
-    def complete(self, goal_id: str, summary: str, clear_focus: bool = True) -> Goal:
+    def complete(
+        self,
+        goal_id: str,
+        summary: str,
+        clear_focus: bool = True,
+        cascade_completion: bool = True,
+    ) -> Goal:
         """
         完成指定 Goal
 
@@ -330,6 +336,7 @@ class GoalTree:
             goal_id: 要完成的目标 ID
             summary: 完成总结
             clear_focus: 如果完成的是当前焦点,是否清除焦点(默认 True)
+            cascade_completion: 是否自动完成父 Goal;legacy 默认 True,显式编排传 False
         """
         goal = self.find(goal_id)
         if not goal:
@@ -348,7 +355,7 @@ class GoalTree:
                 self.current_id = None
 
         # 检查是否所有兄弟都完成了,如果是则自动完成父节点
-        if goal.parent_id:
+        if cascade_completion and goal.parent_id:
             siblings = self.get_children(goal.parent_id)
             all_completed = all(g.status == "completed" for g in siblings)
             if all_completed:

+ 8 - 1
agent/agent/trace/protocols.py

@@ -87,13 +87,20 @@ class TraceStore(Protocol):
         """
         ...
 
-    async def update_goal(self, trace_id: str, goal_id: str, **updates) -> None:
+    async def update_goal(
+        self,
+        trace_id: str,
+        goal_id: str,
+        cascade_completion: bool = True,
+        **updates,
+    ) -> None:
         """
         更新 Goal 字段
 
         Args:
             trace_id: Trace ID
             goal_id: Goal ID
+            cascade_completion: 是否自动级联完成父 Goal(legacy 默认开启)
             **updates: 要更新的字段(如 status, summary, self_stats, cumulative_stats)
         """
         ...

+ 8 - 3
agent/agent/trace/store.py

@@ -21,7 +21,6 @@ Sub-Trace 是完全独立的 Trace,有自己的目录:
 """
 
 import json
-import os
 import logging
 from pathlib import Path
 from typing import Dict, List, Optional, Any
@@ -213,7 +212,13 @@ class FileSystemTraceStore:
             reason_preview = goal.reason[:60] + "..." if len(goal.reason) > 60 else goal.reason
             print(f"  💡 {reason_preview}")
 
-    async def update_goal(self, trace_id: str, goal_id: str, **updates) -> None:
+    async def update_goal(
+        self,
+        trace_id: str,
+        goal_id: str,
+        cascade_completion: bool = True,
+        **updates,
+    ) -> None:
         """更新 Goal 字段"""
         tree = await self.get_goal_tree(trace_id)
         if not tree:
@@ -237,7 +242,7 @@ class FileSystemTraceStore:
         # 如果状态变为 completed,检查是否需要级联完成父 Goal
         affected_goals = [{"goal_id": goal_id, "updates": updates}]
 
-        if updates.get("status") == "completed":
+        if cascade_completion and updates.get("status") == "completed":
             # 检查级联完成:如果所有兄弟 Goal 都完成,父 Goal 也完成
             cascade_completed = await self._check_cascade_completion(trace_id, goal)
             affected_goals.extend(cascade_completed)