feat(toolset): 工具系统重构为 toolset 统一管理,新增系统预置工具集
将工具管理从"agent 挂单个 tool"改为"agent 挂 toolset"模式: - 三个系统预置工具集(system_basic/system_chat/system_workflow)入 DB - 新增 send_file 工具(系统对话工具集)、修复 approval actor 调用 bug - 后端 agent 加载全部走 toolset 链路,移除 load_tools_from_list - 前端工具集中心卡片展示 + agent 配置改为 toolset 多选 - resource API 增加 category 过滤与系统 toolset 保护 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import String, Text, DateTime, func
|
||||
from sqlalchemy import String, Text, DateTime, Boolean, func, text
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
@@ -9,10 +9,12 @@ from .base import BaseDataModel
|
||||
|
||||
|
||||
class CustomToolsetModel(BaseDataModel):
|
||||
"""用户自定义工具组:把若干个非 system / 非 mcp 的工具插件打包成一个 toolset。
|
||||
"""工具集:把若干个工具插件打包成一个 toolset。
|
||||
|
||||
``tools`` 字段保存工具名列表(即 ``plugin/tool_plugin/`` 下的目录名);
|
||||
GSM 启动时按列表把对应工具函数装进同一个 ``FunctionToolset``。
|
||||
系统预置工具集(is_system=True)由启动期种子写入,前端不允许修改/删除。
|
||||
用户自定义工具集(is_system=False)只能包含第三方工具。
|
||||
|
||||
``tools`` 字段保存工具名列表(即 ``plugin/tool_plugin/`` 下的目录名)。
|
||||
"""
|
||||
|
||||
__tablename__ = "custom_toolset"
|
||||
@@ -22,7 +24,23 @@ class CustomToolsetModel(BaseDataModel):
|
||||
description: Mapped[Optional[str]] = mapped_column(Text)
|
||||
owner_id: Mapped[Optional[str]] = mapped_column(String(64), index=True)
|
||||
tools: Mapped[List[str]] = mapped_column(
|
||||
JSONB, default=list, comment="工具名列表,仅允许非 system/非 mcp 的工具"
|
||||
JSONB, default=list, comment="工具名列表"
|
||||
)
|
||||
is_system: Mapped[bool] = mapped_column(
|
||||
Boolean,
|
||||
nullable=False,
|
||||
default=False,
|
||||
server_default=text("false"),
|
||||
index=True,
|
||||
comment="是否系统预置工具集(不可修改/删除)",
|
||||
)
|
||||
category: Mapped[str] = mapped_column(
|
||||
String(32),
|
||||
nullable=False,
|
||||
default="user",
|
||||
server_default=text("'user'"),
|
||||
index=True,
|
||||
comment="分类:system_basic/system_chat/system_workflow/user",
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
|
||||
@@ -33,7 +33,7 @@ class SystemNodeConfigModel(BaseDataModel):
|
||||
provider_title: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
model_id: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
tools: Mapped[Optional[List[str]]] = mapped_column(
|
||||
JSONB, default=list, comment="节点可调用的工具标识列表"
|
||||
JSONB, default=list, comment="节点挂载的工具集 ID 列表(custom_toolset.toolset_id)"
|
||||
)
|
||||
persona_id: Mapped[Optional[str]] = mapped_column(
|
||||
ForeignKey("persona_template.template_id", ondelete="SET NULL"),
|
||||
|
||||
@@ -7,7 +7,7 @@ from kilostar.core.postgres_database.model.custom_toolset import CustomToolsetMo
|
||||
|
||||
|
||||
class CustomToolsetDatabase:
|
||||
"""用户自定义工具组 DAO。``tools`` 字段是工具名列表,业务层负责保证只放非 system/非 mcp 的工具。"""
|
||||
"""工具集 DAO。包含系统预置 toolset(is_system=True)和用户自定义 toolset。"""
|
||||
|
||||
def __init__(self, async_session_maker):
|
||||
self.async_session_maker = async_session_maker
|
||||
@@ -20,6 +20,8 @@ class CustomToolsetDatabase:
|
||||
"description": row.description,
|
||||
"owner_id": row.owner_id,
|
||||
"tools": list(row.tools or []),
|
||||
"is_system": bool(row.is_system),
|
||||
"category": row.category,
|
||||
}
|
||||
|
||||
@database_exception
|
||||
@@ -30,6 +32,8 @@ class CustomToolsetDatabase:
|
||||
tools: List[str],
|
||||
description: Optional[str] = None,
|
||||
owner_id: Optional[str] = None,
|
||||
is_system: bool = False,
|
||||
category: str = "user",
|
||||
) -> Dict[str, Any]:
|
||||
async with self.async_session_maker() as session:
|
||||
stmt = select(CustomToolsetModel).where(
|
||||
@@ -41,6 +45,8 @@ class CustomToolsetDatabase:
|
||||
row.description = description
|
||||
row.owner_id = owner_id
|
||||
row.tools = list(tools)
|
||||
row.is_system = is_system
|
||||
row.category = category
|
||||
else:
|
||||
row = CustomToolsetModel(
|
||||
toolset_id=toolset_id,
|
||||
@@ -48,6 +54,8 @@ class CustomToolsetDatabase:
|
||||
description=description,
|
||||
owner_id=owner_id,
|
||||
tools=list(tools),
|
||||
is_system=is_system,
|
||||
category=category,
|
||||
)
|
||||
session.add(row)
|
||||
await session.commit()
|
||||
|
||||
Reference in New Issue
Block a user