/** * @zhin.js/ai - TF-IDF 工具过滤 * 根据用户消息的相关性对候选工具进行评分与筛选 */ import type { AgentTool, ToolFilterOptions } from '../types.js'; export declare function tokenize(text: string): string[]; /** * 程序化工具过滤 —— TF-IDF 加权的相关性评分 * * 评分层级(基础权重 × IDF 倍率): * 1. keywords 精确匹配: base 1.0 × idf —— 工具声明的触发关键词 * 2. tags 匹配: base 0.5 × idf —— 工具分类标签 * 3. 工具名 token 匹配: base 0.3 × idf —— 工具名按 `.` `_` `-` 拆词 * 4. description 关键词: base 0.15 × idf —— 描述中的词/短语 * * IDF = log(N / df),N 为工具总数,df 为包含该词的工具数。 * 高频词(出现在大部分工具中)的 IDF 接近 0,权重被压低; * 稀有词(仅少数工具有)的 IDF 较高,权重被放大。 * * @param message 用户消息原文 * @param tools 候选工具列表 * @param options 过滤选项 * @returns 按相关性降序排列的工具子集 */ export declare function filterTools(message: string, tools: AgentTool[], options?: ToolFilterOptions): AgentTool[]; /** * 计算工具集的身份 hash * * 使用工具名排序后拼接,变化即意味着工具集被修改。 */ export declare function computeToolSetHash(tools: AgentTool[]): string; /** * 带缓存的工具过滤器 * * 包装 filterTools,对相同的 (messageKey, toolSetHash, options) 复用结果。 */ export declare class CachedToolFilter { /** 缓存键 → 过滤结果 */ private cache; /** 当前工具集 hash */ private toolSetHash; /** * 执行带缓存的过滤 * * @param message 用户消息 * @param tools 候选工具列表 * @param options 过滤选项 * @returns 过滤后的工具列表 */ filter(message: string, tools: AgentTool[], options?: ToolFilterOptions): AgentTool[]; /** * 手动失效缓存(工具增减时调用) */ invalidate(): void; /** * 当前缓存条目数 */ get size(): number; private buildCacheKey; private pruneExpiredEntries; private evictOldest; } //# sourceMappingURL=tool-filter.d.ts.map