|
2 | 2 | * Strategy runner - executes all enabled pruning strategies and collects results. |
3 | 3 | */ |
4 | 4 |
|
5 | | -import type { PruningStrategy, StrategyResult, ToolMetadata } from "./types" |
6 | 5 | import { deduplicationStrategy } from "./deduplication" |
7 | 6 |
|
8 | | -export type { PruningStrategy, StrategyResult, ToolMetadata, StrategyDetail } from "./types" |
| 7 | +/** |
| 8 | + * Common interface for rule-based pruning strategies. |
| 9 | + * Each strategy analyzes tool metadata and returns IDs that should be pruned. |
| 10 | + */ |
| 11 | + |
| 12 | +export interface ToolMetadata { |
| 13 | + tool: string |
| 14 | + parameters?: any |
| 15 | +} |
| 16 | + |
| 17 | +export interface StrategyResult { |
| 18 | + /** Tool call IDs that should be pruned */ |
| 19 | + prunedIds: string[] |
| 20 | + /** Optional details about what was pruned and why */ |
| 21 | + details?: Map<string, StrategyDetail> |
| 22 | +} |
| 23 | + |
| 24 | +export interface StrategyDetail { |
| 25 | + toolName: string |
| 26 | + parameterKey: string |
| 27 | + reason: string |
| 28 | + /** Additional info specific to the strategy */ |
| 29 | + [key: string]: any |
| 30 | +} |
| 31 | + |
| 32 | +export interface PruningStrategy { |
| 33 | + /** Unique identifier for this strategy */ |
| 34 | + name: string |
| 35 | + |
| 36 | + /** |
| 37 | + * Analyze tool metadata and determine which tool calls should be pruned. |
| 38 | + * |
| 39 | + * @param toolMetadata - Map of tool call ID to metadata (tool name + parameters) |
| 40 | + * @param unprunedIds - Tool call IDs that haven't been pruned yet (chronological order) |
| 41 | + * @param protectedTools - Tool names that should never be pruned |
| 42 | + * @returns IDs to prune and optional details |
| 43 | + */ |
| 44 | + detect( |
| 45 | + toolMetadata: Map<string, ToolMetadata>, |
| 46 | + unprunedIds: string[], |
| 47 | + protectedTools: string[] |
| 48 | + ): StrategyResult |
| 49 | +} |
9 | 50 |
|
10 | 51 | /** All available strategies */ |
11 | 52 | const ALL_STRATEGIES: PruningStrategy[] = [ |
|
0 commit comments