4aa1dab283
- control_node 标注 DEPRECATED:保留目录壳子供未来远程探针节点复用,删除调用路径与相关测试
- 新增 task 表:极简元数据持久化 regulatory_node 完成的短任务(出报告/写文件/查询整理)
- regulatory_node 自标注:MessageResponse 扩展 task_action/title/summary,_run 末尾非阻塞落库
- query_task_list 改查 task 表,符合用户对"任务列表"的直觉,与 workflow 体系解耦
- 新增 /api/v1/task/list|/{id} 只读 API(task 由 regulatory 内部触发,不开放对外创建)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
"""把组织包装成 cabinet 可调用的高阶 tool。
|
|
|
|
每个组织 → 一个 ``dispatch_to_<org>(task_description)`` 工具。
|
|
RegulatoryNode/ConsciousnessNode 通过这个工具向部门派单,等待部门完成。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Callable, Dict
|
|
|
|
|
|
def make_dispatch_tool(org_name: str, display_name: str, description: str) -> Callable:
|
|
"""生成对应组织的 dispatch tool。
|
|
|
|
工具签名故意保持简单:只收一个自然语言任务描述,cabinet 不需要懂部门内部
|
|
capability 划分;部门内部 ReAct 自己决定怎么干。
|
|
"""
|
|
tool_name = f"dispatch_to_{org_name}"
|
|
desc_text = description or f"把任务派给{display_name or org_name}部门,由部门内部多 agent 协作完成。"
|
|
|
|
async def _impl(task_description: str) -> str:
|
|
from kilostar.utils.ray_hook import ray_actor_hook
|
|
|
|
actor_name = f"org_{org_name}"
|
|
actor = ray_actor_hook(actor_name)
|
|
target = getattr(actor, actor_name)
|
|
result = await target.dispatch.remote(task_description, {})
|
|
if result.get("status") == "completed":
|
|
return str(result.get("result") or "")
|
|
return f"[{org_name} 任务失败] {result.get('error') or 'unknown'}"
|
|
|
|
_impl.__name__ = tool_name
|
|
_impl.__doc__ = (
|
|
f"{desc_text}\n\n"
|
|
"Args:\n"
|
|
" task_description: 用自然语言描述要部门完成的任务。\n\n"
|
|
"Returns:\n"
|
|
" 部门交付的结果文本,失败时返回错误说明。\n"
|
|
)
|
|
return _impl
|
|
|
|
|
|
def collect_dispatch_tools(org_specs: Dict[str, Dict[str, str]]) -> Dict[str, Callable]:
|
|
"""根据 ``{org_name: {"display_name": ..., "description": ...}}`` 批量生成。"""
|
|
return {
|
|
f"dispatch_to_{name}": make_dispatch_tool(
|
|
name,
|
|
spec.get("display_name", ""),
|
|
spec.get("description", ""),
|
|
)
|
|
for name, spec in org_specs.items()
|
|
}
|