diff --git a/codex-rs/config.md b/codex-rs/config.md index c7dfe42a75..f7e56f803b 100644 --- a/codex-rs/config.md +++ b/codex-rs/config.md @@ -243,6 +243,17 @@ By default, `reasoning` is only set on requests to OpenAI models that are known model_supports_reasoning_summaries = true ``` +## include_plan_tool + +Controls whether to expose the experimental plan tool (named `update_plan`) to the model and include the corresponding guidance in the system prompt. + +When enabled, the model can call `update_plan` to keep an up-to-date, step-by-step plan for the task and Codex will render plan updates in the UI. When disabled, the tool is not advertised to the model and the “Plan updates” section is omitted from the prompt; any unsolicited `update_plan` calls will be treated as unsupported. + +```toml +# Enable the experimental plan tool and prompt instructions +include_plan_tool = true +``` + ## sandbox_mode Codex executes model-generated shell commands inside an OS-level sandbox. diff --git a/codex-rs/core/prompt.md b/codex-rs/core/prompt.md index 0a4578270a..8bbe618589 100644 --- a/codex-rs/core/prompt.md +++ b/codex-rs/core/prompt.md @@ -97,6 +97,7 @@ You can invoke apply_patch like: shell {"command":["apply_patch","*** Begin Patch\n*** Add File: hello.txt\n+Hello, world!\n*** End Patch\n"]} ``` + Plan updates A tool named `update_plan` is available. Use it to keep an up‑to‑date, step‑by‑step plan for the task so you can follow your progress. When making your plans, keep in mind that you are a deployed coding agent - `update_plan` calls should not involve doing anything that you aren't capable of doing. For example, `update_plan` calls should NEVER contain tasks to merge your own pull requests. Only stop to ask the user if you genuinely need their feedback on a change. @@ -105,3 +106,4 @@ A tool named `update_plan` is available. Use it to keep an up‑to‑date, step - Whenever you finish a step, call `update_plan` again, marking the finished step as `completed` and the next step as `in_progress`. - If your plan needs to change, call `update_plan` with the revised steps and include an `explanation` describing the change. - When all steps are complete, make a final `update_plan` call with all steps marked `completed`. + diff --git a/codex-rs/core/src/chat_completions.rs b/codex-rs/core/src/chat_completions.rs index 5ede774b1c..f98d906c17 100644 --- a/codex-rs/core/src/chat_completions.rs +++ b/codex-rs/core/src/chat_completions.rs @@ -37,7 +37,7 @@ pub(crate) async fn stream_chat_completions( // Build messages array let mut messages = Vec::::new(); - let full_instructions = prompt.get_full_instructions(model); + let full_instructions = prompt.get_full_instructions(model, include_plan_tool); messages.push(json!({"role": "system", "content": full_instructions})); if let Some(instr) = &prompt.user_instructions { diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index b9ea6b13f4..a2c2294a68 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -141,7 +141,8 @@ impl ModelClient { let token = auth.get_token().await?; - let full_instructions = prompt.get_full_instructions(&self.config.model); + let full_instructions = + prompt.get_full_instructions(&self.config.model, self.config.include_plan_tool); let tools_json = create_tools_json_for_responses_api( prompt, &self.config.model, diff --git a/codex-rs/core/src/client_common.rs b/codex-rs/core/src/client_common.rs index 157f35872a..e9fd1abfc1 100644 --- a/codex-rs/core/src/client_common.rs +++ b/codex-rs/core/src/client_common.rs @@ -38,12 +38,41 @@ pub struct Prompt { } impl Prompt { - pub(crate) fn get_full_instructions(&self, model: &str) -> Cow<'_, str> { - let base = self + pub(crate) fn get_full_instructions( + &self, + model: &str, + include_plan_tool: bool, + ) -> Cow<'_, str> { + let mut base = self .base_instructions_override .as_deref() - .unwrap_or(BASE_INSTRUCTIONS); - let mut sections: Vec<&str> = vec![base]; + .unwrap_or(BASE_INSTRUCTIONS) + .to_string(); + + if !include_plan_tool { + // Remove the plan-tool section if present. Prefer explicit markers + // for robustness, but fall back to trimming from the "Plan updates" + // heading if markers are missing. + let start_marker = ""; + let end_marker = ""; + if let (Some(start), Some(end)) = (base.find(start_marker), base.find(end_marker)) { + if end > start { + let mut edited = String::with_capacity(base.len()); + edited.push_str(&base[..start]); + edited.push_str(&base[end + end_marker.len()..]); + base = edited; + } + } else if let Some(idx) = base + .find("\n\nPlan updates") + .or_else(|| base.find("\nPlan updates")) + .or_else(|| base.find("Plan updates")) + { + base.truncate(idx); + } + base = base.trim_end().to_string(); + } + + let mut sections: Vec<&str> = vec![&base]; if model.starts_with("gpt-4.1") { sections.push(APPLY_PATCH_TOOL_INSTRUCTIONS); } @@ -197,7 +226,7 @@ mod tests { ..Default::default() }; let expected = format!("{BASE_INSTRUCTIONS}\n{APPLY_PATCH_TOOL_INSTRUCTIONS}"); - let full = prompt.get_full_instructions("gpt-4.1"); + let full = prompt.get_full_instructions("gpt-4.1", true); assert_eq!(full, expected); } } diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 6e21642da1..a3939da60f 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -225,6 +225,9 @@ pub(crate) struct Session { state: Mutex, codex_linux_sandbox_exe: Option, user_shell: shell::Shell, + + /// Whether the experimental plan tool is enabled for this session. + include_plan_tool: bool, } impl Session { @@ -791,6 +794,7 @@ async fn submission_loop( codex_linux_sandbox_exe: config.codex_linux_sandbox_exe.clone(), disable_response_storage, user_shell: default_shell, + include_plan_tool: config.include_plan_tool, })); // Patch restored state into the newly created session. @@ -1531,7 +1535,19 @@ async fn handle_function_call( }; handle_container_exec_with_params(params, sess, sub_id, call_id).await } - "update_plan" => handle_update_plan(sess, arguments, sub_id, call_id).await, + "update_plan" => { + if sess.include_plan_tool { + handle_update_plan(sess, arguments, sub_id, call_id).await + } else { + ResponseInputItem::FunctionCallOutput { + call_id, + output: FunctionCallOutputPayload { + content: format!("unsupported call: {name}"), + success: None, + }, + } + } + } _ => { match sess.mcp_connection_manager.parse_tool_name(&name) { Some((server, tool_name)) => { diff --git a/codex-rs/core/src/config.rs b/codex-rs/core/src/config.rs index 87629d821a..818e1bd83b 100644 --- a/codex-rs/core/src/config.rs +++ b/codex-rs/core/src/config.rs @@ -342,6 +342,9 @@ pub struct ConfigToml { /// The value for the `originator` header included with Responses API requests. pub internal_originator: Option, + + /// Include an experimental plan tool that the model can use to update its current plan and status of each step. + pub include_plan_tool: Option, } impl ConfigToml { @@ -535,7 +538,7 @@ impl Config { .unwrap_or("https://chatgpt.com/backend-api/".to_string()), experimental_resume, - include_plan_tool: include_plan_tool.unwrap_or(false), + include_plan_tool: include_plan_tool.or(cfg.include_plan_tool).unwrap_or(false), internal_originator: cfg.internal_originator, }; Ok(config)