AutoCorrectionPolicy

class AutoCorrectionPolicy(maxRetries: Int = DEFAULT_MAX_RETRIES, minTokenLength: Int = DEFAULT_MIN_TOKEN_LENGTH, minTokenSimilarity: Double = DEFAULT_MIN_TOKEN_SIMILARITY) : ToolNotFoundPolicy

Feeds the error back to the LLM with a fuzzy-match suggestion, allowing it to self-correct. Uses a two-tier matching strategy for performance. Throws ToolNotFoundException after maxRetries consecutive failures.

Matching strategy:

  1. Fast path: Simple normalization (lowercase + remove non-alphanumeric) for exact matches

  2. Fallback: Token-based similarity (Jaccard index) for fuzzy matches

Handles:

  • Delimiter variations: vector_searchvectorSearchvector-search (simple normalization)

  • Case insensitivity: VECTORSEARCHvectorSearch (simple normalization)

  • Prefix hallucinations: ragbot_vectorSearchvectorSearch (token-based)

  • Wrapped names: my_vectorSearch_v2vectorSearch (token-based)

Performance optimizations:

  • Simple normalization fast path handles ~80% of cases with O(n) complexity

  • Token-based matching only used when needed with O(n*m) complexity

  • Skips fuzzy matching for very short tool names (<minTokenLength)

  • Returns top 3 closest matches only

Parameters

maxRetries

maximum number of consecutive failures before throwing

minTokenLength

minimum token length to include in matching (performance optimization)

minTokenSimilarity

minimum Jaccard similarity (0.0-1.0) to consider a match

Constructors

Link copied to clipboard
constructor(maxRetries: Int = DEFAULT_MAX_RETRIES, minTokenLength: Int = DEFAULT_MIN_TOKEN_LENGTH, minTokenSimilarity: Double = DEFAULT_MIN_TOKEN_SIMILARITY)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun handle(requestedName: String, availableTools: List<Tool>): ToolNotFoundAction

Handle a tool-not-found event.

Link copied to clipboard
open override fun onToolFound()

Called when a tool is found successfully, allowing stateful policies to reset internal counters.