web search mode

This commit is contained in:
ashwinnathan-openai
2026-03-16 18:22:53 -07:00
parent b3b0ce3645
commit eb50e97cf1
2 changed files with 38 additions and 3 deletions

View File

@@ -508,6 +508,14 @@ impl ToolsConfig {
}
fn is_tool_capability_enabled(&self, capability: ToolCapabilityKey) -> bool {
if matches!(capability, ToolCapabilityKey::WebSearch) {
// The resolved web_search_mode already reflects config, feature defaults,
// and any requirement-driven overrides.
return self
.web_search_mode
.is_some_and(|mode| mode != WebSearchMode::Disabled);
}
if let Some(enabled_tool_capabilities) = self.enabled_tool_capabilities.as_ref() {
return enabled_tool_capabilities.contains(capability.capability_name());
}
@@ -524,9 +532,6 @@ impl ToolsConfig {
ToolCapabilityKey::ApplyPatch => self.apply_patch_tool_type.is_some(),
ToolCapabilityKey::UpdatePlan => true,
ToolCapabilityKey::RequestUserInput => self.request_user_input,
ToolCapabilityKey::WebSearch => self
.web_search_mode
.is_some_and(|mode| mode != WebSearchMode::Disabled),
ToolCapabilityKey::ImageGeneration => self.image_gen_tool,
ToolCapabilityKey::ViewImage => self.legacy_view_image_override.unwrap_or(true),
ToolCapabilityKey::Artifacts => self.artifact_tools,

View File

@@ -1174,6 +1174,36 @@ fn web_search_mode_live_sets_external_web_access_true() {
);
}
#[test]
fn web_search_mode_overrides_enabled_tool_capabilities() {
let features = Features::with_defaults();
let available_models = Vec::new();
let tools_config = ToolsConfig::new(&ToolsConfigParams {
model_info: &search_capable_model_info(),
available_models: &available_models,
features: &features,
web_search_mode: Some(WebSearchMode::Live),
session_source: SessionSource::Cli,
sandbox_policy: &SandboxPolicy::DangerFullAccess,
windows_sandbox_level: WindowsSandboxLevel::Disabled,
})
.with_enabled_tool_capabilities(Some(BTreeSet::from(["shell".to_string()])));
let (tools, _) = build_specs(&tools_config, None, None, &[]).build();
let tool = find_tool(&tools, "web_search");
assert_eq!(
tool.spec,
ToolSpec::WebSearch {
external_web_access: Some(true),
filters: None,
user_location: None,
search_context_size: None,
search_content_types: None,
}
);
}
#[test]
fn web_search_config_is_forwarded_to_tool_spec() {
let config = test_config();