Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/src/provider/anthropic/websearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createAgent, HumanMessage } from "langchain";
import { ChatAnthropic, tools } from "@langchain/anthropic";

const model = new ChatAnthropic({
model: "claude-sonnet-4-5-20250929",
});

const agent = createAgent({
model,
tools: [
tools.webSearch_20250305({
maxUses: 5,
}),
],
});

const result = await agent.invoke({
messages: [new HumanMessage("What's the weather in NYC?")],
});

console.log(result);
5 changes: 4 additions & 1 deletion libs/langchain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"allowJs": true,
"strict": true
},
"include": ["src/**/*"],
"include": [
"src/**/*",
"../providers/langchain-anthropic/src/tools/utils/FileData.ts"
],
"exclude": ["node_modules", "dist", "docs"]
}
2 changes: 2 additions & 0 deletions libs/providers/langchain-anthropic/src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { memory, memory_20250818 } from "./memory.js";
import { webSearch_20250305 } from "./websearch.js";

export type { FileSystem } from "./utils/FileSystem.js";
export { StateFileSystem } from "./utils/StateFileSystem.js";

export const tools = {
memory_20250818,
memory,
webSearch_20250305,
};
38 changes: 38 additions & 0 deletions libs/providers/langchain-anthropic/src/tools/websearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Anthropic from "@anthropic-ai/sdk";

import { tool, type DynamicStructuredTool } from "@langchain/core/tools";

interface WebSearchOptions {
maxUses?: number;
allowedDomains?: string[];
blockedDomains?: string[];
userLocation?: Anthropic.Beta.BetaWebSearchTool20250305.UserLocation;
}

export function webSearch_20250305(
options?: WebSearchOptions
): DynamicStructuredTool {
const webSearchTool = tool(
() => {
// not implemented
},
{
name: "web_search",
description: "Web search tool",
schema: {},
}
);

webSearchTool.metadata = {
providerToolDefinition: {
type: "web_search_20250305",
name: "web_search",
max_uses: options?.maxUses,
allowed_domains: options?.allowedDomains,
blocked_domains: options?.blockedDomains,
user_location: options?.userLocation,
},
};

return webSearchTool;
}
Loading