Skip to Content

previewToolSelection

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

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

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.
  • A real follow-up may also include connector tool sets carried from the previous two turns of the conversation, which this preview does not model.

Parameters

ParameterTypeDescription

options

object

‐

options.activeToolSets?

string[]

‐

options.apiKey?

string

X-API-Key auth (server-side / test harnesses). Provide this or getToken.

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>

Bearer-token auth (browser sessions). Provide this or apiKey.

options.prompt

string

‐

options.serverToolsConfig?

{ cache?: ToolsCacheBackend; cacheExpirationMs?: number; deferLoading?: DeferLoadingConfig; }

‐

options.serverToolsConfig.cache?

ToolsCacheBackend

‐

options.serverToolsConfig.cacheExpirationMs?

number

‐

options.serverToolsConfig.deferLoading?

DeferLoadingConfig

‐

options.serverToolsFilter?

string[] | ServerToolsFilterFn

‐

Returns

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

Last updated on