add tools.description_overrides

This commit is contained in:
Camillo Lugaresi
2026-04-07 19:05:35 -07:00
parent 600c3e49e0
commit fe7717da75
10 changed files with 282 additions and 0 deletions
+8
View File
@@ -1699,6 +1699,14 @@
"ToolsToml": {
"additionalProperties": false,
"properties": {
"description_overrides": {
"additionalProperties": {
"type": "string"
},
"default": {},
"description": "Tool descriptions keyed by tool name. Overrides only apply to tools that are enabled for the current turn.",
"type": "object"
},
"view_image": {
"default": null,
"description": "Enable the `view_image` tool that lets the agent attach local images.",
+3
View File
@@ -959,6 +959,7 @@ impl TurnContext {
})
.with_unified_exec_shell_mode(self.tools_config.unified_exec_shell_mode.clone())
.with_web_search_config(self.tools_config.web_search_config.clone())
.with_tool_description_overrides(self.tools_config.tool_description_overrides.clone())
.with_allow_login_shell(self.tools_config.allow_login_shell)
.with_has_environment(self.tools_config.has_environment)
.with_agent_type_description(crate::agent::role::spawn_tool_spec::build(
@@ -1441,6 +1442,7 @@ impl Session {
main_execve_wrapper_exe,
)
.with_web_search_config(per_turn_config.web_search_config.clone())
.with_tool_description_overrides(per_turn_config.tool_description_overrides.clone())
.with_allow_login_shell(per_turn_config.permissions.allow_login_shell)
.with_has_environment(environment.is_some())
.with_agent_type_description(crate::agent::role::spawn_tool_spec::build(
@@ -5619,6 +5621,7 @@ async fn spawn_review_thread(
sess.services.main_execve_wrapper_exe.as_ref(),
)
.with_web_search_config(/*web_search_config*/ None)
.with_tool_description_overrides(config.tool_description_overrides.clone())
.with_allow_login_shell(config.permissions.allow_login_shell)
.with_has_environment(parent_turn_context.environment.is_some())
.with_agent_type_description(crate::agent::role::spawn_tool_spec::build(
+92
View File
@@ -247,6 +247,7 @@ web_search = true
Some(ToolsToml {
web_search: None,
view_image: None,
description_overrides: BTreeMap::new(),
})
);
}
@@ -266,10 +267,97 @@ web_search = false
Some(ToolsToml {
web_search: None,
view_image: None,
description_overrides: BTreeMap::new(),
})
);
}
#[test]
fn tools_description_overrides_deserialize() {
let cfg: ConfigToml = toml::from_str(
r#"
[tools.description_overrides]
spawn_agent = "Use custom spawn guidance."
update_plan = "Use custom plan guidance."
"#,
)
.expect("TOML deserialization should succeed");
assert_eq!(
cfg.tools.expect("tools config").description_overrides,
BTreeMap::from([
(
"spawn_agent".to_string(),
"Use custom spawn guidance.".to_string()
),
(
"update_plan".to_string(),
"Use custom plan guidance.".to_string()
),
])
);
}
#[test]
fn tool_description_overrides_profile_overlays_base() -> std::io::Result<()> {
let mut cfg = ConfigToml {
tools: Some(ToolsToml {
description_overrides: BTreeMap::from([
(
"spawn_agent".to_string(),
"Base spawn guidance.".to_string(),
),
("update_plan".to_string(), "Base plan guidance.".to_string()),
]),
..Default::default()
}),
profile: Some("custom".to_string()),
..Default::default()
};
cfg.profiles.insert(
"custom".to_string(),
ConfigProfile {
tools: Some(ToolsToml {
description_overrides: BTreeMap::from([
(
"spawn_agent".to_string(),
"Profile spawn guidance.".to_string(),
),
(
"wait_agent".to_string(),
"Profile wait guidance.".to_string(),
),
]),
..Default::default()
}),
..Default::default()
},
);
let codex_home = tempdir()?;
let config = Config::load_from_base_config_with_overrides(
cfg,
ConfigOverrides::default(),
codex_home.path().to_path_buf(),
)?;
assert_eq!(
config.tool_description_overrides,
BTreeMap::from([
(
"spawn_agent".to_string(),
"Profile spawn guidance.".to_string(),
),
("update_plan".to_string(), "Base plan guidance.".to_string()),
(
"wait_agent".to_string(),
"Profile wait guidance.".to_string()
),
])
);
Ok(())
}
#[test]
fn rejects_provider_auth_with_env_key() {
let err = toml::from_str::<ConfigToml>(
@@ -4517,6 +4605,7 @@ fn test_precedence_fixture_with_o3_profile() -> std::io::Result<()> {
include_apply_patch_tool: false,
web_search_mode: Constrained::allow_any(WebSearchMode::Cached),
web_search_config: None,
tool_description_overrides: BTreeMap::new(),
use_experimental_unified_exec_tool: !cfg!(windows),
background_terminal_max_timeout: DEFAULT_MAX_BACKGROUND_TERMINAL_TIMEOUT_MS,
ghost_snapshot: GhostSnapshotConfig::default(),
@@ -4662,6 +4751,7 @@ fn test_precedence_fixture_with_gpt3_profile() -> std::io::Result<()> {
include_apply_patch_tool: false,
web_search_mode: Constrained::allow_any(WebSearchMode::Cached),
web_search_config: None,
tool_description_overrides: BTreeMap::new(),
use_experimental_unified_exec_tool: !cfg!(windows),
background_terminal_max_timeout: DEFAULT_MAX_BACKGROUND_TERMINAL_TIMEOUT_MS,
ghost_snapshot: GhostSnapshotConfig::default(),
@@ -4805,6 +4895,7 @@ fn test_precedence_fixture_with_zdr_profile() -> std::io::Result<()> {
include_apply_patch_tool: false,
web_search_mode: Constrained::allow_any(WebSearchMode::Cached),
web_search_config: None,
tool_description_overrides: BTreeMap::new(),
use_experimental_unified_exec_tool: !cfg!(windows),
background_terminal_max_timeout: DEFAULT_MAX_BACKGROUND_TERMINAL_TIMEOUT_MS,
ghost_snapshot: GhostSnapshotConfig::default(),
@@ -4934,6 +5025,7 @@ fn test_precedence_fixture_with_gpt5_profile() -> std::io::Result<()> {
include_apply_patch_tool: false,
web_search_mode: Constrained::allow_any(WebSearchMode::Cached),
web_search_config: None,
tool_description_overrides: BTreeMap::new(),
use_experimental_unified_exec_tool: !cfg!(windows),
background_terminal_max_timeout: DEFAULT_MAX_BACKGROUND_TERMINAL_TIMEOUT_MS,
ghost_snapshot: GhostSnapshotConfig::default(),
+19
View File
@@ -510,6 +510,9 @@ pub struct Config {
/// Additional parameters for the web search tool when it is enabled.
pub web_search_config: Option<WebSearchConfig>,
/// Tool descriptions keyed by tool name. Overrides only apply to enabled tools.
pub tool_description_overrides: BTreeMap<String, String>,
/// If set to `true`, used only the experimental unified exec tool.
pub use_experimental_unified_exec_tool: bool,
@@ -1279,6 +1282,20 @@ fn resolve_web_search_config(
}
}
fn resolve_tool_description_overrides(
config_toml: &ConfigToml,
config_profile: &ConfigProfile,
) -> BTreeMap<String, String> {
let mut overrides = BTreeMap::new();
if let Some(tools) = &config_toml.tools {
overrides.extend(tools.description_overrides.clone());
}
if let Some(tools) = &config_profile.tools {
overrides.extend(tools.description_overrides.clone());
}
overrides
}
pub(crate) fn resolve_web_search_mode_for_turn(
web_search_mode: &Constrained<WebSearchMode>,
sandbox_policy: &SandboxPolicy,
@@ -1607,6 +1624,7 @@ impl Config {
let web_search_mode = resolve_web_search_mode(&cfg, &config_profile, &features)
.unwrap_or(WebSearchMode::Cached);
let web_search_config = resolve_web_search_config(&cfg, &config_profile);
let tool_description_overrides = resolve_tool_description_overrides(&cfg, &config_profile);
let agent_roles =
agent_roles::load_agent_roles(&cfg, &config_layer_stack, &mut startup_warnings)?;
@@ -2037,6 +2055,7 @@ impl Config {
include_apply_patch_tool: include_apply_patch_tool_flag,
web_search_mode: constrained_web_search_mode.value,
web_search_config,
tool_description_overrides,
use_experimental_unified_exec_tool,
background_terminal_max_timeout,
ghost_snapshot,