新增内部Task系统,包括验证、反馈门控机制,实现自动质量验证 (通过率>=0.75)和用户反馈闭环(satisfied/revise/abandon)。 实现Agent Team v1协调器,支持sequence/parallel/dag执行策略, sub-agent复用主AgentLoop,每个run使用独立memory snapshot。 建立Skill学习pipeline,包含draft/审核/发布/回滚完整生命周期, 通过Task验证通过且用户满意才生成学习候选。 重构目录结构,移除third_party依赖,建立统一engine内核, 所有agent共享运行时基础组件。 更新ContextBuilder清理provider消息字段,增强SkillContext版本管理, 集成TaskExecutionPlanner和TaskSkillResolver实现技能解析机制。
41 lines
2.0 KiB
Python
41 lines
2.0 KiB
Python
"""Main Agent routing between simple chat and internal Task mode."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
from .models import MainAgentDecision, TaskRecord
|
|
|
|
|
|
class MainAgentRouter:
|
|
"""Small deterministic classifier used before the main AgentLoop.
|
|
|
|
The first version intentionally avoids a mandatory model call so the router
|
|
stays reliable during provider outages. The rule set is conservative:
|
|
anything that implies execution, files, tools, iteration, or validation
|
|
becomes Task mode.
|
|
"""
|
|
|
|
_TASK_PATTERNS = [
|
|
r"\b(implement|fix|debug|refactor|migrate|build|create|write|edit|update|test|validate|deploy)\b",
|
|
r"\b(file|repo|code|project|backend|frontend|api|database|migration|pull request|ci|bug)\b",
|
|
r"\b(step|multi-step|workflow|plan and|then)\b",
|
|
r"(实现|修复|调试|重构|迁移|构建|创建|编写|修改|更新|测试|验证|部署|文件|代码|项目|前端|后端|接口|数据库|多步|任务)",
|
|
]
|
|
_NEW_TASK_PATTERNS = [
|
|
r"\b(new task|another task|different task|start over)\b",
|
|
r"(新任务|另一个任务|换个任务|重新开始)",
|
|
]
|
|
|
|
def classify(self, message: str, *, active_task: TaskRecord | None = None) -> MainAgentDecision:
|
|
text = message.strip()
|
|
lowered = text.lower()
|
|
starts_new = any(re.search(pattern, lowered, re.IGNORECASE) for pattern in self._NEW_TASK_PATTERNS)
|
|
if active_task is not None and active_task.status in {"awaiting_feedback", "needs_revision"} and not starts_new:
|
|
return MainAgentDecision(mode="task", reason="continuing_open_task", starts_new_task=False)
|
|
if any(re.search(pattern, lowered, re.IGNORECASE) for pattern in self._TASK_PATTERNS):
|
|
return MainAgentDecision(mode="task", reason="task_pattern_matched", starts_new_task=starts_new)
|
|
if len(text) > 240:
|
|
return MainAgentDecision(mode="task", reason="long_request", starts_new_task=starts_new)
|
|
return MainAgentDecision(mode="simple", reason="simple_question", starts_new_task=False)
|