@langchain/anthropic
Version:
Anthropic integrations for LangChain.js
1 lines • 4.54 kB
Source Map (JSON)
{"version":3,"file":"toolSearch.cjs","names":["options?: ToolSearchOptions"],"sources":["../../src/tools/toolSearch.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { type ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Options for the tool search tool.\n */\nexport interface ToolSearchOptions {\n /**\n * Create a cache control breakpoint at this content block.\n */\n cacheControl?: Anthropic.Beta.BetaCacheControlEphemeral;\n}\n\n/**\n * Creates a regex-based tool search tool that enables Claude to work with hundreds\n * or thousands of tools by dynamically discovering and loading them on-demand.\n * Claude constructs regex patterns (using Python's `re.search()` syntax) to search\n * for tools by name, description, argument names, and argument descriptions.\n *\n * @note This tool requires the beta header `advanced-tool-use-2025-11-20` in API requests.\n *\n * @see {@link https://docs.anthropic.com/en/docs/build-with-claude/tool-use/tool-search-tool | Anthropic Tool Search Documentation}\n * @param options - Configuration options for the tool search tool\n * @returns A tool search tool definition to be passed to the Anthropic API\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const model = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * const getWeather = tool(\n * async (input: { location: string }) => {\n * return `Weather in ${input.location}`;\n * },\n * {\n * name: \"get_weather\",\n * description: \"Get the weather at a specific location\",\n * schema: z.object({\n * location: z.string(),\n * }),\n * extras: { defer_loading: true },\n * },\n * );\n *\n * // Use with deferred tools - Claude will search and discover tools as needed\n * const response = await model.invoke(\"What is the weather in San Francisco?\", {\n * tools: [\n * tools.toolSearchRegex_20251119(),\n * getWeather,\n * ],\n * });\n * ```\n */\nexport function toolSearchRegex_20251119(\n options?: ToolSearchOptions\n): ServerTool {\n return {\n type: \"tool_search_tool_regex_20251119\",\n name: \"tool_search_tool_regex\",\n cache_control: options?.cacheControl,\n } satisfies Anthropic.Beta.Messages.BetaToolSearchToolRegex20251119;\n}\n\n/**\n * Creates a BM25-based tool search tool that enables Claude to work with hundreds\n * or thousands of tools by dynamically discovering and loading them on-demand.\n * Claude uses natural language queries to search for tools by name, description,\n * argument names, and argument descriptions.\n *\n * @note This tool requires the beta header `advanced-tool-use-2025-11-20` in API requests.\n *\n * @see {@link https://docs.anthropic.com/en/docs/build-with-claude/tool-use/tool-search-tool | Anthropic Tool Search Documentation}\n * @param options - Configuration options for the tool search tool\n * @returns A tool search tool definition to be passed to the Anthropic API\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const model = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * clientOptions: {\n * defaultHeaders: { \"anthropic-beta\": \"advanced-tool-use-2025-11-20\" },\n * },\n * });\n *\n * const getWeather = tool(\n * async (input: { location: string }) => {\n * return `Weather in ${input.location}`;\n * },\n * {\n * name: \"get_weather\",\n * description: \"Get the weather at a specific location\",\n * schema: z.object({\n * location: z.string(),\n * }),\n * extras: { defer_loading: true },\n * },\n * );\n *\n * // Use with deferred tools - Claude will search using natural language\n * const response = await model.invoke(\"What is the weather in San Francisco?\", {\n * tools: [\n * tools.toolSearchBM25_20251119(),\n * getWeather,\n * ],\n * });\n * ```\n */\nexport function toolSearchBM25_20251119(\n options?: ToolSearchOptions\n): ServerTool {\n return {\n type: \"tool_search_tool_bm25_20251119\",\n name: \"tool_search_tool_bm25\",\n cache_control: options?.cacheControl,\n } satisfies Anthropic.Beta.Messages.BetaToolSearchToolBm25_20251119;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,yBACdA,SACY;AACZ,QAAO;EACL,MAAM;EACN,MAAM;EACN,eAAe,SAAS;CACzB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDD,SAAgB,wBACdA,SACY;AACZ,QAAO;EACL,MAAM;EACN,MAAM;EACN,eAAe,SAAS;CACzB;AACF"}