Skip to Content

useTools

useTools(options: object): UseToolsResult

Defined in: src/react/useTools.ts:84 

React hook for fetching and caching server-side tools.

This hook provides:

  • Automatic fetching of tools on mount
  • Caching with localStorage persistence
  • Checksum-based cache invalidation
  • Automatic refresh when tools change on the server

Parameters

ParameterTypeDescription

options

object

options.autoFetch?

boolean

Whether to fetch tools automatically on mount (default: true)

options.baseUrl?

string

Optional base URL for the API requests.

options.getToken

() => Promise<string | null>

Custom function to get auth token for API calls

options.includeTools?

string[]

Filter to include only specific tools by name.

  • undefined: include all tools
  • []: include no tools
  • [‘tool1’, ‘tool2’]: include only named tools

Returns

UseToolsResult

Example

const { tools, checkForUpdates, refresh } = useTools({ getToken: async () => authToken, }); // After sending a message, check if tools need refresh const result = await sendMessage({ messages, model }); checkForUpdates(result.toolsChecksum);
Last updated on