config for planning tool

This commit is contained in:
easong-openai
2025-08-01 18:35:13 -07:00
parent 7e0f506da2
commit c66fd9d59a
7 changed files with 71 additions and 9 deletions
+11
View File
@@ -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.
+2
View File
@@ -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_TOOL:START -->
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`.
<!-- PLAN_TOOL:END -->
+1 -1
View File
@@ -37,7 +37,7 @@ pub(crate) async fn stream_chat_completions(
// Build messages array
let mut messages = Vec::<serde_json::Value>::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 {
+2 -1
View File
@@ -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,
+34 -5
View File
@@ -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 = "<!-- PLAN_TOOL:START -->";
let end_marker = "<!-- PLAN_TOOL:END -->";
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);
}
}
+17 -1
View File
@@ -225,6 +225,9 @@ pub(crate) struct Session {
state: Mutex<State>,
codex_linux_sandbox_exe: Option<PathBuf>,
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)) => {
+4 -1
View File
@@ -342,6 +342,9 @@ pub struct ConfigToml {
/// The value for the `originator` header included with Responses API requests.
pub internal_originator: Option<String>,
/// 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<bool>,
}
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)