feat(v2): T6 CollaborativePipeline 编排(快路径/协作循环/熔断/终审)

This commit is contained in:
tzt
2026-08-30 21:12:03 +08:00
parent 4fbbdb5290
commit ad81e1afb7
5 changed files with 484 additions and 5 deletions
+12 -4
View File
@@ -68,6 +68,12 @@ class WorkerLoop:
self.max_fix_attempts = max_fix_attempts
self.model_used = model_used
async def direct_answer(self, query: str) -> str:
"""快路径直答:让 Worker 直接生成用户回答(非 JSON、无围栏)。"""
prompt = ("请直接回答下面这个问题,输出对用户有用的正文"
"(不要输出 JSON,不要加代码块围栏)。问题:" + query)
return await self.generate(prompt)
def _domain_from(self, ws: Workspace) -> str:
tags = (ws.get("brief") or {}).get("tags") or []
for t in tags:
@@ -76,8 +82,8 @@ class WorkerLoop:
return "general"
async def run_step(self, ws: Workspace, step_id: str,
existing_artifact: str = "") -> StepOutcome:
"""执行单个 step。existing_artifact 为该步当前已有工件全文(若有)"""
existing_artifact: str = "", hint: str = "") -> StepOutcome:
"""执行单个 step。existing_artifact 为该步当前已有工件全文hint 为 Architect 裁决提示"""
domain = self._domain_from(ws)
brief = ws.get("brief") or {}
plan = brief.get("plan") or []
@@ -89,7 +95,7 @@ class WorkerLoop:
details: List[str] = []
for attempt in range(1, self.max_fix_attempts + 1):
prompt = self._build_prompt(ws, step_id, current, attempt, done_criteria)
prompt = self._build_prompt(ws, step_id, current, attempt, done_criteria, hint)
out = await self.generate(prompt)
if domain == "code":
candidate = extract_code_block(out)
@@ -134,13 +140,15 @@ class WorkerLoop:
)
def _build_prompt(self, ws: Workspace, step_id: str, current: str,
attempt: int, done_criteria: str) -> str:
attempt: int, done_criteria: str, hint: str = "") -> str:
base = ws.render_for_worker(step_id, artifact_text=current or None)
if attempt > 1:
base += (
"\n\n[注意] 上次生成的工件未通过接地验证。请修正以下问题后重新输出"
f"完整工件。本次为第 {attempt} 次尝试。"
)
if hint:
base += "\n\n[架构师裁决] " + hint
return base