feat(tasks): add skill-templated task graph execution

This commit is contained in:
2026-06-23 10:22:58 +08:00
parent 6843d89b2c
commit 53b13e8eac
53 changed files with 4773 additions and 756 deletions

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio
import json
import re
from typing import Any
from .models import MainAgentDecision, TaskRecord
@ -24,6 +25,15 @@ class MainAgentRouter:
thinking_enabled: bool | None = None,
timeout_seconds: float = 8.0,
) -> MainAgentDecision:
if active_task is None and _is_obvious_simple_chat(message):
return MainAgentDecision(mode="simple", reason="obvious_simple_chat", action="simple_chat")
if active_task is None and _is_obvious_task_request(message):
return MainAgentDecision(
mode="task",
reason="obvious_task",
starts_new_task=True,
action="create_task",
)
if provider is None:
return self._apply_active_task_boundary(
self._fallback(active_task=active_task, reason="router_provider_unavailable"),
@ -246,6 +256,64 @@ def _clean_short_title(value: Any) -> str | None:
return title[:40] or None
def _is_obvious_simple_chat(message: str) -> bool:
text = _compact_text(message).lower().strip("!??。.,~")
if not text:
return False
if _has_url_or_path(text) or _looks_like_fresh_task_request(text):
return False
if len(text) <= 24 and text in {
"hi",
"hello",
"hey",
"thanks",
"thankyou",
"thankyou!",
"谢谢",
"谢了",
"多谢",
"你好",
"您好",
"",
"在吗",
"早上好",
"下午好",
"晚上好",
"辛苦了",
}:
return True
simple_prefixes = (
"翻译",
"translate",
"润色",
"改写",
"校对",
"总结下面",
"总结这段",
"摘要下面",
"summarize this",
)
return len(text) <= 1200 and text.startswith(simple_prefixes)
def _is_obvious_task_request(message: str) -> bool:
text = _compact_text(message)
if not text:
return False
if _looks_like_explicit_task_followup(text):
return False
if _has_url_or_path(text):
return True
return _looks_like_fresh_task_request(text)
def _has_url_or_path(text: str) -> bool:
return bool(
re.search(r"https?://|www\.", text)
or re.search(r"(^|[\s'\"`])(?:[./~]|[a-zA-Z]:[\\/])[^\s'\"`]+", text)
)
def _looks_like_explicit_task_followup(message: str) -> bool:
text = _compact_text(message)
if not text:
@ -307,6 +375,16 @@ def _looks_like_fresh_task_request(message: str) -> bool:
"看看最新",
"最新",
"今天",
"昨天",
"昨日",
"昨晚",
"刚刚",
"最近",
"近期",
"本届",
"本场",
"这场",
"上一场",
"明天",
"上传",
"下载",
@ -324,6 +402,12 @@ def _looks_like_fresh_task_request(message: str) -> bool:
"look up",
"latest",
"today",
"yesterday",
"last night",
"recent",
"recently",
"this match",
"this game",
"tomorrow",
"upload",
"download",