feat: 实现 Tool Search Tool 动态工具发现机制

- 新增 ToolRegistry 工具注册表,支持核心工具和延迟加载工具分离
- 新增 tool_search 元工具,支持关键词搜索发现可用工具
- 新增基于关键词的搜索算法,按相关度评分排序
- 为所有工具添加 metadata(分类、关键词、延迟加载标识)
- 修改 Agent 支持动态工具注入,tool_search 结果自动添加到可用工具
- 核心工具(tool_search, bash)始终加载,其他工具按需发现
This commit is contained in:
2025-12-10 19:51:25 +08:00
parent e435b2f8f8
commit bc1ece3dad
19 changed files with 569 additions and 66 deletions
+21 -14
View File
@@ -1,8 +1,12 @@
import type { Tool } from '../types/index.js';
import type { ToolWithMetadata } from './types.js';
import { toolRegistry } from './registry.js';
// Shell 工具
import { bashTool } from './shell/index.js';
// 核心工具
import { toolSearchTool } from './tool-search.js';
// 文件系统工具
import {
readFileTool,
@@ -18,30 +22,33 @@ import {
deleteFileTool,
} from './filesystem/index.js';
// 所有可用工具的注册中心
// 添加新工具只需在此数组中添加一行
export const allTools: Tool[] = [
// Shell
// 所有工具列表(用于注册)
const allToolsWithMetadata: ToolWithMetadata[] = [
// 核心工具 (deferLoading: false)
toolSearchTool,
bashTool,
// 文件读写
// 文件系统工具 (deferLoading: true)
readFileTool,
writeFileTool,
editFileTool,
// 目录操作
listDirTool,
createDirectoryTool,
// 搜索
searchFilesTool,
grepContentTool,
// 文件信息
getFileInfoTool,
// 文件管理
moveFileTool,
copyFileTool,
deleteFileTool,
];
// 注册所有工具到 registry
toolRegistry.registerAll(allToolsWithMetadata);
// 导出
export { toolRegistry } from './registry.js';
export { toolSearchTool } from './tool-search.js';
export type { ToolWithMetadata, ToolMetadata, ToolCategory, ToolSearchResult } from './types.js';
// 兼容旧代码:导出所有工具数组(基础 Tool 类型)
export const allTools = toolRegistry.getAllTools();