-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(anthropic): support websearch tool #9407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
8ab0863 to
3dc8c0c
Compare
1782388 to
78191d8
Compare
78191d8 to
b8f3094
Compare
8fc9755 to
adcf1de
Compare
b8f3094 to
3f43365
Compare
3f43365 to
461bc40
Compare
b593f4f to
23837dd
Compare
This PR adds support for Anthropic's Web Search tool (
web_search_20250305) to@langchain/anthropic, enabling Claude to perform real-time web searches and cite sources in its responses.Usage
Based on the direction from #9406 this would implement the websearch tool. Here is the example output from the example script:
{ messages: [ HumanMessage { "id": "c7416f2c-bea0-4e49-a3b6-384b23099211", "content": "What's the weather in NYC?", "additional_kwargs": {}, "response_metadata": {} }, AIMessage { "id": "msg_01CqUm4rR4KrgtUvemNA1gfK", "content": [ { "type": "server_tool_use", "id": "srvtoolu_01NottiD8nsS9Y4H64A1TEsb", "name": "web_search", "input": { "query": "NYC weather today" } }, { "type": "web_search_tool_result", "tool_use_id": "srvtoolu_01NottiD8nsS9Y4H64A1TEsb", "content": [ "[Object]", "[Object]", "[Object]", "[Object]", "[Object]", "[Object]", "[Object]", "[Object]", "[Object]", "[Object]" ] }, { "type": "text", "text": "Based on the latest weather information for New York City:\n\n**Today (Thursday, November 14):**\n" }, { "citations": [ "[Object]" ], "type": "text", "text": "Partly cloudy skies in the morning will give way to cloudy skies during the afternoon, with a high near 53°F and winds from the west-northwest at 10 to 15 mph." }, { "type": "text", "text": "\n\n**Tonight:**\n" }, { "citations": [ "[Object]" ], "type": "text", "text": "Mostly cloudy, then gradually becoming mostly clear, with a low around 42°F and west wind around 13 mph, with gusts as high as 24 mph." }, { "type": "text", "text": "\n\n**Recent Weather Note:**\n" }, { "citations": [ "[Object]" ], "type": "text", "text": "NYC saw its first snow of the season on Tuesday, with wintry showers during the morning commute." }, { "type": "text", "text": "\n\nThe weather is cool and breezy today with temperatures in the low 50s, typical for mid-November in New York City." } ], "name": "model", "additional_kwargs": { "model": "claude-sonnet-4-5-20250929", "id": "msg_01CqUm4rR4KrgtUvemNA1gfK", "type": "message", "role": "assistant", "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 9422, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, "output_tokens": 290, "service_tier": "standard", "server_tool_use": { "web_search_requests": 1 } } }, "response_metadata": { "model": "claude-sonnet-4-5-20250929", "id": "msg_01CqUm4rR4KrgtUvemNA1gfK", "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 9422, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, "output_tokens": 290, "service_tier": "standard", "server_tool_use": { "web_search_requests": 1 } }, "type": "message", "role": "assistant", "model_provider": "anthropic" }, "tool_calls": [], "invalid_tool_calls": [], "usage_metadata": { "input_tokens": 9422, "output_tokens": 290, "total_tokens": 9712, "input_token_details": { "cache_creation": 0, "cache_read": 0 } } } ] }