Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions codex-rs/core/src/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ impl Session {
use_streamable_shell_tool: config.use_experimental_streamable_shell_tool,
include_view_image_tool: config.include_view_image_tool,
experimental_unified_exec_tool: config.use_experimental_unified_exec_tool,
disable_builtin_tools: config.disable_builtin_tools,
}),
user_instructions,
base_instructions,
Expand Down Expand Up @@ -1201,6 +1202,7 @@ async fn submission_loop(
use_streamable_shell_tool: config.use_experimental_streamable_shell_tool,
include_view_image_tool: config.include_view_image_tool,
experimental_unified_exec_tool: config.use_experimental_unified_exec_tool,
disable_builtin_tools: config.disable_builtin_tools,
});

let new_turn_context = TurnContext {
Expand Down Expand Up @@ -1305,6 +1307,7 @@ async fn submission_loop(
include_view_image_tool: config.include_view_image_tool,
experimental_unified_exec_tool: config
.use_experimental_unified_exec_tool,
disable_builtin_tools: config.disable_builtin_tools,
}),
user_instructions: turn_context.user_instructions.clone(),
base_instructions: turn_context.base_instructions.clone(),
Expand Down Expand Up @@ -1544,6 +1547,7 @@ async fn spawn_review_thread(
use_streamable_shell_tool: false,
include_view_image_tool: false,
experimental_unified_exec_tool: config.use_experimental_unified_exec_tool,
disable_builtin_tools: config.disable_builtin_tools,
});

