@langchain/anthropic
Version:
Anthropic integrations for LangChain.js
108 lines (106 loc) • 3.72 kB
TypeScript
import Anthropic from "@anthropic-ai/sdk";
import { ServerTool } from "@langchain/core/tools";
//#region src/tools/toolSearch.d.ts
/**
* Options for the tool search tool.
*/
interface ToolSearchOptions {
/**
* Create a cache control breakpoint at this content block.
*/
cacheControl?: Anthropic.Beta.BetaCacheControlEphemeral;
}
/**
* Creates a regex-based tool search tool that enables Claude to work with hundreds
* or thousands of tools by dynamically discovering and loading them on-demand.
* Claude constructs regex patterns (using Python's `re.search()` syntax) to search
* for tools by name, description, argument names, and argument descriptions.
*
* @note This tool requires the beta header `advanced-tool-use-2025-11-20` in API requests.
*
* @see {@link https://docs.anthropic.com/en/docs/build-with-claude/tool-use/tool-search-tool | Anthropic Tool Search Documentation}
* @param options - Configuration options for the tool search tool
* @returns A tool search tool definition to be passed to the Anthropic API
*
* @example
* ```typescript
* import { ChatAnthropic, tools } from "@langchain/anthropic";
*
* const model = new ChatAnthropic({
* model: "claude-sonnet-4-5-20250929",
* });
*
* const getWeather = tool(
* async (input: { location: string }) => {
* return `Weather in ${input.location}`;
* },
* {
* name: "get_weather",
* description: "Get the weather at a specific location",
* schema: z.object({
* location: z.string(),
* }),
* extras: { defer_loading: true },
* },
* );
*
* // Use with deferred tools - Claude will search and discover tools as needed
* const response = await model.invoke("What is the weather in San Francisco?", {
* tools: [
* tools.toolSearchRegex_20251119(),
* getWeather,
* ],
* });
* ```
*/
declare function toolSearchRegex_20251119(options?: ToolSearchOptions): ServerTool;
/**
* Creates a BM25-based tool search tool that enables Claude to work with hundreds
* or thousands of tools by dynamically discovering and loading them on-demand.
* Claude uses natural language queries to search for tools by name, description,
* argument names, and argument descriptions.
*
* @note This tool requires the beta header `advanced-tool-use-2025-11-20` in API requests.
*
* @see {@link https://docs.anthropic.com/en/docs/build-with-claude/tool-use/tool-search-tool | Anthropic Tool Search Documentation}
* @param options - Configuration options for the tool search tool
* @returns A tool search tool definition to be passed to the Anthropic API
*
* @example
* ```typescript
* import { ChatAnthropic, tools } from "@langchain/anthropic";
*
* const model = new ChatAnthropic({
* model: "claude-sonnet-4-5-20250929",
* clientOptions: {
* defaultHeaders: { "anthropic-beta": "advanced-tool-use-2025-11-20" },
* },
* });
*
* const getWeather = tool(
* async (input: { location: string }) => {
* return `Weather in ${input.location}`;
* },
* {
* name: "get_weather",
* description: "Get the weather at a specific location",
* schema: z.object({
* location: z.string(),
* }),
* extras: { defer_loading: true },
* },
* );
*
* // Use with deferred tools - Claude will search using natural language
* const response = await model.invoke("What is the weather in San Francisco?", {
* tools: [
* tools.toolSearchBM25_20251119(),
* getWeather,
* ],
* });
* ```
*/
declare function toolSearchBM25_20251119(options?: ToolSearchOptions): ServerTool;
//#endregion
export { ToolSearchOptions, toolSearchBM25_20251119, toolSearchRegex_20251119 };
//# sourceMappingURL=toolSearch.d.ts.map