auto-sync: 2026-06-04 22:33:27
This commit is contained in:
+35
-40
@@ -274,50 +274,40 @@ class AgentSpawner:
|
||||
task_id, title, description, must_haves,
|
||||
project_id, agent_id)
|
||||
|
||||
# 尝试 BootstrapBuilder
|
||||
if self.bootstrap_builder and task is not None:
|
||||
try:
|
||||
# v3.1: spawn_type 映射到角色 (executor→executor, review→reviewer, discussion→planner)
|
||||
role_map = {"executor": "executor", "review": "reviewer", "discussion": "planner"}
|
||||
role = role_map.get(spawn_type, "executor")
|
||||
bootstrap_prompt = self.bootstrap_builder.build_for_task(
|
||||
task=task,
|
||||
role=role,
|
||||
project_config=project_config,
|
||||
)
|
||||
# mail 任务用精简模板,不走 BootstrapBuilder
|
||||
if project_id == "_mail":
|
||||
return self._build_mail_prompt(task_id, title, description, must_haves, agent_id)
|
||||
api_section = self._build_api_section(
|
||||
project_id, task_id, agent_id)
|
||||
return bootstrap_prompt + "\n\n---\n\n" + api_section
|
||||
except Exception:
|
||||
logger.exception("BootstrapBuilder failed, falling back to template")
|
||||
|
||||
# mail 任务用精简模板
|
||||
if project_id == "_mail":
|
||||
return self._build_mail_prompt(task_id, title, description, must_haves, agent_id)
|
||||
|
||||
# Fallback: 使用硬编码模板
|
||||
# mail 任务直接 done,不走 review
|
||||
completion_status = "done" if project_id == "_mail" else "review"
|
||||
identity_section = self._inject_agent_identity(agent_id)
|
||||
guardrails_summary = self._get_guardrails_summary()
|
||||
return SPAWN_PROMPT_TEMPLATE.format(
|
||||
identity_section=identity_section,
|
||||
project_id=project_id,
|
||||
task_id=task_id,
|
||||
title=title,
|
||||
description=description or "(无描述)",
|
||||
task_type=task_type or "general",
|
||||
priority=priority,
|
||||
must_haves=must_haves or "(无)",
|
||||
agent_id=agent_id,
|
||||
api_base=f"http://{self.api_host}:{self.api_port}/api",
|
||||
retry_context=retry_context or "",
|
||||
completion_status=completion_status,
|
||||
guardrails_summary=guardrails_summary,
|
||||
)
|
||||
# 走 BootstrapBuilder 新路径
|
||||
if self.bootstrap_builder and task is not None:
|
||||
role_map = {"executor": "executor", "review": "reviewer", "discussion": "planner"}
|
||||
role = role_map.get(spawn_type, "executor")
|
||||
bootstrap_prompt = self.bootstrap_builder.build_for_task(
|
||||
task=task,
|
||||
role=role,
|
||||
)
|
||||
api_section = self._build_api_section(
|
||||
project_id, task_id, agent_id)
|
||||
return bootstrap_prompt + "\n\n---\n\n" + api_section
|
||||
|
||||
# 无 BootstrapBuilder 或无 task 对象 → 最小 fallback
|
||||
# 只保留任务上下文 + API 操作指令
|
||||
logger.warning("No BootstrapBuilder or task object, using minimal fallback")
|
||||
return self._build_minimal_fallback(
|
||||
task_id, title, description, must_haves,
|
||||
project_id, agent_id)
|
||||
|
||||
def _build_minimal_fallback(self, task_id, title, description, must_haves,
|
||||
project_id, agent_id):
|
||||
"""最小 fallback:只有任务上下文 + API 指令"""
|
||||
task_section = f"""## 任务
|
||||
{title}
|
||||
{description or "(无描述)"}
|
||||
|
||||
项目: {project_id} | ID: {task_id}
|
||||
验收标准: {must_haves or "(无)"}"""
|
||||
api_section = self._build_api_section(project_id, task_id, agent_id)
|
||||
return task_section + "\n\n---\n\n" + api_section
|
||||
|
||||
def _build_api_section(self, project_id: str, task_id: str,
|
||||
agent_id: str) -> str:
|
||||
@@ -767,6 +757,11 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_
|
||||
logger.info("Agent %s finished (session=%s, outcome=%s, exit=%d, task_status=%s)",
|
||||
agent_id, session_id, outcome, exit_code, task_status)
|
||||
|
||||
# 广播反馈追踪(Phase 1 bug fix)
|
||||
if task_id and task_id != "broadcast" and hasattr(self, '_ticker') and self._ticker:
|
||||
outcome_str = "claimed" if cls.get("status") == "ok" else "no_reply"
|
||||
self._ticker.record_broadcast_response(task_id, agent_id, outcome_str)
|
||||
|
||||
if cls["should_retry"]:
|
||||
# cooldown: 新增的可恢复场景(A14/A15/A16/A8/A10)
|
||||
cooldown_seconds = cls.get("cooldown_seconds", 0)
|
||||
|
||||
Reference in New Issue
Block a user