/**
 * RAG-based Tool Selection Module
 *
 * Implements semantic tool selection using TF-IDF and cosine similarity
 * to reduce prompt bloat and improve tool selection accuracy.
 *
 * Based on research from:
 * - RAG-MCP (arXiv:2505.03275)
 * - ToolLLM (ICLR'24)
 *
 * Key improvements:
 * - Reduces prompt tokens by ~50%
 * - Improves tool selection accuracy from ~13% to ~43%+ with many tools
 * - Adaptive thresholds based on success metrics
 * - LRU cache for repeated queries
 */
import { CodeBuddyTool } from "../codebuddy/client.js";
import { ToolCategory, ToolMetadata, QueryClassification, ToolSelectionResult, ToolSelectionMetrics } from "./types.js";
export type { ToolCategory, ToolMetadata, QueryClassification, ToolSelectionResult, ToolSelectionMetrics };
/**
 * Event for when LLM requests a tool
 */
export interface ToolRequestEvent {
    requestedTool: string;
    selectedTools: string[];
    query: string;
    wasSelected: boolean;
}
/**
 * RAG-based Tool Selector.
 *
 * Selects the most relevant tools for a given query to reduce context window usage
 * and improve LLM adherence to tool definitions.
 *
 * Uses a hybrid approach:
 * 1. **TF-IDF Scoring**: Matches query terms against tool keywords and descriptions.
 * 2. **Category Classification**: Classifies intent (e.g., "edit file" -> `file_write`) and boosts relevant tools.
 * 3. **Adaptive Thresholding**: Adjusts inclusion threshold based on success metrics to balance precision/recall.
 *
 * Includes LRU caching for performance.
 */
export declare class ToolSelector {
    private toolIndex;
    private idfScores;
    private documentFrequency;
    private totalDocuments;
    private metrics;
    private requestHistory;
    private maxHistorySize;
    private baseMinScore;
    private adaptiveMinScore;
    private adaptationRate;
    private classificationCache;
    private selectionCache;
    constructor();
    /**
     * Build the TF-IDF index from tool metadata
     */
    private buildIndex;
    /**
     * Tokenize and normalize a query string
     */
    private tokenize;
    /**
     * Calculate TF-IDF score for a query against a tool
     */
    private calculateTFIDF;
    /**
     * Classify a user query into tool categories (with caching)
     */
    classifyQuery(query: string): QueryClassification;
    /**
     * Select the most relevant tools for a given query.
     *
     * @param query - The user's natural language query
     * @param allTools - List of all available tools
     * @param options - Configuration options
     * @returns Selection result containing the filtered list of tools
     */
    selectTools(query: string, allTools: CodeBuddyTool[], options?: {
        /** Maximum number of tools to return (default: 10) */
        maxTools?: number;
        /** Minimum relevance score (0-1) to include a tool */
        minScore?: number;
        /** Only include tools in these categories */
        includeCategories?: ToolCategory[];
        /** Exclude tools in these categories */
        excludeCategories?: ToolCategory[];
        /** List of tool names to always include regardless of score */
        alwaysInclude?: string[];
        /** Whether to use dynamic thresholding based on success rate */
        useAdaptiveThreshold?: boolean;
    }): ToolSelectionResult;
    /**
     * Estimate token count for tools (rough approximation)
     */
    private estimateTokens;
    /**
     * Get tool metadata by name
     */
    getToolMetadata(name: string): ToolMetadata | undefined;
    /**
     * Register a new tool (for MCP tools)
     */
    registerTool(name: string, category: ToolCategory, keywords: string[], description: string, priority?: number): void;
    /**
     * Auto-register MCP tools by parsing their names and descriptions
     */
    registerMCPTool(tool: CodeBuddyTool): void;
    /**
     * Record a tool request from the LLM
     *
     * Call this when the LLM requests a tool to track whether
     * our RAG selection correctly included it.
     *
     * @param requestedTool - The tool name requested by LLM
     * @param selectedTools - The tools that were selected by RAG
     * @param query - The original user query
     */
    recordToolRequest(requestedTool: string, selectedTools: string[], query: string): void;
    /**
     * Adjust adaptive threshold based on recent performance
     */
    private adjustAdaptiveThreshold;
    /**
     * Get current metrics
     */
    getMetrics(): ToolSelectionMetrics;
    /**
     * Get most frequently missed tools
     */
    getMostMissedTools(limit?: number): Array<{
        tool: string;
        count: number;
    }>;
    /**
     * Get recent request history
     */
    getRequestHistory(limit?: number): ToolRequestEvent[];
    /**
     * Get current adaptive threshold
     */
    getAdaptiveThreshold(): number;
    /**
     * Manually set the adaptive threshold
     */
    setAdaptiveThreshold(threshold: number): void;
    /**
     * Reset metrics to initial state
     */
    resetMetrics(): void;
    /**
     * Format metrics as a readable string
     */
    formatMetrics(): string;
    /**
     * Clear classification cache
     */
    clearClassificationCache(): void;
    /**
     * Clear selection cache
     */
    clearSelectionCache(): void;
    /**
     * Clear all caches
     */
    clearAllCaches(): void;
    /**
     * Get cache statistics
     */
    getCacheStats(): {
        classificationCache: {
            size: number;
        };
        selectionCache: {
            size: number;
        };
    };
}
export declare function getToolSelector(): ToolSelector;
/**
 * Convenience function for tool selection
 */
export declare function selectRelevantTools(query: string, allTools: CodeBuddyTool[], maxTools?: number): ToolSelectionResult;
/**
 * Record a tool request for metrics tracking
 */
export declare function recordToolRequest(requestedTool: string, selectedTools: string[], query: string): void;
/**
 * Get tool selection metrics
 */
export declare function getToolSelectionMetrics(): ToolSelectionMetrics;
/**
 * Format metrics as string
 */
export declare function formatToolSelectionMetrics(): string;
