From c1d951c594c5d55ebf317cd96d11587879e3a4c8 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Wed, 15 Oct 2025 16:26:33 -0700 Subject: [PATCH] change-web-search --- codex-rs/core/src/codex.rs | 25 ++++++++++++++++++++++++- codex-rs/protocol/src/protocol.rs | 5 ++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 9df905a0c2..8c1d24f4f1 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -1981,13 +1981,36 @@ async fn run_turn( .get_model_family() .supports_parallel_tool_calls; let parallel_tool_calls = model_supports_parallel; + let mut allowed_tools = Vec::new(); + let mut restricted_tool_choice = false; + for tool in router.allowed_tools() { + let is_disabled = tool + .get("name") + .and_then(|val| val.as_str()) + .is_some_and(|name| { + turn_context + .disabled_tools + .iter() + .any(|disabled| disabled.matches_tool_name(name)) + }); + if is_disabled { + restricted_tool_choice = true; + continue; + } + allowed_tools.push(tool); + } + let allowed_tools = if restricted_tool_choice { + Some(allowed_tools) + } else { + None + }; let prompt = Prompt { input, tools: router.specs(), parallel_tool_calls, base_instructions_override: turn_context.base_instructions.clone(), output_schema: turn_context.final_output_json_schema.clone(), - allowed_tools: Some(router.allowed_tools()), + allowed_tools, }; let mut retries = 0; diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index a2746a9deb..43bc50e5e1 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -96,7 +96,10 @@ impl DisabledTool { } pub fn matches_tool_name(&self, tool_name: &str) -> bool { - self.raw_name() == tool_name + match self { + DisabledTool::Known(kind) => kind.raw_name() == tool_name, + DisabledTool::Other(name) => name == tool_name, + } } }