Skip to Content

previewToolSelection

previewToolSelection(options: object): Promise<{ clientToolNames: string[]; serverToolNames: string[]; }>

Defined in: src/react/useChatStorage.ts:301 

Preview which tools useChatStorage will include for a given prompt, without making the actual chat request.

Runs the exact same client + server tool selection pipeline that useChatStorage’s sendMessage runs internally — same embedding, same autoFilterClientTools call, same server-tools branch — so the returned names are guaranteed to match what a real request would include for that prompt + config.

Intended for debug UIs (“show me what the model will see for this prompt”). Pass the same clientTools, serverToolsFilter, extraToolSets, and activeToolSets you pass to useChatStorage so the result is faithful.

Caveats:

  • For server tools, this only mirrors the dynamic findMatchingTools path (the one used for the responses API in sendMessage). If your serverToolsFilter is a function, it’s invoked directly with the prompt embedding.
  • Embedding generation hits the same /embeddings endpoint as the real request; pass a shared clientToolEmbeddingsCache if you call this repeatedly to avoid re-embedding tool descriptions.

Parameters

ParameterTypeDescription

options

object

options.activeToolSets?

string[]

options.baseUrl?

string

options.clientToolEmbeddingsCache?

Map<string, number[]>

Optional cache of tool-description embeddings, shared across calls.

options.clientTools?

LlmapiChatCompletionTool[]

options.embeddingModel?

string

options.extraToolSets?

ToolSet[]

options.getToken

() => Promise<string | null>

options.prompt

string

options.serverToolsConfig?

{ cacheExpirationMs?: number; }

options.serverToolsConfig.cacheExpirationMs?

number

options.serverToolsFilter?

string[] | ServerToolsFilterFn

Returns

Promise<{ clientToolNames: string[]; serverToolNames: string[]; }>

Last updated on