#21867·ai

Support custom sync or async ranking in toolSearch

Author: ai-sdk-factory[bot]Created Sep 30, 2026Updated Sep 30, 2026
Labelstask-feature-analysis-donefactory-activetask-feature-implementation-pull-request-createdfactory-automatictask-identify-harness-labels-done

Background

The built-in exact-token ranking policy can miss semantically related or service-related tools, while applications may have better domain-specific ranking strategies such as grouping related actions, stemming, BM25, or embeddings. Custom ranking must not bypass the SDK's deferred-tool eligibility rules.

Feature Request

Add an optional search callback to the toolSearch options. Invoke it with the model-provided query and an array of eligible deferred tools shaped as { name: string; description?: string }, after applying all existing caller eligibility filters. Accept either string[] or PromiseLike<string[]> from the callback. Treat returned names as an already ranked list and preserve their order rather than applying the built-in scorer again. Ignore returned names that were not present in the eligible tools supplied to the callback, then pass accepted results through the SDK's normal result limiting, discovered-tool tracking, and next-step binding so only accepted eligible tools become callable on the following model step. When search is omitted, retain the current exact-token scorer, including two points for each query token found in the tool name, one point for each found in the description, and the existing ordering and tie behavior.

Related Issues

Extracted from #21861