update(config): web_search=bool, web_search_config

This commit is contained in:
Fouad Matin
2026-03-10 21:11:36 -07:00
parent 78280f872a
commit c1121ac0ee
11 changed files with 263 additions and 26 deletions
@@ -16961,6 +16961,12 @@
]
},
"web_search": {
"type": [
"boolean",
"null"
]
},
"web_search_config": {
"anyOf": [
{
"$ref": "#/definitions/v2/WebSearchToolConfig"
@@ -14782,6 +14782,12 @@
]
},
"web_search": {
"type": [
"boolean",
"null"
]
},
"web_search_config": {
"anyOf": [
{
"$ref": "#/definitions/WebSearchToolConfig"
@@ -739,6 +739,12 @@
]
},
"web_search": {
"type": [
"boolean",
"null"
]
},
"web_search_config": {
"anyOf": [
{
"$ref": "#/definitions/WebSearchToolConfig"
@@ -3,4 +3,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { WebSearchToolConfig } from "../WebSearchToolConfig";
export type ToolsV2 = { web_search: WebSearchToolConfig | null, view_image: boolean | null, };
export type ToolsV2 = { web_search: boolean | null, web_search_config: WebSearchToolConfig | null, view_image: boolean | null, };
@@ -498,7 +498,9 @@ pub struct SandboxWorkspaceWrite {
#[serde(rename_all = "snake_case")]
#[ts(export_to = "v2/")]
pub struct ToolsV2 {
pub web_search: Option<WebSearchToolConfig>,
#[serde(alias = "web_search_request")]
pub web_search: Option<bool>,
pub web_search_config: Option<WebSearchToolConfig>,
pub view_image: Option<bool>,
}
+1 -1
View File
@@ -171,7 +171,7 @@ Example with notification opt-out:
- `mcpServerStatus/list` — enumerate configured MCP servers with their tools, resources, resource templates, and auth status; supports cursor+limit pagination.
- `windowsSandbox/setupStart` — start Windows sandbox setup for the selected mode (`elevated` or `unelevated`); accepts an optional absolute `cwd` to target setup for a specific workspace, returns `{ started: true }` immediately, and later emits `windowsSandbox/setupCompleted`.
- `feedback/upload` — submit a feedback report (classification + optional reason/logs, conversation_id, and optional `extraLogFiles` attachments array); returns the tracking thread id.
- `config/read` — fetch the effective config on disk after resolving config layering.
- `config/read` — fetch the effective config on disk after resolving config layering. In `tools`, `web_search` is a boolean toggle and `web_search_config` carries nested Responses web search options.
- `externalAgentConfig/detect` — detect migratable external-agent artifacts with `includeHome` and optional `cwds`; each detected item includes `cwd` (`null` for home).
- `externalAgentConfig/import` — apply selected external-agent migration items by passing explicit `migrationItems` with `cwd` (`null` for home).
- `config/value/write` — write a single config key/value to the user's config.toml on disk.
+123 -17
View File
@@ -96,12 +96,13 @@ async fn config_read_includes_tools() -> Result<()> {
r#"
model = "gpt-user"
[tools.web_search]
[tools]
web_search = true
view_image = false
[tools.web_search_config]
context_size = "low"
allowed_domains = ["example.com"]
[tools]
view_image = false
"#,
)?;
let codex_home_path = codex_home.path().canonicalize()?;
@@ -131,7 +132,8 @@ view_image = false
assert_eq!(
tools,
ToolsV2 {
web_search: Some(WebSearchToolConfig {
web_search: Some(true),
web_search_config: Some(WebSearchToolConfig {
context_size: Some(WebSearchContextSize::Low),
allowed_domains: Some(vec!["example.com".to_string()]),
location: None,
@@ -139,9 +141,15 @@ view_image = false
view_image: Some(false),
}
);
assert_eq!(
origins.get("tools.web_search").expect("origin").name,
ConfigLayerSource::User {
file: user_file.clone(),
}
);
assert_eq!(
origins
.get("tools.web_search.context_size")
.get("tools.web_search_config.context_size")
.expect("origin")
.name,
ConfigLayerSource::User {
@@ -150,7 +158,7 @@ view_image = false
);
assert_eq!(
origins
.get("tools.web_search.allowed_domains.0")
.get("tools.web_search_config.allowed_domains.0")
.expect("origin")
.name,
ConfigLayerSource::User {
@@ -178,7 +186,10 @@ async fn config_read_includes_nested_web_search_tool_config() -> Result<()> {
r#"
web_search = "live"
[tools.web_search]
[tools]
web_search = true
[tools.web_search_config]
context_size = "high"
allowed_domains = ["example.com"]
location = { country = "US", city = "New York", timezone = "America/New_York" }
@@ -202,16 +213,111 @@ location = { country = "US", city = "New York", timezone = "America/New_York" }
let ConfigReadResponse { config, .. } = to_response(resp)?;
assert_eq!(
config.tools.expect("tools present").web_search,
Some(WebSearchToolConfig {
context_size: Some(WebSearchContextSize::High),
allowed_domains: Some(vec!["example.com".to_string()]),
location: Some(WebSearchLocation {
country: Some("US".to_string()),
region: None,
city: Some("New York".to_string()),
timezone: Some("America/New_York".to_string()),
config.tools,
Some(ToolsV2 {
web_search: Some(true),
web_search_config: Some(WebSearchToolConfig {
context_size: Some(WebSearchContextSize::High),
allowed_domains: Some(vec!["example.com".to_string()]),
location: Some(WebSearchLocation {
country: Some("US".to_string()),
region: None,
city: Some("New York".to_string()),
timezone: Some("America/New_York".to_string()),
}),
}),
view_image: None,
}),
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn config_read_includes_nested_web_search_config_without_bool() -> Result<()> {
let codex_home = TempDir::new()?;
write_config(
&codex_home,
r#"
web_search = "live"
[tools.web_search_config]
context_size = "high"
allowed_domains = ["example.com"]
location = { country = "US", city = "New York", timezone = "America/New_York" }
"#,
)?;
let mut mcp = McpProcess::new(codex_home.path()).await?;
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
let request_id = mcp
.send_config_read_request(ConfigReadParams {
include_layers: false,
cwd: None,
})
.await?;
let resp: JSONRPCResponse = timeout(
DEFAULT_READ_TIMEOUT,
mcp.read_stream_until_response_message(RequestId::Integer(request_id)),
)
.await??;
let ConfigReadResponse { config, .. } = to_response(resp)?;
assert_eq!(
config.tools,
Some(ToolsV2 {
web_search: None,
web_search_config: Some(WebSearchToolConfig {
context_size: Some(WebSearchContextSize::High),
allowed_domains: Some(vec!["example.com".to_string()]),
location: Some(WebSearchLocation {
country: Some("US".to_string()),
region: None,
city: Some("New York".to_string()),
timezone: Some("America/New_York".to_string()),
}),
}),
view_image: None,
}),
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn config_read_accepts_legacy_web_search_request_key() -> Result<()> {
let codex_home = TempDir::new()?;
write_config(
&codex_home,
r#"
[tools]
web_search_request = true
"#,
)?;
let mut mcp = McpProcess::new(codex_home.path()).await?;
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
let request_id = mcp
.send_config_read_request(ConfigReadParams {
include_layers: false,
cwd: None,
})
.await?;
let resp: JSONRPCResponse = timeout(
DEFAULT_READ_TIMEOUT,
mcp.read_stream_until_response_message(RequestId::Integer(request_id)),
)
.await??;
let ConfigReadResponse { config, .. } = to_response(resp)?;
assert_eq!(
config.tools,
Some(ToolsV2 {
web_search: Some(true),
web_search_config: None,
view_image: None,
}),
);
+6 -1
View File
@@ -1502,12 +1502,17 @@
"type": "boolean"
},
"web_search": {
"default": null,
"type": "boolean"
},
"web_search_config": {
"allOf": [
{
"$ref": "#/definitions/WebSearchToolConfig"
}
],
"default": null
"default": null,
"description": "Additional parameters for the native `web_search` tool."
}
},
"type": "object"
+99
View File
@@ -14,6 +14,11 @@ use crate::config_loader::RequirementSource;
use crate::features::Feature;
use assert_matches::assert_matches;
use codex_config::CONFIG_TOML_FILE;
use codex_protocol::config_types::WebSearchContextSize;
use codex_protocol::config_types::WebSearchFilters;
use codex_protocol::config_types::WebSearchLocation;
use codex_protocol::config_types::WebSearchUserLocation;
use codex_protocol::config_types::WebSearchUserLocationType;
use codex_protocol::permissions::FileSystemAccessMode;
use codex_protocol::permissions::FileSystemPath;
use codex_protocol::permissions::FileSystemSandboxEntry;
@@ -1374,6 +1379,100 @@ fn web_search_mode_disabled_overrides_legacy_request() {
);
}
#[test]
fn web_search_config_reads_tools_web_search_config() {
let cfg = ConfigToml {
tools: Some(ToolsToml {
web_search: Some(true),
web_search_config: Some(WebSearchToolConfig {
context_size: Some(WebSearchContextSize::High),
allowed_domains: Some(vec!["example.com".to_string()]),
location: Some(WebSearchLocation {
country: Some("US".to_string()),
region: None,
city: Some("New York".to_string()),
timezone: Some("America/New_York".to_string()),
}),
}),
view_image: None,
}),
..Default::default()
};
let profile = ConfigProfile::default();
assert_eq!(
resolve_web_search_config(&cfg, &profile),
Some(WebSearchConfig {
filters: Some(WebSearchFilters {
allowed_domains: Some(vec!["example.com".to_string()]),
}),
user_location: Some(WebSearchUserLocation {
r#type: WebSearchUserLocationType::Approximate,
country: Some("US".to_string()),
region: None,
city: Some("New York".to_string()),
timezone: Some("America/New_York".to_string()),
}),
search_context_size: Some(WebSearchContextSize::High),
}),
);
}
#[test]
fn web_search_config_profile_overrides_base_values() {
let cfg = ConfigToml {
tools: Some(ToolsToml {
web_search: Some(true),
web_search_config: Some(WebSearchToolConfig {
context_size: Some(WebSearchContextSize::Low),
allowed_domains: Some(vec!["example.com".to_string()]),
location: Some(WebSearchLocation {
country: Some("US".to_string()),
region: Some("CA".to_string()),
city: None,
timezone: Some("America/Los_Angeles".to_string()),
}),
}),
view_image: None,
}),
..Default::default()
};
let profile = ConfigProfile {
tools: Some(ToolsToml {
web_search: None,
web_search_config: Some(WebSearchToolConfig {
context_size: Some(WebSearchContextSize::High),
allowed_domains: None,
location: Some(WebSearchLocation {
country: None,
region: Some("NY".to_string()),
city: Some("New York".to_string()),
timezone: None,
}),
}),
view_image: None,
}),
..Default::default()
};
assert_eq!(
resolve_web_search_config(&cfg, &profile),
Some(WebSearchConfig {
filters: Some(WebSearchFilters {
allowed_domains: Some(vec!["example.com".to_string()]),
}),
user_location: Some(WebSearchUserLocation {
r#type: WebSearchUserLocationType::Approximate,
country: Some("US".to_string()),
region: Some("NY".to_string()),
city: Some("New York".to_string()),
timezone: Some("America/Los_Angeles".to_string()),
}),
search_context_size: Some(WebSearchContextSize::High),
}),
);
}
#[test]
fn web_search_mode_for_turn_uses_preference_for_read_only() {
let web_search_mode = Constrained::allow_any(WebSearchMode::Cached);
+8 -4
View File
@@ -1392,8 +1392,12 @@ pub struct RealtimeAudioToml {
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, JsonSchema)]
#[schemars(deny_unknown_fields)]
pub struct ToolsToml {
#[serde(default, alias = "web_search_request")]
pub web_search: Option<bool>,
/// Additional parameters for the native `web_search` tool.
#[serde(default)]
pub web_search: Option<WebSearchToolConfig>,
pub web_search_config: Option<WebSearchToolConfig>,
/// Enable the `view_image` tool that lets the agent attach local images.
#[serde(default)]
@@ -1457,7 +1461,7 @@ pub struct AgentRoleToml {
impl From<ToolsToml> for Tools {
fn from(tools_toml: ToolsToml) -> Self {
Self {
web_search: tools_toml.web_search.is_some().then_some(true),
web_search: tools_toml.web_search,
view_image: tools_toml.view_image,
}
}
@@ -1756,11 +1760,11 @@ fn resolve_web_search_config(
let base = config_toml
.tools
.as_ref()
.and_then(|tools| tools.web_search.as_ref());
.and_then(|tools| tools.web_search_config.as_ref());
let profile = config_profile
.tools
.as_ref()
.and_then(|tools| tools.web_search.as_ref());
.and_then(|tools| tools.web_search_config.as_ref());
match (base, profile) {
(None, None) => None,
+4 -1
View File
@@ -242,7 +242,10 @@ async fn web_search_tool_config_from_config_toml_is_forwarded_to_request() {
home.path().join("config.toml"),
r#"web_search = "live"
[tools.web_search]
[tools]
web_search = true
[tools.web_search_config]
context_size = "high"
allowed_domains = ["example.com"]
location = { country = "US", city = "New York", timezone = "America/New_York" }