Skip to content

Commit e81327e

Browse files
authored
feat: add hide_agent_reasoning config option (openai#1181)
This PR introduces a `hide_agent_reasoning` config option (that defaults to `false`) that users can enable to make the output less verbose by suppressing reasoning output. To test, verified that this includes agent reasoning in the output: ``` echo hello | just exec ``` whereas this does not: ``` echo hello | just exec --config hide_agent_reasoning=false ```
1 parent 4f3d294 commit e81327e

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

codex-rs/config.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,16 @@ Note this is **not** a general editor setting (like `$EDITOR`), as it only accep
354354

355355
Currently, `"vscode"` is the default, though Codex does not verify VS Code is installed. As such, `file_opener` may default to `"none"` or something else in the future.
356356

357+
## hide_agent_reasoning
358+
359+
Codex intermittently emits "reasoning" events that show the model’s internal "thinking" before it produces a final answer. Some users may find these events distracting, especially in CI logs or minimal terminal output.
360+
361+
Setting `hide_agent_reasoning` to `true` suppresses these events in **both** the TUI as well as the headless `exec` sub-command:
362+
363+
```toml
364+
hide_agent_reasoning = true # defaults to false
365+
```
366+
357367
## project_doc_max_bytes
358368

359369
Maximum number of bytes to read from an `AGENTS.md` file to include in the instructions sent with the first turn of a session. Defaults to 32 KiB.

codex-rs/core/src/config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ pub struct Config {
4242

4343
pub shell_environment_policy: ShellEnvironmentPolicy,
4444

45+
/// When `true`, `AgentReasoning` events emitted by the backend will be
46+
/// suppressed from the frontend output. This can reduce visual noise when
47+
/// users are only interested in the final agent responses.
48+
pub hide_agent_reasoning: bool,
49+
4550
/// Disable server-side response storage (sends the full conversation
4651
/// context with every request). Currently necessary for OpenAI customers
4752
/// who have opted into Zero Data Retention (ZDR).
@@ -272,6 +277,10 @@ pub struct ConfigToml {
272277

273278
/// Collection of settings that are specific to the TUI.
274279
pub tui: Option<Tui>,
280+
281+
/// When set to `true`, `AgentReasoning` events will be hidden from the
282+
/// UI/output. Defaults to `false`.
283+
pub hide_agent_reasoning: Option<bool>,
275284
}
276285

277286
fn deserialize_sandbox_permissions<'de, D>(
@@ -433,6 +442,8 @@ impl Config {
433442
file_opener: cfg.file_opener.unwrap_or(UriBasedFileOpener::VsCode),
434443
tui: cfg.tui.unwrap_or_default(),
435444
codex_linux_sandbox_exe,
445+
446+
hide_agent_reasoning: cfg.hide_agent_reasoning.unwrap_or(false),
436447
};
437448
Ok(config)
438449
}
@@ -774,6 +785,7 @@ disable_response_storage = true
774785
file_opener: UriBasedFileOpener::VsCode,
775786
tui: Tui::default(),
776787
codex_linux_sandbox_exe: None,
788+
hide_agent_reasoning: false,
777789
},
778790
o3_profile_config
779791
);
@@ -813,6 +825,7 @@ disable_response_storage = true
813825
file_opener: UriBasedFileOpener::VsCode,
814826
tui: Tui::default(),
815827
codex_linux_sandbox_exe: None,
828+
hide_agent_reasoning: false,
816829
};
817830

818831
assert_eq!(expected_gpt3_profile_config, gpt3_profile_config);
@@ -867,6 +880,7 @@ disable_response_storage = true
867880
file_opener: UriBasedFileOpener::VsCode,
868881
tui: Tui::default(),
869882
codex_linux_sandbox_exe: None,
883+
hide_agent_reasoning: false,
870884
};
871885

872886
assert_eq!(expected_zdr_profile_config, zdr_profile_config);

codex-rs/exec/src/event_processor.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ pub(crate) struct EventProcessor {
4343
red: Style,
4444
green: Style,
4545
cyan: Style,
46+
47+
/// Whether to include `AgentReasoning` events in the output.
48+
show_agent_reasoning: bool,
4649
}
4750

4851
impl EventProcessor {
49-
pub(crate) fn create_with_ansi(with_ansi: bool) -> Self {
52+
pub(crate) fn create_with_ansi(with_ansi: bool, show_agent_reasoning: bool) -> Self {
5053
let call_id_to_command = HashMap::new();
5154
let call_id_to_patch = HashMap::new();
5255
let call_id_to_tool_call = HashMap::new();
@@ -63,6 +66,7 @@ impl EventProcessor {
6366
green: Style::new().green(),
6467
cyan: Style::new().cyan(),
6568
call_id_to_tool_call,
69+
show_agent_reasoning,
6670
}
6771
} else {
6872
Self {
@@ -76,6 +80,7 @@ impl EventProcessor {
7680
green: Style::new(),
7781
cyan: Style::new(),
7882
call_id_to_tool_call,
83+
show_agent_reasoning,
7984
}
8085
}
8186
}
@@ -411,12 +416,14 @@ impl EventProcessor {
411416
// Should we exit?
412417
}
413418
EventMsg::AgentReasoning(agent_reasoning_event) => {
414-
ts_println!(
415-
self,
416-
"{}\n{}",
417-
"thinking".style(self.italic).style(self.magenta),
418-
agent_reasoning_event.text
419-
);
419+
if self.show_agent_reasoning {
420+
ts_println!(
421+
self,
422+
"{}\n{}",
423+
"thinking".style(self.italic).style(self.magenta),
424+
agent_reasoning_event.text
425+
);
426+
}
420427
}
421428
EventMsg::SessionConfigured(session_configured_event) => {
422429
let SessionConfiguredEvent {

codex-rs/exec/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
112112
};
113113

114114
let config = Config::load_with_cli_overrides(cli_kv_overrides, overrides)?;
115-
let mut event_processor = EventProcessor::create_with_ansi(stdout_with_ansi);
115+
let mut event_processor =
116+
EventProcessor::create_with_ansi(stdout_with_ansi, !config.hide_agent_reasoning);
116117
// Print the effective configuration and prompt so users can see what Codex
117118
// is using.
118119
event_processor.print_config_summary(&config, &prompt);

codex-rs/tui/src/chatwidget.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ impl ChatWidget<'_> {
239239
self.request_redraw();
240240
}
241241
EventMsg::AgentReasoning(AgentReasoningEvent { text }) => {
242-
self.conversation_history
243-
.add_agent_reasoning(&self.config, text);
244-
self.request_redraw();
242+
if !self.config.hide_agent_reasoning {
243+
self.conversation_history
244+
.add_agent_reasoning(&self.config, text);
245+
self.request_redraw();
246+
}
245247
}
246248
EventMsg::TaskStarted => {
247249
self.bottom_pane.set_task_running(true);

0 commit comments

Comments
 (0)