Skip to content

Commit 1dc7bc6

Browse files
authored
Add Anthropic web_search settings and wire into BYOK provider (#1783)
* Add Anthropic web_search settings and wire into BYOK provider * Mark Anthropic websearch configuration options as experimental
1 parent e5018e7 commit 1dc7bc6

File tree

4 files changed

+105
-3
lines changed

4 files changed

+105
-3
lines changed

package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,67 @@
32303230
"onExp"
32313231
]
32323232
},
3233+
"github.copilot.chat.anthropic.tools.websearch.maxUses": {
3234+
"type": "number",
3235+
"default": 5,
3236+
"markdownDescription": "%github.copilot.config.anthropic.tools.websearch.maxUses%",
3237+
"minimum": 1,
3238+
"maximum": 20,
3239+
"tags": [
3240+
"experimental"
3241+
]
3242+
},
3243+
"github.copilot.chat.anthropic.tools.websearch.allowedDomains": {
3244+
"type": "array",
3245+
"default": [],
3246+
"markdownDescription": "%github.copilot.config.anthropic.tools.websearch.allowedDomains%",
3247+
"items": {
3248+
"type": "string"
3249+
},
3250+
"tags": [
3251+
"experimental"
3252+
]
3253+
},
3254+
"github.copilot.chat.anthropic.tools.websearch.blockedDomains": {
3255+
"type": "array",
3256+
"default": [],
3257+
"markdownDescription": "%github.copilot.config.anthropic.tools.websearch.blockedDomains%",
3258+
"items": {
3259+
"type": "string"
3260+
},
3261+
"tags": [
3262+
"experimental"
3263+
]
3264+
},
3265+
"github.copilot.chat.anthropic.tools.websearch.userLocation": {
3266+
"type": [
3267+
"object",
3268+
"null"
3269+
],
3270+
"default": null,
3271+
"markdownDescription": "%github.copilot.config.anthropic.tools.websearch.userLocation%",
3272+
"properties": {
3273+
"city": {
3274+
"type": "string",
3275+
"description": "City name (e.g., 'San Francisco')"
3276+
},
3277+
"region": {
3278+
"type": "string",
3279+
"description": "State or region (e.g., 'California')"
3280+
},
3281+
"country": {
3282+
"type": "string",
3283+
"description": "ISO country code (e.g., 'US')"
3284+
},
3285+
"timezone": {
3286+
"type": "string",
3287+
"description": "IANA timezone identifier (e.g., 'America/Los_Angeles')"
3288+
}
3289+
},
3290+
"tags": [
3291+
"experimental"
3292+
]
3293+
},
32333294
"github.copilot.chat.tools.memory.enabled": {
32343295
"type": "boolean",
32353296
"default": false,

package.nls.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@
347347
"github.copilot.config.anthropic.thinking.enabled": "Enable extended thinking for Anthropic models that support it. \n\n **Note**: This is an experimental feature only supported in BYOK Anthropic models.",
348348
"github.copilot.config.anthropic.thinking.maxTokens": "Maximum number of tokens to allocate for extended thinking in Anthropic models. Valid range is 1,024 to 32,000 tokens. Always capped at (max output tokens - 1).\n\n**Note**: This is an experimental feature only supported in BYOK Anthropic models.",
349349
"github.copilot.config.anthropic.tools.websearch.enabled": "Enable Anthropic's native web search tool for BYOK Claude models. When enabled, allows Claude to search the web for current information. \n\n**Note**: This is an experimental feature only available for BYOK Anthropic Claude models.",
350+
"github.copilot.config.anthropic.tools.websearch.maxUses": "Maximum number of web searches allowed per request. Valid range is 1 to 20. Prevents excessive API calls within a single interaction. If Claude exceeds this limit, the response returns an error.",
351+
"github.copilot.config.anthropic.tools.websearch.allowedDomains": "List of domains to restrict web search results to (e.g., `[\"example.com\", \"docs.example.com\"]`). Domains should not include the HTTP/HTTPS scheme. Subdomains are automatically included. Cannot be used together with blocked domains.",
352+
"github.copilot.config.anthropic.tools.websearch.blockedDomains": "List of domains to exclude from web search results (e.g., `[\"untrustedsource.com\"]`). Domains should not include the HTTP/HTTPS scheme. Subdomains are automatically excluded. Cannot be used together with allowed domains.",
353+
"github.copilot.config.anthropic.tools.websearch.userLocation": "User location for personalizing web search results based on geographic context. All fields (city, region, country, timezone) are optional. Example: `{\"city\": \"San Francisco\", \"region\": \"California\", \"country\": \"US\", \"timezone\": \"America/Los_Angeles\"}`",
350354
"github.copilot.config.tools.memory.enabled": "Enable memory tool to allow models to store and retrieve information across conversations. \n\n**Note**: This is an experimental feature.",
351355
"github.copilot.config.completionsFetcher": "Sets the fetcher used for the inline completions.",
352356
"github.copilot.config.nesFetcher": "Sets the fetcher used for the next edit suggestions.",

src/extension/byok/vscode-node/anthropicProvider.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,35 @@ export class AnthropicLMProvider implements BYOKModelProvider<LanguageModelChatI
216216
// We need to do this because there is no local web_search tool definition we can replace.
217217
const webSearchEnabled = this._configurationService.getExperimentBasedConfig(ConfigKey.AnthropicWebSearchToolEnabled, this._experimentationService);
218218
if (webSearchEnabled && !tools.some(tool => tool.name === 'web_search')) {
219-
tools.push({
219+
const maxUses = this._configurationService.getConfig(ConfigKey.AnthropicWebSearchMaxUses);
220+
const allowedDomains = this._configurationService.getConfig(ConfigKey.AnthropicWebSearchAllowedDomains);
221+
const blockedDomains = this._configurationService.getConfig(ConfigKey.AnthropicWebSearchBlockedDomains);
222+
const userLocation = this._configurationService.getConfig(ConfigKey.AnthropicWebSearchUserLocation);
223+
224+
const webSearchTool: Anthropic.Beta.BetaWebSearchTool20250305 = {
220225
name: 'web_search',
221226
type: 'web_search_20250305',
222-
max_uses: 5
223-
});
227+
max_uses: maxUses
228+
};
229+
230+
// Add domain filtering if configured
231+
// Cannot use both allowed and blocked domains simultaneously
232+
if (allowedDomains && allowedDomains.length > 0) {
233+
webSearchTool.allowed_domains = allowedDomains;
234+
} else if (blockedDomains && blockedDomains.length > 0) {
235+
webSearchTool.blocked_domains = blockedDomains;
236+
}
237+
238+
// Add user location if configured
239+
// Note: All fields are optional according to Anthropic docs
240+
if (userLocation && (userLocation.city || userLocation.region || userLocation.country || userLocation.timezone)) {
241+
webSearchTool.user_location = {
242+
type: 'approximate',
243+
...userLocation
244+
};
245+
}
246+
247+
tools.push(webSearchTool);
224248
}
225249

226250
const thinkingEnabled = this._enableThinking(model.id);

src/platform/configuration/common/configurationService.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,19 @@ export namespace ConfigKey {
764764
export const MaxAnthropicThinkingTokens = defineSetting<number | null>('chat.anthropic.thinking.maxTokens', null);
765765
/** Enable Anthropic web search tool for BYOK Claude models */
766766
export const AnthropicWebSearchToolEnabled = defineExpSetting<boolean>('chat.anthropic.tools.websearch.enabled', false);
767+
/** Maximum number of web searches allowed per request */
768+
export const AnthropicWebSearchMaxUses = defineSetting<number>('chat.anthropic.tools.websearch.maxUses', 5);
769+
/** List of domains to restrict web search results to */
770+
export const AnthropicWebSearchAllowedDomains = defineSetting<string[]>('chat.anthropic.tools.websearch.allowedDomains', []);
771+
/** List of domains to exclude from web search results */
772+
export const AnthropicWebSearchBlockedDomains = defineSetting<string[]>('chat.anthropic.tools.websearch.blockedDomains', []);
773+
/** User location for personalizing web search results */
774+
export const AnthropicWebSearchUserLocation = defineSetting<{
775+
city?: string;
776+
region?: string;
777+
country?: string;
778+
timezone?: string;
779+
} | null>('chat.anthropic.tools.websearch.userLocation', null);
767780
/** Enable memory tool */
768781
export const MemoryToolEnabled = defineExpSetting<boolean>('chat.tools.memory.enabled', false);
769782

0 commit comments

Comments
 (0)