feat(task): 添加任务修订功能和超时处理机制
添加了 `revise_task` 路由动作类型,允许用户修改、纠正或重新执行最新活动任务结果。 实现了工具失败指导原则,防止相同类别工具重复失败。 为任务规划器添加了超时处理机制,避免长时间等待。 BREAKING CHANGE: 任务路由逻辑已更新,新增 `revise_task` 动作类型。 fix(api): 修复任务详情API返回完整流程投影 修复了任务详情API端点,现在会包含过滤后的流程运行、事件和工件信息, 并确保时间戳字段正确序列化。 refactor(engine): 优化任务技能解析器摘要节点处理 改进了任务技能解析器对摘要节点的处理逻辑,对于仅依赖文本生成功能的摘要节 点不再分配具体技能,直接使用依赖项输出进行汇总。 test: 增加任务修订和超时处理测试用例 添加了测试用例验证任务修订输入记录反馈、超时回退到单模式以及 摘要节点技能解析等新功能。
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Literal
|
||||
@ -77,6 +78,7 @@ class TaskExecutionPlanner:
|
||||
attempt_index: int,
|
||||
latest_validation: ValidationResult | None = None,
|
||||
provider_bundle: ProviderBundle | None = None,
|
||||
timeout_seconds: float = 30.0,
|
||||
) -> TaskExecutionPlan:
|
||||
provider = None
|
||||
model = None
|
||||
@ -87,29 +89,32 @@ class TaskExecutionPlanner:
|
||||
if provider is None:
|
||||
return TaskExecutionPlan.single("planner_provider_unavailable")
|
||||
try:
|
||||
response = await provider.chat(
|
||||
messages=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": (
|
||||
"You choose whether an internal Beaver Task attempt should run as a single "
|
||||
"main-agent pass or use a small sub-agent team first. Return only compact JSON."
|
||||
),
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": self._prompt(
|
||||
task=task,
|
||||
user_message=user_message,
|
||||
attempt_index=attempt_index,
|
||||
latest_validation=latest_validation,
|
||||
),
|
||||
},
|
||||
],
|
||||
tools=None,
|
||||
model=model,
|
||||
max_tokens=4096,
|
||||
temperature=0.0,
|
||||
response = await asyncio.wait_for(
|
||||
provider.chat(
|
||||
messages=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": (
|
||||
"You choose whether an internal Beaver Task attempt should run as a single "
|
||||
"main-agent pass or use a small sub-agent team first. Return only compact JSON."
|
||||
),
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": self._prompt(
|
||||
task=task,
|
||||
user_message=user_message,
|
||||
attempt_index=attempt_index,
|
||||
latest_validation=latest_validation,
|
||||
),
|
||||
},
|
||||
],
|
||||
tools=None,
|
||||
model=model,
|
||||
max_tokens=4096,
|
||||
temperature=0.0,
|
||||
),
|
||||
timeout=timeout_seconds,
|
||||
)
|
||||
plan = self.from_json(response.content or "")
|
||||
return await self._resolve_plan(
|
||||
@ -120,7 +125,9 @@ class TaskExecutionPlanner:
|
||||
provider_bundle=provider_bundle,
|
||||
)
|
||||
except Exception as exc:
|
||||
return TaskExecutionPlan.single("planner_failed", fallback_error=str(exc))
|
||||
detail = str(exc)
|
||||
error = f"{type(exc).__name__}: {detail}" if detail else type(exc).__name__
|
||||
return TaskExecutionPlan.single("planner_failed", fallback_error=error)
|
||||
|
||||
async def _resolve_plan(
|
||||
self,
|
||||
|
||||
@ -69,6 +69,14 @@ class MainAgentRouter:
|
||||
reason = str(payload.get("reason") or raw_action or "llm_router")
|
||||
short_title = _clean_short_title(payload.get("short_title") or payload.get("title"))
|
||||
|
||||
if raw_action in {"revise_task", "revise", "revision", "needs_revision"}:
|
||||
return MainAgentDecision(
|
||||
mode="task",
|
||||
reason=reason,
|
||||
starts_new_task=active_task is None,
|
||||
short_title=short_title,
|
||||
action="revise_task" if active_task is not None else "create_task",
|
||||
)
|
||||
if raw_action in {"continue_task", "continue", "task"}:
|
||||
return MainAgentDecision(
|
||||
mode="task",
|
||||
@ -146,13 +154,16 @@ class MainAgentRouter:
|
||||
"Actions:\n"
|
||||
"- simple_chat: no Task should be created or continued.\n"
|
||||
"- continue_task: keep the user in the active Task.\n"
|
||||
"- revise_task: user asks to change, correct, refine, expand, reformat, or redo the latest active Task result.\n"
|
||||
"- new_task: start a separate new Task.\n"
|
||||
"- close_task: user explicitly says the active Task is done/satisfactory/finished.\n"
|
||||
"- abandon_task: user explicitly says to stop, cancel, abandon, or no longer do the active Task.\n\n"
|
||||
"Critical policy:\n"
|
||||
"- If there is an active Task, choose continue_task unless the user's topic is completely unrelated "
|
||||
"- If there is an active Task, choose continue_task or revise_task unless the user's topic is completely unrelated "
|
||||
"to that Task or the user explicitly closes/abandons it.\n"
|
||||
"- Follow-up questions, corrections, partial changes, extra constraints, and result discussion stay in continue_task.\n"
|
||||
"- Choose revise_task when the active Task is awaiting feedback or needs revision and the user asks for changes "
|
||||
"such as '改一下', '加上', '删除', '换成', '再详细点', '格式改成', '不要', or equivalent wording.\n"
|
||||
"- Choose continue_task for neutral follow-up questions or additional next steps that do not imply dissatisfaction with the previous result.\n"
|
||||
"- Use new_task only when the user clearly asks to start a different task.\n"
|
||||
"- If there is no active Task, choose new_task only for work that requires execution, iteration, tools, files, "
|
||||
"implementation, validation, or multi-step completion. Otherwise choose simple_chat.\n"
|
||||
|
||||
@ -93,6 +93,29 @@ class TaskSkillResolver:
|
||||
for item in node.agent.metadata.get("required_capabilities", [])
|
||||
if str(item).strip()
|
||||
]
|
||||
if self._is_summary_only_node(node, skill_query=skill_query, required_capabilities=required_capabilities):
|
||||
resolved = self._generic_node(
|
||||
node,
|
||||
pinned_skill_names=[],
|
||||
pinned_skill_contexts=[],
|
||||
metadata={
|
||||
**node.agent.metadata,
|
||||
"skill_query": skill_query,
|
||||
"required_capabilities": required_capabilities,
|
||||
"selected_skill_names": [],
|
||||
"ephemeral_skill_names": [],
|
||||
"summary_uses_dependency_outputs_only": True,
|
||||
},
|
||||
)
|
||||
return resolved, SkillResolutionReport(
|
||||
node_id=node.node_id,
|
||||
skill_query=skill_query,
|
||||
required_capabilities=required_capabilities,
|
||||
selected_skill_names=[],
|
||||
ephemeral_used=False,
|
||||
reason="summary node uses dependency outputs directly",
|
||||
)
|
||||
|
||||
selected = await self._select_published_skills(
|
||||
query="\n".join(
|
||||
part
|
||||
@ -226,6 +249,34 @@ class TaskSkillResolver:
|
||||
selected.append(name)
|
||||
return selected
|
||||
|
||||
@staticmethod
|
||||
def _is_summary_only_node(
|
||||
node: ExecutionNode,
|
||||
*,
|
||||
skill_query: str,
|
||||
required_capabilities: list[str],
|
||||
) -> bool:
|
||||
node_id = node.node_id.strip().lower()
|
||||
query = skill_query.strip().lower()
|
||||
capabilities = {item.strip().lower() for item in required_capabilities}
|
||||
task_text = node.task.strip().lower()
|
||||
summary_identity = node_id in {"summarize", "summary", "synthesis"} or query in {
|
||||
"summarization",
|
||||
"summary",
|
||||
"synthesis",
|
||||
"final synthesis",
|
||||
}
|
||||
text_only_capabilities = not capabilities or capabilities.issubset(
|
||||
{"text generation", "summarization", "summary", "synthesis"}
|
||||
)
|
||||
dependency_summary_task = (
|
||||
"summary" in task_text
|
||||
or "summarize" in task_text
|
||||
or "synthesis" in task_text
|
||||
or "compile" in task_text
|
||||
)
|
||||
return summary_identity and text_only_capabilities and dependency_summary_task
|
||||
|
||||
@staticmethod
|
||||
def _generic_node(
|
||||
node: ExecutionNode,
|
||||
@ -246,7 +297,9 @@ class TaskSkillResolver:
|
||||
},
|
||||
),
|
||||
inherited_pinned_skills=pinned_skill_names,
|
||||
inherited_pinned_skill_contexts=list(pinned_skill_contexts or node.inherited_pinned_skill_contexts),
|
||||
inherited_pinned_skill_contexts=list(
|
||||
node.inherited_pinned_skill_contexts if pinned_skill_contexts is None else pinned_skill_contexts
|
||||
),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user