mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
add tools.description_overrides
This commit is contained in:
@@ -14,6 +14,7 @@ use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
@@ -110,6 +111,7 @@ pub struct ToolsConfig {
|
||||
pub agent_jobs_tools: bool,
|
||||
pub agent_jobs_worker_tools: bool,
|
||||
pub agent_type_description: String,
|
||||
pub tool_description_overrides: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
pub struct ToolsConfigParams<'a> {
|
||||
@@ -225,6 +227,7 @@ impl ToolsConfig {
|
||||
agent_jobs_tools: include_agent_jobs,
|
||||
agent_jobs_worker_tools,
|
||||
agent_type_description: String::new(),
|
||||
tool_description_overrides: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,6 +236,14 @@ impl ToolsConfig {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_tool_description_overrides(
|
||||
mut self,
|
||||
tool_description_overrides: BTreeMap<String, String>,
|
||||
) -> Self {
|
||||
self.tool_description_overrides = tool_description_overrides;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_allow_login_shell(mut self, allow_login_shell: bool) -> Self {
|
||||
self.allow_login_shell = allow_login_shell;
|
||||
self
|
||||
|
||||
@@ -491,6 +491,22 @@ pub fn build_tool_registry_plan(
|
||||
}
|
||||
}
|
||||
|
||||
if !config.tool_description_overrides.is_empty() {
|
||||
for configured_tool in &mut plan.specs {
|
||||
let Some(override_description) = config
|
||||
.tool_description_overrides
|
||||
.get(configured_tool.name())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let Some(description) = configured_tool.spec.description_mut() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
*description = override_description.clone();
|
||||
}
|
||||
}
|
||||
|
||||
plan
|
||||
}
|
||||
|
||||
|
||||
@@ -179,6 +179,74 @@ fn test_build_specs_collab_tools_enabled() {
|
||||
assert!(!properties.contains_key("fork_turns"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_description_override_replaces_enabled_tool_description() {
|
||||
let model_info = model_info();
|
||||
let mut features = Features::with_defaults();
|
||||
features.enable(Feature::Collab);
|
||||
let available_models = Vec::new();
|
||||
let mut overrides = BTreeMap::new();
|
||||
overrides.insert(
|
||||
"spawn_agent".to_string(),
|
||||
"Use this custom spawn guidance.".to_string(),
|
||||
);
|
||||
let tools_config = ToolsConfig::new(&ToolsConfigParams {
|
||||
model_info: &model_info,
|
||||
available_models: &available_models,
|
||||
features: &features,
|
||||
web_search_mode: Some(WebSearchMode::Cached),
|
||||
session_source: SessionSource::Cli,
|
||||
sandbox_policy: &SandboxPolicy::DangerFullAccess,
|
||||
windows_sandbox_level: WindowsSandboxLevel::Disabled,
|
||||
})
|
||||
.with_tool_description_overrides(overrides);
|
||||
|
||||
let (tools, _) = build_specs(
|
||||
&tools_config,
|
||||
/*mcp_tools*/ None,
|
||||
/*app_tools*/ None,
|
||||
&[],
|
||||
);
|
||||
let ToolSpec::Function(ResponsesApiTool { description, .. }) =
|
||||
&find_tool(&tools, "spawn_agent").spec
|
||||
else {
|
||||
panic!("expected spawn_agent function tool");
|
||||
};
|
||||
|
||||
assert_eq!(description, "Use this custom spawn guidance.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_description_override_for_disabled_tool_is_ignored() {
|
||||
let model_info = model_info();
|
||||
let features = Features::with_defaults();
|
||||
let available_models = Vec::new();
|
||||
let mut overrides = BTreeMap::new();
|
||||
overrides.insert(
|
||||
"spawn_agents_on_csv".to_string(),
|
||||
"Use this custom batch guidance.".to_string(),
|
||||
);
|
||||
let tools_config = ToolsConfig::new(&ToolsConfigParams {
|
||||
model_info: &model_info,
|
||||
available_models: &available_models,
|
||||
features: &features,
|
||||
web_search_mode: Some(WebSearchMode::Cached),
|
||||
session_source: SessionSource::Cli,
|
||||
sandbox_policy: &SandboxPolicy::DangerFullAccess,
|
||||
windows_sandbox_level: WindowsSandboxLevel::Disabled,
|
||||
})
|
||||
.with_tool_description_overrides(overrides);
|
||||
|
||||
let (tools, _) = build_specs(
|
||||
&tools_config,
|
||||
/*mcp_tools*/ None,
|
||||
/*app_tools*/ None,
|
||||
&[],
|
||||
);
|
||||
|
||||
assert_lacks_tool_name(&tools, "spawn_agents_on_csv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_specs_multi_agent_v2_uses_task_names_and_hides_resume() {
|
||||
let model_info = model_info();
|
||||
@@ -1660,6 +1728,43 @@ fn code_mode_only_exec_description_includes_full_nested_tool_details() {
|
||||
assert!(description.contains("### `view_image` (`view_image`)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_mode_only_exec_description_uses_nested_tool_description_overrides() {
|
||||
let model_info = model_info();
|
||||
let mut features = Features::with_defaults();
|
||||
features.enable(Feature::CodeMode);
|
||||
features.enable(Feature::CodeModeOnly);
|
||||
let available_models = Vec::new();
|
||||
let mut overrides = BTreeMap::new();
|
||||
overrides.insert(
|
||||
"update_plan".to_string(),
|
||||
"Use this custom plan guidance.".to_string(),
|
||||
);
|
||||
let tools_config = ToolsConfig::new(&ToolsConfigParams {
|
||||
model_info: &model_info,
|
||||
available_models: &available_models,
|
||||
features: &features,
|
||||
web_search_mode: Some(WebSearchMode::Cached),
|
||||
session_source: SessionSource::Cli,
|
||||
sandbox_policy: &SandboxPolicy::DangerFullAccess,
|
||||
windows_sandbox_level: WindowsSandboxLevel::Disabled,
|
||||
})
|
||||
.with_tool_description_overrides(overrides);
|
||||
|
||||
let (tools, _) = build_specs(
|
||||
&tools_config,
|
||||
/*mcp_tools*/ None,
|
||||
/*app_tools*/ None,
|
||||
&[],
|
||||
);
|
||||
let ToolSpec::Freeform(FreeformTool { description, .. }) = &find_tool(&tools, "exec").spec
|
||||
else {
|
||||
panic!("expected freeform tool");
|
||||
};
|
||||
|
||||
assert!(description.contains("Use this custom plan guidance."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_mode_exec_description_omits_nested_tool_details_when_not_code_mode_only() {
|
||||
let model_info = model_info();
|
||||
|
||||
@@ -64,6 +64,17 @@ impl ToolSpec {
|
||||
ToolSpec::Freeform(tool) => tool.name.as_str(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn description_mut(&mut self) -> Option<&mut String> {
|
||||
match self {
|
||||
ToolSpec::Function(tool) => Some(&mut tool.description),
|
||||
ToolSpec::ToolSearch { description, .. } => Some(description),
|
||||
ToolSpec::Freeform(tool) => Some(&mut tool.description),
|
||||
ToolSpec::LocalShell {}
|
||||
| ToolSpec::ImageGeneration { .. }
|
||||
| ToolSpec::WebSearch { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_local_shell_tool() -> ToolSpec {
|
||||
|
||||
Reference in New Issue
Block a user