39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""把组织包装成 cabinet 可调用的高阶 tool。
|
|
|
|
每个组织 → 一个 ``dispatch_to_<org>(task_description)`` 工具。
|
|
RegulatoryNode/ConsciousnessNode 通过这个工具向部门派单,等待部门完成。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Callable
|
|
|
|
|
|
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.actor import get_actor
|
|
|
|
target = get_actor(f"org_{org_name}")
|
|
result = await target.dispatch(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
|