Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

[codex] Add configurable multi-agent mode hint text (#30493)

Shijie Raoda4c8ca57d40
diff --git a/codex-rs/app-server-protocol/schema/json/ClientRequest.json b/codex-rs/app-server-protocol/schema/json/ClientRequest.json
index f3983e31f4..7f7ead662b 100644
--- a/codex-rs/app-server-protocol/schema/json/ClientRequest.json
+++ b/codex-rs/app-server-protocol/schema/json/ClientRequest.json
@@ -1786,13 +1786,29 @@
"type": "object"
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.json
index 23dae42a9d..e7a533d76b 100644
--- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json
+++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json
@@ -2713,13 +2713,29 @@
"type": "object"
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json
index b77b512b36..a717ec3428 100644
--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json
+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json
@@ -12860,13 +12860,29 @@
"type": "object"
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json
index bdd61d6b94..6155844a8b 100644
--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json
+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json
@@ -9264,13 +9264,29 @@
"type": "object"
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json
index 5d20d64e68..59a14cc070 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json
@@ -681,13 +681,29 @@
]
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json
index ee1ca83917..80fbb183f8 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json
@@ -681,13 +681,29 @@
]
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadSettingsUpdatedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadSettingsUpdatedNotification.json
index 8d528246b5..f3296fa376 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadSettingsUpdatedNotification.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadSettingsUpdatedNotification.json
@@ -108,13 +108,29 @@
"type": "string"
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.json
index 3a23d13d22..3819f1f761 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.json
@@ -195,13 +195,29 @@
"type": "string"
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"Personality": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json
index 9d16598696..3ef1577038 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json
@@ -681,13 +681,29 @@
]
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartParams.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartParams.json
index 36b4d2a15d..cc4869e1d1 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartParams.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartParams.json
@@ -141,13 +141,29 @@
"type": "string"
},
"MultiAgentMode": {
- "description": "Controls whether the model receives multi-agent delegation instructions and, when it does, whether it should only spawn sub-agents after an explicit user request or may delegate proactively when doing so would help. `none` leaves the multi-agent tools available without injecting delegation instructions.",
- "enum": [
- "none",
- "explicitRequestOnly",
- "proactive"
- ],
- "type": "string"
+ "description": "Controls the effective multi-agent delegation instructions for a turn. `custom` means the configured mode hint defines the policy instead of a built-in policy.",
+ "oneOf": [
+ {
+ "enum": [
+ "explicitRequestOnly",
+ "proactive"
+ ],
+ "type": "string"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "custom": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "custom"
+ ],
+ "title": "CustomMultiAgentMode",
+ "type": "object"
+ }
+ ]
},
"NetworkAccess": {
"enum": [
diff --git a/codex-rs/app-server-protocol/schema/typescript/MultiAgentMode.ts b/codex-rs/app-server-protocol/schema/typescript/MultiAgentMode.ts
index b59be94f8e..7784a6f5ca 100644
--- a/codex-rs/app-server-protocol/schema/typescript/MultiAgentMode.ts
+++ b/codex-rs/app-server-protocol/schema/typescript/MultiAgentMode.ts
@@ -3,9 +3,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
- * Controls whether the model receives multi-agent delegation instructions and,
- * when it does, whether it should only spawn sub-agents after an explicit user
- * request or may delegate proactively when doing so would help. `none` leaves
- * the multi-agent tools available without injecting delegation instructions.
+ * Controls the effective multi-agent delegation instructions for a turn. `custom` means the
+ * configured mode hint defines the policy instead of a built-in policy.
*/
-export type MultiAgentMode = "none" | "explicitRequestOnly" | "proactive";
+export type MultiAgentMode = { "custom": string } | "explicitRequestOnly" | "proactive";
diff --git a/codex-rs/core/config.schema.json b/codex-rs/core/config.schema.json
index ab787ba34f..876180dd7e 100644
--- a/codex-rs/core/config.schema.json
+++ b/codex-rs/core/config.schema.json
@@ -1750,6 +1750,9 @@
"minimum": 0.0,
"type": "integer"
},
+ "multi_agent_mode_hint_text": {
+ "type": "string"
+ },
"non_code_mode_only": {
"type": "boolean"
},
diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs
index c344475541..6156b9b9ea 100644
--- a/codex-rs/core/src/config/config_tests.rs
+++ b/codex-rs/core/src/config/config_tests.rs
@@ -10307,6 +10307,7 @@ default_wait_timeout_ms = 30000
usage_hint_text = "Custom delegation guidance."
root_agent_usage_hint_text = "Root guidance."
subagent_usage_hint_text = "Subagent guidance."
+multi_agent_mode_hint_text = "Custom mode guidance."
tool_namespace = "agents"
hide_spawn_agent_metadata = true
non_code_mode_only = true
@@ -10343,6 +10344,10 @@ non_code_mode_only = true
config.multi_agent_v2.subagent_usage_hint_text.as_deref(),
Some("Subagent guidance.")
);
+ assert_eq!(
+ config.multi_agent_v2.multi_agent_mode_hint_text.as_deref(),
+ Some("Custom mode guidance.")
+ );
assert_eq!(
config.multi_agent_v2.tool_namespace.as_deref(),
Some("agents")
@@ -10405,6 +10410,22 @@ max_concurrent_threads_per_session = 17
);
}
+#[test]
+fn multi_agent_v2_preserves_empty_mode_hint_override() {
+ let config_toml = toml::from_str(
+ r#"[features.multi_agent_v2]
+multi_agent_mode_hint_text = ""
+"#,
+ )
+ .expect("multi-agent v2 config should parse");
+
+ let expected = MultiAgentV2Config {
+ multi_agent_mode_hint_text: Some(String::new()),
+ ..Default::default()
+ };
+ assert_eq!(resolve_multi_agent_v2_config(&config_toml), expected);
+}
+
#[tokio::test]
async fn multi_agent_v2_empty_usage_hint_overrides_clear_default_hints() -> std::io::Result<()> {
let codex_home = TempDir::new()?;
diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs
index d90d010102..e29cb3875c 100644
--- a/codex-rs/core/src/config/mod.rs
+++ b/codex-rs/core/src/config/mod.rs
@@ -1144,6 +1144,7 @@ pub struct MultiAgentV2Config {
pub usage_hint_text: Option<String>,
pub root_agent_usage_hint_text: Option<String>,
pub subagent_usage_hint_text: Option<String>,
+ pub multi_agent_mode_hint_text: Option<String>,
pub tool_namespace: Option<String>,
pub hide_spawn_agent_metadata: bool,
pub non_code_mode_only: bool,
@@ -1165,6 +1166,7 @@ impl MultiAgentV2Config {
DEFAULT_MULTI_AGENT_V2_SUBAGENT_USAGE_HINT_TEXT,
max_concurrent_threads_per_session,
)),
+ multi_agent_mode_hint_text: None,
tool_namespace: Some(DEFAULT_MULTI_AGENT_V2_TOOL_NAMESPACE.to_string()),
hide_spawn_agent_metadata: true,
non_code_mode_only: true,
@@ -2501,6 +2503,10 @@ fn resolve_multi_agent_v2_config(config_toml: &ConfigToml) -> MultiAgentV2Config
base.map(|config| &config.subagent_usage_hint_text),
default.subagent_usage_hint_text,
);
+ let multi_agent_mode_hint_text = base
+ .and_then(|config| config.multi_agent_mode_hint_text.as_ref())
+ .cloned()
+ .or(default.multi_agent_mode_hint_text);
let tool_namespace = base
.and_then(|config| config.tool_namespace.as_ref())
.cloned()
@@ -2520,6 +2526,7 @@ fn resolve_multi_agent_v2_config(config_toml: &ConfigToml) -> MultiAgentV2Config
usage_hint_text,
root_agent_usage_hint_text,
subagent_usage_hint_text,
+ multi_agent_mode_hint_text,
tool_namespace,
hide_spawn_agent_metadata,
non_code_mode_only,
diff --git a/codex-rs/core/src/context/multi_agent_mode_instructions.rs b/codex-rs/core/src/context/multi_agent_mode_instructions.rs
index ff471967ca..9c8f5ad5ed 100644
--- a/codex-rs/core/src/context/multi_agent_mode_instructions.rs
+++ b/codex-rs/core/src/context/multi_agent_mode_instructions.rs
@@ -4,7 +4,6 @@ use codex_protocol::protocol::MULTI_AGENT_MODE_CLOSE_TAG;
use codex_protocol::protocol::MULTI_AGENT_MODE_OPEN_TAG;
const EXPLICIT_REQUEST_ONLY_MULTI_AGENT_MODE_TEXT: &str = "Do not spawn sub-agents unless the user or applicable AGENTS.md/skill instructions explicitly ask for sub-agents, delegation, or parallel agent work.";
-const NO_MULTI_AGENT_MODE_TEXT: &str = "Multi-agent delegation mode instructions are inactive. Any earlier multi-agent mode developer message no longer applies.";
const PROACTIVE_MULTI_AGENT_MODE_TEXT: &str = "Proactive multi-agent delegation is active. Any earlier instruction requiring an explicit user request before spawning sub-agents no longer applies. Use sub-agents when parallel work would materially improve speed or quality. This mode remains active until a later multi-agent mode developer message changes it.";
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -32,8 +31,8 @@ impl ContextualUserFragment for MultiAgentModeInstructions {
}
fn body(&self) -> String {
- match self.multi_agent_mode {
- MultiAgentMode::None => NO_MULTI_AGENT_MODE_TEXT.to_string(),
+ match &self.multi_agent_mode {
+ MultiAgentMode::Custom(hint_text) => hint_text.clone(),
MultiAgentMode::ExplicitRequestOnly => {
EXPLICIT_REQUEST_ONLY_MULTI_AGENT_MODE_TEXT.to_string()
}
diff --git a/codex-rs/core/src/context_manager/updates.rs b/codex-rs/core/src/context_manager/updates.rs
index 5e81bc2a7d..a520e6f595 100644
--- a/codex-rs/core/src/context_manager/updates.rs
+++ b/codex-rs/core/src/context_manager/updates.rs
@@ -85,9 +85,6 @@ fn build_multi_agent_mode_update_item(
}
match effective_multi_agent_mode {
- Some(MultiAgentMode::None) => {
- Some(MultiAgentModeInstructions::new(MultiAgentMode::None).render())
- }
Some(multi_agent_mode) => Some(MultiAgentModeInstructions::new(multi_agent_mode).render()),
None if previous.multi_agent_mode == Some(MultiAgentMode::Proactive) => {
Some(MultiAgentModeInstructions::new(MultiAgentMode::ExplicitRequestOnly).render())
diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs
index 809fa92015..978768ba00 100644
--- a/codex-rs/core/src/session/mod.rs
+++ b/codex-rs/core/src/session/mod.rs
@@ -94,7 +94,6 @@ use codex_protocol::approvals::NetworkPolicyRuleAction;
use codex_protocol::config_types::ApprovalsReviewer;
use codex_protocol::config_types::AutoCompactTokenLimitScope;
use codex_protocol::config_types::ModeKind;
-use codex_protocol::config_types::MultiAgentMode;
use codex_protocol::config_types::SERVICE_TIER_DEFAULT_REQUEST_VALUE;
use codex_protocol::config_types::Settings;
use codex_protocol::config_types::WebSearchMode;
@@ -3430,16 +3429,10 @@ impl Session {
{
items.push(usage_hint_message);
}
- match multi_agents::effective_multi_agent_mode(turn_context) {
- Some(
- multi_agent_mode
- @ (MultiAgentMode::ExplicitRequestOnly | MultiAgentMode::Proactive),
- ) => {
- items.push(ContextualUserFragment::into(
- MultiAgentModeInstructions::new(multi_agent_mode),
- ));
- }
- Some(MultiAgentMode::None) | None => {}
+ if let Some(multi_agent_mode) = multi_agents::effective_multi_agent_mode(turn_context) {
+ items.push(ContextualUserFragment::into(
+ MultiAgentModeInstructions::new(multi_agent_mode),
+ ));
}
if let Some(contextual_user_message) =
crate::context_manager::updates::build_contextual_user_message(contextual_user_sections)
diff --git a/codex-rs/core/src/session/multi_agents.rs b/codex-rs/core/src/session/multi_agents.rs
index 385f2281ba..c2f139e68b 100644
--- a/codex-rs/core/src/session/multi_agents.rs
+++ b/codex-rs/core/src/session/multi_agents.rs
@@ -41,9 +41,18 @@ pub(crate) fn effective_multi_agent_mode(turn_context: &TurnContext) -> Option<M
return None;
}
- let multi_agent_mode = match turn_context.effective_reasoning_effort() {
- Some(ReasoningEffort::Ultra) => MultiAgentMode::Proactive,
- _ => MultiAgentMode::ExplicitRequestOnly,
+ // A configured hint, including an empty string, defines a custom policy instead of an
+ // effort-derived built-in policy.
+ let multi_agent_mode = match &turn_context
+ .config
+ .multi_agent_v2
+ .multi_agent_mode_hint_text
+ {
+ Some(hint_text) => MultiAgentMode::Custom(hint_text.clone()),
+ None => match turn_context.effective_reasoning_effort() {
+ Some(ReasoningEffort::Ultra) => MultiAgentMode::Proactive,
+ _ => MultiAgentMode::ExplicitRequestOnly,
+ },
};
match &turn_context.session_source {
diff --git a/codex-rs/core/tests/suite/multi_agent_mode.rs b/codex-rs/core/tests/suite/multi_agent_mode.rs
index fd177e7ed9..283ed6c5cc 100644
--- a/codex-rs/core/tests/suite/multi_agent_mode.rs
+++ b/codex-rs/core/tests/suite/multi_agent_mode.rs
@@ -20,9 +20,11 @@ use core_test_support::test_codex::test_codex;
use core_test_support::wait_for_event;
use pretty_assertions::assert_eq;
use serde_json::Value;
+use serde_json::json;
const NO_SPAWN_TEXT: &str = "Do not spawn sub-agents unless the user or applicable AGENTS.md/skill instructions explicitly ask for sub-agents, delegation, or parallel agent work.";
const PROACTIVE_TEXT: &str = "Proactive multi-agent delegation is active.";
+const CUSTOM_MODE_HINT_TEXT: &str = "Use the configured delegation policy.";
fn add_ultra_reasoning(model_info: &mut ModelInfo) {
model_info.supports_reasoning_summaries = true;
@@ -41,6 +43,12 @@ fn configure_multi_agent_v2(config: &mut Config) {
.expect("test config should allow feature update");
}
+// Configuring a custom mode hint also enables multi-agent V2 for the test.
+fn configure_custom_mode_hint(config: &mut Config) {
+ configure_multi_agent_v2(config);
+ config.multi_agent_v2.multi_agent_mode_hint_text = Some(CUSTOM_MODE_HINT_TEXT.to_string());
+}
+
fn configure_ultra(config: &mut Config) {
configure_multi_agent_v2(config);
config.model_reasoning_effort = Some(ReasoningEffort::Ultra);
@@ -120,6 +128,105 @@ async fn ultra_reasoning_uses_max_and_proactive_mode() -> Result<()> {
Ok(())
}
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn configured_mode_hint_uses_custom_mode_across_reasoning_efforts() -> Result<()> {
+ skip_if_no_network!(Ok(()));
+
+ let server = start_mock_server().await;
+ let responses = mount_sse_sequence(
+ &server,
+ (1..=2)
+ .map(|index| {
+ sse(vec![
+ ev_response_created(&format!("resp-{index}")),
+ ev_completed(&format!("resp-{index}")),
+ ])
+ })
+ .collect(),
+ )
+ .await;
+ let test = test_codex()
+ .with_model_info_override("gpt-5.4", add_ultra_reasoning)
+ .with_config(configure_custom_mode_hint)
+ .build(&server)
+ .await?;
+ let rollout_path = test
+ .session_configured
+ .rollout_path
+ .clone()
+ .expect("rollout path");
+
+ submit_turn(&test.codex, "explicit", Some(ReasoningEffort::High)).await?;
+ submit_turn(&test.codex, "proactive", Some(ReasoningEffort::Ultra)).await?;
+
+ let requests = responses.requests();
+ let first_input = requests[0].input();
+ let first_texts = developer_texts(&first_input);
+ let second_input = requests[1].input();
+ let second_texts = developer_texts(&second_input);
+ let instruction_counts = |texts: &[&str]| {
+ (
+ count_containing(texts, CUSTOM_MODE_HINT_TEXT),
+ count_containing(texts, NO_SPAWN_TEXT),
+ count_containing(texts, PROACTIVE_TEXT),
+ )
+ };
+ assert_eq!(instruction_counts(&first_texts), (1, 0, 0));
+ assert_eq!(instruction_counts(&second_texts), (1, 0, 0));
+ let rollout_values = std::fs::read_to_string(rollout_path)?
+ .lines()
+ .map(serde_json::from_str::<Value>)
+ .collect::<serde_json::Result<Vec<_>>>()?;
+ let recorded_modes = rollout_values
+ .iter()
+ .filter(|value| value.get("type").and_then(Value::as_str) == Some("turn_context"))
+ .filter_map(|value| value.pointer("/payload/multi_agent_mode").cloned())
+ .collect::<Vec<_>>();
+ assert_eq!(
+ recorded_modes,
+ [
+ json!({"custom": CUSTOM_MODE_HINT_TEXT}),
+ json!({"custom": CUSTOM_MODE_HINT_TEXT}),
+ ]
+ );
+
+ Ok(())
+}
+
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn empty_configured_mode_hint_suppresses_builtin_text() -> Result<()> {
+ skip_if_no_network!(Ok(()));
+
+ let server = start_mock_server().await;
+ let response = mount_sse_once(
+ &server,
+ sse(vec![ev_response_created("resp-1"), ev_completed("resp-1")]),
+ )
+ .await;
+ let test = test_codex()
+ .with_config(|config| {
+ configure_multi_agent_v2(config);
+ config.multi_agent_v2.multi_agent_mode_hint_text = Some(String::new());
+ })
+ .build(&server)
+ .await?;
+
+ submit_turn(&test.codex, "hello", Some(ReasoningEffort::High)).await?;
+
+ let input = response.single_request().input();
+ let texts = developer_texts(&input);
+ assert_eq!(
+ (
+ count_containing(&texts, MULTI_AGENT_MODE_OPEN_TAG),
+ count_containing(&texts, NO_SPAWN_TEXT),
+ count_containing(&texts, PROACTIVE_TEXT),
+ ),
+ (1, 0, 0)
+ );
+
+ Ok(())
+}
+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn leaving_ultra_after_cold_resume_emits_explicit_mode() -> Result<()> {
skip_if_no_network!(Ok(()));
diff --git a/codex-rs/features/src/feature_configs.rs b/codex-rs/features/src/feature_configs.rs
index 9fc5df2d59..0100dc1d83 100644
--- a/codex-rs/features/src/feature_configs.rs
+++ b/codex-rs/features/src/feature_configs.rs
@@ -56,6 +56,8 @@ pub struct MultiAgentV2ConfigToml {
#[serde(skip_serializing_if = "Option::is_none")]
pub subagent_usage_hint_text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
+ pub multi_agent_mode_hint_text: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
#[schemars(length(min = 1, max = 64), regex(pattern = r"^[a-zA-Z0-9_-]+$"))]
pub tool_namespace: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
diff --git a/codex-rs/features/src/tests.rs b/codex-rs/features/src/tests.rs
index 69fd59e13a..13abd9ecd2 100644
--- a/codex-rs/features/src/tests.rs
+++ b/codex-rs/features/src/tests.rs
@@ -610,6 +610,7 @@ usage_hint_enabled = false
usage_hint_text = "Custom delegation guidance."
root_agent_usage_hint_text = "Root guidance."
subagent_usage_hint_text = "Subagent guidance."
+multi_agent_mode_hint_text = "Custom mode guidance."
tool_namespace = "agents"
hide_spawn_agent_metadata = true
non_code_mode_only = true
@@ -633,6 +634,7 @@ non_code_mode_only = true
usage_hint_text: Some("Custom delegation guidance.".to_string()),
root_agent_usage_hint_text: Some("Root guidance.".to_string()),
subagent_usage_hint_text: Some("Subagent guidance.".to_string()),
+ multi_agent_mode_hint_text: Some("Custom mode guidance.".to_string()),
tool_namespace: Some("agents".to_string()),
hide_spawn_agent_metadata: Some(true),
non_code_mode_only: Some(true),
diff --git a/codex-rs/protocol/src/config_types.rs b/codex-rs/protocol/src/config_types.rs
index 83bcbdc0ae..7732efbbe5 100644
--- a/codex-rs/protocol/src/config_types.rs
+++ b/codex-rs/protocol/src/config_types.rs
@@ -296,23 +296,39 @@ pub enum Personality {
Pragmatic,
}
-/// Controls whether the model receives multi-agent delegation instructions and,
-/// when it does, whether it should only spawn sub-agents after an explicit user
-/// request or may delegate proactively when doing so would help. `none` leaves
-/// the multi-agent tools available without injecting delegation instructions.
-#[derive(
- Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Display, JsonSchema, TS, Default,
-)]
-#[serde(rename_all = "camelCase")]
+/// Controls the effective multi-agent delegation instructions for a turn. `custom` means the
+/// configured mode hint defines the policy instead of a built-in policy.
+#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Display, JsonSchema, TS, Default)]
+#[serde(rename_all = "camelCase", from = "MultiAgentModeWire")]
#[ts(rename_all = "camelCase")]
#[strum(serialize_all = "camelCase")]
pub enum MultiAgentMode {
- None,
+ Custom(String),
#[default]
ExplicitRequestOnly,
Proactive,
}
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+enum MultiAgentModeWire {
+ None,
+ Custom(String),
+ ExplicitRequestOnly,
+ Proactive,
+}
+
+impl From<MultiAgentModeWire> for MultiAgentMode {
+ fn from(value: MultiAgentModeWire) -> Self {
+ match value {
+ MultiAgentModeWire::None => Self::Custom(String::new()),
+ MultiAgentModeWire::Custom(hint_text) => Self::Custom(hint_text),
+ MultiAgentModeWire::ExplicitRequestOnly => Self::ExplicitRequestOnly,
+ MultiAgentModeWire::Proactive => Self::Proactive,
+ }
+ }
+}
+
#[derive(
Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Display, JsonSchema, TS, Default,
)]
diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs
index 96a793bcd3..0096915efb 100644
--- a/codex-rs/protocol/src/protocol.rs
+++ b/codex-rs/protocol/src/protocol.rs
@@ -2668,7 +2668,7 @@ impl InitialHistory {
| RolloutItem::WorldState(_)
| RolloutItem::EventMsg(_) => None,
})
- .and_then(|turn_context| turn_context.multi_agent_mode)
+ .and_then(|turn_context| turn_context.multi_agent_mode.clone())
}
pub fn get_resumed_session_sources(&self) -> Option<(SessionSource, Option<ThreadSource>)> {
@@ -5741,6 +5741,25 @@ mod tests {
Ok(())
}
+ #[test]
+ fn latest_effective_multi_agent_mode_maps_legacy_none_to_empty_custom() -> Result<()> {
+ let value = json!({
+ "cwd": test_path_buf("/tmp"),
+ "approval_policy": "never",
+ "sandbox_policy": { "type": "danger-full-access" },
+ "model": "gpt-5",
+ "multi_agent_mode": "none",
+ "summary": "auto",
+ });
+ let item = RolloutItem::TurnContext(serde_json::from_value(value)?);
+
+ assert_eq!(
+ InitialHistory::Forked(vec![item]).get_latest_effective_multi_agent_mode(),
+ Some(MultiAgentMode::Custom(String::new()))
+ );
+ Ok(())
+ }
+
#[test]
fn turn_context_item_serializes_network_when_present() -> Result<()> {
let item = TurnContextItem {