feat: 实现 Tool Search Tool 动态工具发现机制
- 新增 ToolRegistry 工具注册表,支持核心工具和延迟加载工具分离 - 新增 tool_search 元工具,支持关键词搜索发现可用工具 - 新增基于关键词的搜索算法,按相关度评分排序 - 为所有工具添加 metadata(分类、关键词、延迟加载标识) - 修改 Agent 支持动态工具注入,tool_search 结果自动添加到可用工具 - 核心工具(tool_search, bash)始终加载,其他工具按需发现
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import type { ToolParameter, ToolResult } from '../types/index.js';
|
||||
|
||||
// 工具类别
|
||||
export type ToolCategory = 'core' | 'filesystem' | 'shell' | 'git' | 'web' | 'database';
|
||||
|
||||
// 工具元数据
|
||||
export interface ToolMetadata {
|
||||
name: string;
|
||||
category: ToolCategory;
|
||||
description: string; // 简短描述,用于搜索结果展示
|
||||
keywords: string[]; // 搜索关键词
|
||||
deferLoading: boolean; // true = 延迟加载,false = 始终加载
|
||||
}
|
||||
|
||||
// 扩展后的工具定义(包含元数据)
|
||||
export interface ToolWithMetadata {
|
||||
name: string;
|
||||
description: string;
|
||||
parameters: Record<string, ToolParameter>;
|
||||
execute: (params: Record<string, unknown>) => Promise<ToolResult>;
|
||||
metadata: ToolMetadata;
|
||||
}
|
||||
|
||||
// 搜索结果
|
||||
export interface ToolSearchResult {
|
||||
name: string;
|
||||
description: string;
|
||||
category: ToolCategory;
|
||||
score: number;
|
||||
}
|
||||
Reference in New Issue
Block a user