Merge remote-tracking branch 'origin/master' into ji
# Conflicts: # offline-backend-20260512/backend/app/gateway/app.py # offline-backend-20260512/backend/config.yaml # offline-backend-20260512/backend/packages/harness/deerflow/persistence/models/__init__.py # offline-backend-20260512/backend/packages/harness/deerflow/runtime/checkpointer/async_provider.py
This commit is contained in:
commit
87e0ae683e
112 files changed
+25039
-1804
No files matched your search
+82
@@ -0,0 +1,82 @@
|
||||
"""read_peer_delivery —— 圆桌席位「按需读取前序席位**完整交付**」的只读工具。
|
||||
|
||||
背景:圆桌每个席位是独立 thread(独立 sandbox),彼此隔离。默认情况下,一个席位只能
|
||||
从跨席位广播里看到前序席位的**截断摘要**(≤1500 字)。当席位识别到自己需要某个前序
|
||||
席位的**全文**时,调用本工具按席位名取回完整交付。
|
||||
|
||||
数据来源:全文由**网关层**(``app.gateway``)在发起本席位 run 时,注入到
|
||||
``runtime.context["roundtable_peer_deliveries"]`` —— 一个
|
||||
``[{"name": <席位显示名>, "content": <完整交付正文>}, ...]`` 列表。本工具**只读该上下文
|
||||
dict**,不跨 thread、不碰 sandbox、不发网络请求,因此完全在 ``deerflow.*`` 内(不违反
|
||||
harness→app 导入防火墙)。非圆桌场景下该上下文为空,工具返回「无」。
|
||||
|
||||
「传摘要按需传全文」:完整交付**只在席位真正调用本工具时**才进入它的 LLM 上下文,平时
|
||||
只有摘要,既省 token 又满足「需要时能拿全文」。详见
|
||||
``frontend-web/docs/roundtable-dag-orchestration.md`` §12.9。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from langchain.tools import ToolRuntime, tool
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_CTX_KEY = "roundtable_peer_deliveries"
|
||||
|
||||
|
||||
def _peer_deliveries(runtime: ToolRuntime | None) -> list[dict]:
|
||||
"""从 runtime.context 取出网关注入的前序席位完整交付列表(缺失/非法时返回 [])。"""
|
||||
if runtime is None:
|
||||
return []
|
||||
ctx = getattr(runtime, "context", None)
|
||||
if not ctx:
|
||||
return []
|
||||
try:
|
||||
peers = ctx.get(_CTX_KEY)
|
||||
except Exception:
|
||||
return []
|
||||
if not isinstance(peers, list):
|
||||
return []
|
||||
return [p for p in peers if isinstance(p, dict)]
|
||||
|
||||
|
||||
@tool("read_peer_delivery", parse_docstring=True)
|
||||
def read_peer_delivery_tool(runtime: ToolRuntime, seat_name: str = "") -> str:
|
||||
"""Read another roundtable seat's FULL deliverable on demand.
|
||||
|
||||
In a multi-agent roundtable you (a seat) normally only see **truncated
|
||||
summaries** of earlier seats' deliverables. When you decide you genuinely
|
||||
need the **complete text** of a specific earlier seat (e.g. to build on its
|
||||
detailed data/conclusions), call this tool with that seat's name to fetch
|
||||
its full deliverable. Prefer the summaries you already have; only call this
|
||||
when the summary is insufficient.
|
||||
|
||||
Args:
|
||||
seat_name: The earlier seat's display name (the Chinese name shown in
|
||||
the summaries, e.g. "情报收集"). Leave empty to list which peers'
|
||||
full deliverables are available to read.
|
||||
"""
|
||||
peers = _peer_deliveries(runtime)
|
||||
if not peers:
|
||||
return "(当前没有可读取的前序席位完整交付。请直接基于你已有的上下文与摘要完成交付。)"
|
||||
|
||||
names = [str(p.get("name") or "") for p in peers if p.get("name")]
|
||||
query = (seat_name or "").strip()
|
||||
if not query:
|
||||
return (
|
||||
"可读取**完整交付**的前序席位:" + "、".join(names) + "。\n"
|
||||
"需要哪个席位的全文,就再次调用 read_peer_delivery 并把它的名称传给 seat_name。"
|
||||
)
|
||||
|
||||
ql = query.lower()
|
||||
# 精确匹配(忽略大小写)优先,其次子串互含(容忍模型给「情报收集席位」这类带后缀的名)。
|
||||
for p in peers:
|
||||
if str(p.get("name") or "").lower() == ql:
|
||||
return str(p.get("content") or "(该席位交付为空。)")
|
||||
for p in peers:
|
||||
nm = str(p.get("name") or "")
|
||||
if nm and (ql in nm.lower() or nm.lower() in ql):
|
||||
return str(p.get("content") or "(该席位交付为空。)")
|
||||
return f"未找到名为「{query}」的前序席位。可读取的有:" + "、".join(names) + "。"
|
||||
@@ -139,6 +139,13 @@ def get_available_tools(
|
||||
|
||||
builtin_tools.extend([skill_list_tool, skill_view_tool])
|
||||
|
||||
# read_peer_delivery —— 圆桌席位「按需读取前序席位完整交付」的只读工具(从 run context
|
||||
# 取网关注入的全文,非圆桌场景为空 → 工具自述「无」)。始终提供(只读、无副作用);圆桌
|
||||
# 总控/报告角色由 run policy 显式排除,避免干扰它们。
|
||||
from deerflow.tools.builtins.roundtable_peers_tool import read_peer_delivery_tool
|
||||
|
||||
builtin_tools.append(read_peer_delivery_tool)
|
||||
|
||||
# skill_manage 能创建/修改/删除技能,属于"自我进化"写能力,按 skill_evolution.enabled
|
||||
# 门控。该开关用户可在 per-user 配置里覆盖,所以按"生效配置(含 per-user 覆盖)"判断 ——
|
||||
# Gateway 每次 run 重建 agent,用户改了配置下次 run 即生效;解析失败退回全局 config.yaml。
|
||||
|
||||
Reference in new issue
Block a user