修改了nanobot,往Hermes agent的风格走,进度1/3

This commit is contained in:
2026-04-20 18:11:14 +08:00
parent cdfc222c9f
commit 36882a7d7b
261 changed files with 12659 additions and 604 deletions

View File

@ -0,0 +1,58 @@
"""委派执行结果的共享类型定义。"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any
_PLACEHOLDER_SUMMARY_MARKERS = (
"task completed but no final response was generated",
"no final response was generated",
"已启动代理团队",
"代理团队正在后台工作",
"agent team [",
"spawn_agent_team",
"error calling llm",
"litellm.timeout",
"dashscopeexception",
"service temporarily unavailable",
"planner调用失败",
"本任务当前不可执行",
"无法由单一非sop工具完成",
)
def normalize_summary_text(text: str | None) -> str:
"""把摘要文本压成便于判定的稳定形式。"""
return " ".join(str(text or "").strip().split())
def contains_placeholder_summary(text: str | None) -> bool:
"""判断摘要是否只是占位兜底文本。"""
normalized = normalize_summary_text(text).lower()
if not normalized:
return True
return any(marker in normalized for marker in _PLACEHOLDER_SUMMARY_MARKERS)
def has_meaningful_summary(text: str | None) -> bool:
"""判断摘要是否包含可复用的真实结果。"""
normalized = normalize_summary_text(text)
return bool(normalized) and not contains_placeholder_summary(normalized)
@dataclass
class AgentRunResult:
"""统一描述一次 agent 执行结果。"""
# 执行方的稳定 ID适合程序判断和日志检索。
agent_id: str
# 展示给用户或前端时使用的人类可读名称。
agent_name: str
# 归一化状态:通常是 `ok` / `error` / `cancelled` 等。
status: str
# 面向上层的简要总结,是最终展示和二次总结的主要输入。
summary: str
# 可选原始载荷,保留底层协议返回值,便于调试或后续扩展。
raw: dict[str, Any] | None = None