let base_instructions = REVIEW_PROMPT.to_string();
Expand Down Expand Up @@ -2756,6 +2760,7 @@ mod tests {
use_streamable_shell_tool: config.use_experimental_streamable_shell_tool,
include_view_image_tool: config.include_view_image_tool,
experimental_unified_exec_tool: config.use_experimental_unified_exec_tool,
disable_builtin_tools: config.disable_builtin_tools,
});
let turn_context = TurnContext {
client,
Expand Down
11 changes: 11 additions & 0 deletions codex-rs/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ pub struct Config {
/// Include the `view_image` tool that lets the agent attach a local image path to context.
pub include_view_image_tool: bool,

/// When true, disables all built-in tools (shell, read_file, list_dir, grep_files, apply_patch).
/// MCP tools and web search remain available if configured.
pub disable_builtin_tools: bool,

/// The active profile name used to derive this `Config` (if any).
pub active_profile: Option<String>,

Expand Down Expand Up @@ -957,6 +961,7 @@ pub struct ConfigOverrides {
pub include_view_image_tool: Option<bool>,
pub show_raw_agent_reasoning: Option<bool>,
pub tools_web_search_request: Option<bool>,
pub disable_builtin_tools: Option<bool>,
}

impl Config {
Expand Down Expand Up @@ -985,6 +990,7 @@ impl Config {
include_view_image_tool,
show_raw_agent_reasoning,
tools_web_search_request: override_tools_web_search_request,
disable_builtin_tools,
} = overrides;

let active_profile_name = config_profile_key
Expand Down Expand Up @@ -1177,6 +1183,7 @@ impl Config {
.unwrap_or(false),
use_experimental_use_rmcp_client: cfg.experimental_use_rmcp_client.unwrap_or(false),
include_view_image_tool,
disable_builtin_tools: disable_builtin_tools.unwrap_or(false),
active_profile: active_profile_name,
windows_wsl_setup_acknowledged: cfg.windows_wsl_setup_acknowledged.unwrap_or(false),
disable_paste_burst: cfg.disable_paste_burst.unwrap_or(false),
Expand Down Expand Up @@ -2120,6 +2127,7 @@ model_verbosity = "high"
use_experimental_unified_exec_tool: false,
use_experimental_use_rmcp_client: false,
include_view_image_tool: true,
disable_builtin_tools: false,
active_profile: Some("o3".to_string()),
windows_wsl_setup_acknowledged: false,
disable_paste_burst: false,
Expand Down Expand Up @@ -2183,6 +2191,7 @@ model_verbosity = "high"
use_experimental_unified_exec_tool: false,
use_experimental_use_rmcp_client: false,
include_view_image_tool: true,
disable_builtin_tools: false,
active_profile: Some("gpt3".to_string()),
windows_wsl_setup_acknowledged: false,
disable_paste_burst: false,
Expand Down Expand Up @@ -2261,6 +2270,7 @@ model_verbosity = "high"
use_experimental_unified_exec_tool: false,
use_experimental_use_rmcp_client: false,
include_view_image_tool: true,
disable_builtin_tools: false,
active_profile: Some("zdr".to_string()),
windows_wsl_setup_acknowledged: false,
disable_paste_burst: false,
Expand Down Expand Up @@ -2325,6 +2335,7 @@ model_verbosity = "high"
use_experimental_unified_exec_tool: false,
use_experimental_use_rmcp_client: false,
include_view_image_tool: true,
disable_builtin_tools: false,
active_profile: Some("gpt5".to_string()),
windows_wsl_setup_acknowledged: false,
disable_paste_burst: false,
Expand Down
153 changes: 83 additions & 70 deletions codex-rs/core/src/tools/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub(crate) struct ToolsConfig {
pub include_view_image_tool: bool,
pub experimental_unified_exec_tool: bool,
pub experimental_supported_tools: Vec<String>,
pub disable_builtin_tools: bool,
}

pub(crate) struct ToolsConfigParams<'a> {
Expand All @@ -39,6 +40,7 @@ pub(crate) struct ToolsConfigParams<'a> {
pub(crate) use_streamable_shell_tool: bool,
pub(crate) include_view_image_tool: bool,
pub(crate) experimental_unified_exec_tool: bool,
pub(crate) disable_builtin_tools: bool,
}

impl ToolsConfig {
Expand All @@ -51,6 +53,7 @@ impl ToolsConfig {
use_streamable_shell_tool,
include_view_image_tool,
experimental_unified_exec_tool,
disable_builtin_tools,
} = params;
let shell_type = if *use_streamable_shell_tool {
ConfigShellToolType::Streamable
Expand Down Expand Up @@ -80,6 +83,7 @@ impl ToolsConfig {
include_view_image_tool: *include_view_image_tool,
experimental_unified_exec_tool: *experimental_unified_exec_tool,
experimental_supported_tools: model_family.experimental_supported_tools.clone(),
disable_builtin_tools: *disable_builtin_tools,
}
}
}
Expand Down Expand Up @@ -742,87 +746,90 @@ pub(crate) fn build_specs(
let view_image_handler = Arc::new(ViewImageHandler);
let mcp_handler = Arc::new(McpHandler);

if config.experimental_unified_exec_tool {
builder.push_spec(create_unified_exec_tool());
builder.register_handler("unified_exec", unified_exec_handler);
} else {
match &config.shell_type {
ConfigShellToolType::Default => {
builder.push_spec(create_shell_tool());
}
ConfigShellToolType::Local => {
builder.push_spec(ToolSpec::LocalShell {});
}
ConfigShellToolType::Streamable => {
builder.push_spec(ToolSpec::Function(
create_exec_command_tool_for_responses_api(),
));
builder.push_spec(ToolSpec::Function(
create_write_stdin_tool_for_responses_api(),
));
builder.register_handler(EXEC_COMMAND_TOOL_NAME, exec_stream_handler.clone());
builder.register_handler(WRITE_STDIN_TOOL_NAME, exec_stream_handler);
// Skip built-in tools if the flag is set
if !config.disable_builtin_tools {
if config.experimental_unified_exec_tool {
builder.push_spec(create_unified_exec_tool());
builder.register_handler("unified_exec", unified_exec_handler);
} else {
match &config.shell_type {
ConfigShellToolType::Default => {
builder.push_spec(create_shell_tool());
}
ConfigShellToolType::Local => {
builder.push_spec(ToolSpec::LocalShell {});
}
ConfigShellToolType::Streamable => {
builder.push_spec(ToolSpec::Function(
create_exec_command_tool_for_responses_api(),
));
builder.push_spec(ToolSpec::Function(
create_write_stdin_tool_for_responses_api(),
));
builder.register_handler(EXEC_COMMAND_TOOL_NAME, exec_stream_handler.clone());
builder.register_handler(WRITE_STDIN_TOOL_NAME, exec_stream_handler);
}
}
}
}

// Always register shell aliases so older prompts remain compatible.
builder.register_handler("shell", shell_handler.clone());
builder.register_handler("container.exec", shell_handler.clone());
builder.register_handler("local_shell", shell_handler);
// Always register shell aliases so older prompts remain compatible.
builder.register_handler("shell", shell_handler.clone());
builder.register_handler("container.exec", shell_handler.clone());
builder.register_handler("local_shell", shell_handler);

if config.plan_tool {
builder.push_spec(PLAN_TOOL.clone());
builder.register_handler("update_plan", plan_handler);
}
if config.plan_tool {
builder.push_spec(PLAN_TOOL.clone());
builder.register_handler("update_plan", plan_handler);
}

if let Some(apply_patch_tool_type) = &config.apply_patch_tool_type {
match apply_patch_tool_type {
ApplyPatchToolType::Freeform => {
builder.push_spec(create_apply_patch_freeform_tool());
}
ApplyPatchToolType::Function => {
builder.push_spec(create_apply_patch_json_tool());
if let Some(apply_patch_tool_type) = &config.apply_patch_tool_type {
match apply_patch_tool_type {
ApplyPatchToolType::Freeform => {
builder.push_spec(create_apply_patch_freeform_tool());
}
ApplyPatchToolType::Function => {
builder.push_spec(create_apply_patch_json_tool());
}
}
builder.register_handler("apply_patch", apply_patch_handler);
}
builder.register_handler("apply_patch", apply_patch_handler);
}

if config
.experimental_supported_tools
.contains(&"grep_files".to_string())
{
let grep_files_handler = Arc::new(GrepFilesHandler);
builder.push_spec_with_parallel_support(create_grep_files_tool(), true);
builder.register_handler("grep_files", grep_files_handler);
}
if config
.experimental_supported_tools
.contains(&"grep_files".to_string())
{
let grep_files_handler = Arc::new(GrepFilesHandler);
builder.push_spec_with_parallel_support(create_grep_files_tool(), true);
builder.register_handler("grep_files", grep_files_handler);
}

if config
.experimental_supported_tools
.contains(&"read_file".to_string())
{
let read_file_handler = Arc::new(ReadFileHandler);
builder.push_spec_with_parallel_support(create_read_file_tool(), true);
builder.register_handler("read_file", read_file_handler);
}
if config
.experimental_supported_tools
.contains(&"read_file".to_string())
{
let read_file_handler = Arc::new(ReadFileHandler);
builder.push_spec_with_parallel_support(create_read_file_tool(), true);
builder.register_handler("read_file", read_file_handler);
}

if config
.experimental_supported_tools
.iter()
.any(|tool| tool == "list_dir")
{
let list_dir_handler = Arc::new(ListDirHandler);
builder.push_spec_with_parallel_support(create_list_dir_tool(), true);
builder.register_handler("list_dir", list_dir_handler);
}
if config
.experimental_supported_tools
.iter()
.any(|tool| tool == "list_dir")
{
let list_dir_handler = Arc::new(ListDirHandler);
builder.push_spec_with_parallel_support(create_list_dir_tool(), true);
builder.register_handler("list_dir", list_dir_handler);
}

if config
.experimental_supported_tools
.contains(&"test_sync_tool".to_string())
{
let test_sync_handler = Arc::new(TestSyncHandler);
builder.push_spec_with_parallel_support(create_test_sync_tool(), true);
builder.register_handler("test_sync_tool", test_sync_handler);
if config
.experimental_supported_tools
.contains(&"test_sync_tool".to_string())
{
let test_sync_handler = Arc::new(TestSyncHandler);
builder.push_spec_with_parallel_support(create_test_sync_tool(), true);
builder.register_handler("test_sync_tool", test_sync_handler);
}
}

if config.web_search_request {
Expand Down Expand Up @@ -914,6 +921,7 @@ mod tests {
use_streamable_shell_tool: false,
include_view_image_tool: true,
experimental_unified_exec_tool: true,
disable_builtin_tools: false,
});
let (tools, _) = build_specs(&config, Some(HashMap::new())).build();

Expand All @@ -934,6 +942,7 @@ mod tests {
use_streamable_shell_tool: false,
include_view_image_tool: true,
experimental_unified_exec_tool: true,
disable_builtin_tools: false,
});
let (tools, _) = build_specs(&config, Some(HashMap::new())).build();

Expand All @@ -956,6 +965,7 @@ mod tests {
use_streamable_shell_tool: false,
include_view_image_tool: false,
experimental_unified_exec_tool: true,
disable_builtin_tools: false,
});
let (tools, _) = build_specs(&config, None).build();

Expand All @@ -977,6 +987,7 @@ mod tests {
use_streamable_shell_tool: false,
include_view_image_tool: false,
experimental_unified_exec_tool: false,
disable_builtin_tools: false,
});
let (tools, _) = build_specs(&config, None).build();

Expand Down Expand Up @@ -1009,6 +1020,7 @@ mod tests {
use_streamable_shell_tool: false,
include_view_image_tool: true,
experimental_unified_exec_tool: true,
disable_builtin_tools: false,
});
let (tools, _) = build_specs(
&config,
Expand Down Expand Up @@ -1470,6 +1482,7 @@ mod tests {
use_streamable_shell_tool: false,
include_view_image_tool: true,
experimental_unified_exec_tool: true,
disable_builtin_tools: false,
});
let (tools, _) = build_specs(
&config,
Expand Down
5 changes: 5 additions & 0 deletions codex-rs/exec/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ pub struct Cli {
#[arg(long = "include-plan-tool", default_value_t = false)]
pub include_plan_tool: bool,

/// Disable all built-in tools (shell, read_file, list_dir, grep_files, apply_patch).
/// MCP tools and web search will still be available if configured.
#[arg(long = "disable-builtin-tools", default_value_t = false)]
pub disable_builtin_tools: bool,

/// Specifies file where the last message from the agent should be written.
#[arg(long = "output-last-message", short = 'o', value_name = "FILE")]
pub last_message_file: Option<PathBuf>,
Expand Down
2 changes: 2 additions & 0 deletions codex-rs/exec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
prompt,
output_schema: output_schema_path,
include_plan_tool,
disable_builtin_tools,
config_overrides,
} = cli;

Expand Down Expand Up @@ -181,6 +182,7 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
include_view_image_tool: None,
show_raw_agent_reasoning: oss.then_some(true),
tools_web_search_request: None,
disable_builtin_tools: Some(disable_builtin_tools),
};
// Parse `-c` overrides.
let cli_kv_overrides = match config_overrides.parse_overrides() {
Expand Down