feat: 工具系统迁移 + 重型插件骨架 + 前端交互增强
- 工具系统从 kilostar/plugin/tool_plugin/ 迁移到 data/toolset/(manifest.json 声明式) - 新增 plugin_runtime 模块:BaseOrganization / GlobalPluginManager / loader / tool_bridge - 新增 org_task + org_task_event 表及 DAO(alembic 0009) - 新增 /api/v1/plugin 路由(submit/status/stream/install/reload) - 新增 data/plugin/example_dept 示例重型插件 - regulatory_node 支持聊天历史上下文注入 - send_file 改为 artifact 存盘 + SSE 推送下载链接 - 前端 WorkflowFileCard 组件 + ToolSettings README 渲染 - utils 整理:合并 access/role_check、standalone_proxy→ray_compat、删除废弃模块 - 项目结构文档移至 docs/STRUCTURE.md 并详细展开 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""把组织包装成 cabinet 可调用的高阶 tool。
|
||||
|
||||
每个组织 → 一个 ``dispatch_to_<org>(task_description)`` 工具。
|
||||
ConsciousnessNode/ControlNode 通过这个工具向部门派单,等待部门完成。
|
||||
"""
|
||||
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user