mirror of
https://github.com/openai/codex.git
synced 2026-11-27 15:30:27 +00:00
Honor configured model defaults for spawned agents (#33631)
## What changed - Apply `agents.default_subagent_model` and `agents.default_subagent_reasoning_effort` when a spawn request does not provide explicit values, including agent job workers. - Allow full-history forks to use configured defaults or explicit model and reasoning-effort overrides while retaining the parent conversation context. - Preserve the selected model and reasoning effort when an agent role does not override them. ## Testing - Cover configured defaults, explicit override precedence, full-history forks, role application, and agent job workers. GitOrigin-RevId: b1efa8c9abeee82355088fceef57560433144595
This commit is contained in:
1 parent
0f44bca915
commit
21c37fb374
14 files changed
+299
-155
No files matched your search
@@ -2,9 +2,9 @@
|
||||
//!
|
||||
//! Roles are selected at spawn time and are loaded with the same config machinery as
|
||||
//! `config.toml`. This module resolves built-in and user-defined role files, inserts the role as a
|
||||
//! high-precedence layer, and preserves the caller's current provider and service tier unless the
|
||||
//! role layer sets them. It does not decide when to spawn a sub-agent or which role to use; the
|
||||
//! multi-agent tool handler owns that orchestration.
|
||||
//! high-precedence layer, and preserves the caller's current model, reasoning effort, provider,
|
||||
//! and service tier unless the role layer sets them. It does not decide when to spawn a sub-agent
|
||||
//! or which role to use; the multi-agent tool handler owns that orchestration.
|
||||
|
||||
use crate::config::AgentRoleConfig;
|
||||
use crate::config::Config;
|
||||
@@ -135,14 +135,18 @@ mod reload {
|
||||
preserve_current_provider: bool,
|
||||
preserve_current_service_tier: bool,
|
||||
) -> anyhow::Result<Config> {
|
||||
let preserve_current_model = role_layer_toml.get("model").is_none();
|
||||
let preserve_current_reasoning_effort =
|
||||
role_layer_toml.get("model_reasoning_effort").is_none();
|
||||
let config_layer_stack = build_config_layer_stack(config, &role_layer_toml)?;
|
||||
let merged_config = deserialize_effective_config(config, &config_layer_stack)?;
|
||||
|
||||
let next_config = Config::load_config_with_layer_stack(
|
||||
let mut next_config = Config::load_config_with_layer_stack(
|
||||
LOCAL_FS.as_ref(),
|
||||
merged_config,
|
||||
reload_overrides(
|
||||
config,
|
||||
preserve_current_model,
|
||||
preserve_current_provider,
|
||||
preserve_current_service_tier,
|
||||
),
|
||||
@@ -150,6 +154,11 @@ mod reload {
|
||||
config_layer_stack,
|
||||
)
|
||||
.await?;
|
||||
if preserve_current_reasoning_effort {
|
||||
next_config
|
||||
.model_reasoning_effort
|
||||
.clone_from(&config.model_reasoning_effort);
|
||||
}
|
||||
Ok(next_config)
|
||||
}
|
||||
|
||||
@@ -200,11 +209,15 @@ mod reload {
|
||||
|
||||
fn reload_overrides(
|
||||
config: &Config,
|
||||
preserve_current_model: bool,
|
||||
preserve_current_provider: bool,
|
||||
preserve_current_service_tier: bool,
|
||||
) -> ConfigOverrides {
|
||||
ConfigOverrides {
|
||||
cwd: Some(config.cwd.to_path_buf()),
|
||||
model: preserve_current_model
|
||||
.then(|| config.model.clone())
|
||||
.flatten(),
|
||||
model_provider: preserve_current_provider.then(|| config.model_provider_id.clone()),
|
||||
service_tier: preserve_current_service_tier.then(|| config.service_tier.clone()),
|
||||
codex_linux_sandbox_exe: config.codex_linux_sandbox_exe.clone(),
|
||||
|
||||
@@ -183,8 +183,8 @@ async fn apply_role_preserves_unspecified_keys() {
|
||||
config.main_execve_wrapper_exe = Some(PathBuf::from("/tmp/codex-execve-wrapper"));
|
||||
let role_path = write_role_config(
|
||||
&home,
|
||||
"effort-only.toml",
|
||||
"developer_instructions = \"Stay focused\"\nmodel_reasoning_effort = \"high\"",
|
||||
"instructions-only.toml",
|
||||
"developer_instructions = \"Stay focused\"",
|
||||
)
|
||||
.await;
|
||||
config.agent_roles.insert(
|
||||
@@ -196,12 +196,17 @@ async fn apply_role_preserves_unspecified_keys() {
|
||||
},
|
||||
);
|
||||
|
||||
config.model = Some("spawn-model".to_string());
|
||||
config.model_reasoning_effort = Some(ReasoningEffort::Low);
|
||||
|
||||
apply_role_to_config(&mut config, Some("custom"))
|
||||
.await
|
||||
.expect("custom role should apply");
|
||||
|
||||
assert_eq!(config.model.as_deref(), Some("base-model"));
|
||||
assert_eq!(config.model_reasoning_effort, Some(ReasoningEffort::High));
|
||||
assert_eq!(
|
||||
(config.model.as_deref(), config.model_reasoning_effort),
|
||||
(Some("spawn-model"), Some(ReasoningEffort::Low)),
|
||||
);
|
||||
assert_eq!(
|
||||
config.codex_linux_sandbox_exe,
|
||||
Some(PathBuf::from("/tmp/codex-linux-sandbox"))
|
||||
|
||||
@@ -863,10 +863,10 @@ pub struct Config {
|
||||
/// User-configured maximum number of spawned agent threads per session.
|
||||
pub agent_max_threads: Option<usize>,
|
||||
|
||||
/// Reserved default model for spawned subagents.
|
||||
/// Default model for spawned subagents when the spawn call does not select one.
|
||||
pub agent_default_subagent_model: Option<String>,
|
||||
|
||||
/// Reserved default reasoning effort for spawned subagents.
|
||||
/// Default reasoning effort for spawned subagents when the spawn call does not select one.
|
||||
pub agent_default_subagent_reasoning_effort: Option<ReasoningEffort>,
|
||||
|
||||
/// Maximum runtime in seconds for agent job workers before they are failed.
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::function_tool::FunctionCallError;
|
||||
use crate::session::session::Session;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
use crate::tools::handlers::multi_agents::build_agent_spawn_config;
|
||||
use crate::tools::handlers::multi_agents_common::apply_requested_spawn_agent_model_overrides;
|
||||
use crate::tools::handlers::parse_arguments;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::error::CodexErr;
|
||||
@@ -124,7 +125,15 @@ async fn build_runner_options(
|
||||
}
|
||||
let max_concurrency = normalize_concurrency(requested_concurrency, agent_max_threads);
|
||||
let base_instructions = session.get_base_instructions().await;
|
||||
let spawn_config = build_agent_spawn_config(&base_instructions, turn.as_ref())?;
|
||||
let mut spawn_config = build_agent_spawn_config(&base_instructions, turn.as_ref())?;
|
||||
apply_requested_spawn_agent_model_overrides(
|
||||
session,
|
||||
turn,
|
||||
&mut spawn_config,
|
||||
/*requested_model*/ None,
|
||||
/*requested_reasoning_effort*/ None,
|
||||
)
|
||||
.await?;
|
||||
Ok(JobRunnerOptions {
|
||||
max_concurrency,
|
||||
spawn_config,
|
||||
|
||||
@@ -92,20 +92,17 @@ async fn handle_spawn_agent(
|
||||
config.service_tier = Some(service_tier.clone());
|
||||
}
|
||||
if args.fork_context {
|
||||
reject_full_fork_spawn_overrides(
|
||||
role_name,
|
||||
args.model.as_deref(),
|
||||
args.reasoning_effort.clone(),
|
||||
)?;
|
||||
} else {
|
||||
apply_requested_spawn_agent_model_overrides(
|
||||
&session,
|
||||
turn.as_ref(),
|
||||
&mut config,
|
||||
args.model.as_deref(),
|
||||
args.reasoning_effort.clone(),
|
||||
)
|
||||
.await?;
|
||||
reject_full_fork_agent_type_override(role_name)?;
|
||||
}
|
||||
apply_requested_spawn_agent_model_overrides(
|
||||
&session,
|
||||
turn.as_ref(),
|
||||
&mut config,
|
||||
args.model.as_deref(),
|
||||
args.reasoning_effort.clone(),
|
||||
)
|
||||
.await?;
|
||||
if !args.fork_context {
|
||||
apply_role_to_config(&mut config, role_name)
|
||||
.await
|
||||
.map_err(FunctionCallError::RespondToModel)?;
|
||||
|
||||
@@ -201,14 +201,12 @@ fn build_agent_shared_config(turn: &TurnContext) -> Result<Config, FunctionCallE
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub(crate) fn reject_full_fork_spawn_overrides(
|
||||
pub(crate) fn reject_full_fork_agent_type_override(
|
||||
agent_type: Option<&str>,
|
||||
model: Option<&str>,
|
||||
reasoning_effort: Option<ReasoningEffort>,
|
||||
) -> Result<(), FunctionCallError> {
|
||||
if agent_type.is_some() || model.is_some() || reasoning_effort.is_some() {
|
||||
if agent_type.is_some() {
|
||||
return Err(FunctionCallError::RespondToModel(
|
||||
"Full-history forked agents inherit the parent agent type, model, and reasoning effort; omit agent_type, model, and reasoning_effort, or spawn without a full-history fork.".to_string(),
|
||||
"Full-history forked agents inherit the parent agent type; omit agent_type, or spawn without a full-history fork.".to_string(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
@@ -249,6 +247,9 @@ pub(crate) async fn apply_requested_spawn_agent_model_overrides(
|
||||
requested_model: Option<&str>,
|
||||
requested_reasoning_effort: Option<ReasoningEffort>,
|
||||
) -> Result<(), FunctionCallError> {
|
||||
let requested_model = requested_model.or(turn.config.agent_default_subagent_model.as_deref());
|
||||
let requested_reasoning_effort = requested_reasoning_effort
|
||||
.or_else(|| turn.config.agent_default_subagent_reasoning_effort.clone());
|
||||
if requested_model.is_none() && requested_reasoning_effort.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -339,42 +339,7 @@ async fn spawn_agent_fork_context_rejects_agent_type_override() {
|
||||
assert_eq!(
|
||||
err,
|
||||
FunctionCallError::RespondToModel(
|
||||
"Full-history forked agents inherit the parent agent type, model, and reasoning effort; omit agent_type, model, and reasoning_effort, or spawn without a full-history fork.".to_string(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn spawn_agent_fork_context_rejects_child_model_overrides() {
|
||||
let (mut session, turn) = make_session_and_context().await;
|
||||
let manager = thread_manager();
|
||||
let root = manager
|
||||
.start_thread((*turn.config).clone())
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
session.services.agent_control = manager.agent_control();
|
||||
session.thread_id = root.thread_id;
|
||||
|
||||
let err = SpawnAgentHandler::default()
|
||||
.handle(invocation(
|
||||
Arc::new(session),
|
||||
Arc::new(turn),
|
||||
"spawn_agent",
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"model": "gpt-5-child-override",
|
||||
"reasoning_effort": "low",
|
||||
"fork_context": true
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.err()
|
||||
.expect("forked spawn should reject child model overrides");
|
||||
|
||||
assert_eq!(
|
||||
err,
|
||||
FunctionCallError::RespondToModel(
|
||||
"Full-history forked agents inherit the parent agent type, model, and reasoning effort; omit agent_type, model, and reasoning_effort, or spawn without a full-history fork.".to_string(),
|
||||
"Full-history forked agents inherit the parent agent type; omit agent_type, or spawn without a full-history fork.".to_string(),
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -420,48 +385,7 @@ async fn multi_agent_v2_spawn_fork_turns_all_rejects_agent_type_override() {
|
||||
assert_eq!(
|
||||
err,
|
||||
FunctionCallError::RespondToModel(
|
||||
"Full-history forked agents inherit the parent agent type, model, and reasoning effort; omit agent_type, model, and reasoning_effort, or spawn without a full-history fork.".to_string(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn multi_agent_v2_spawn_defaults_to_full_fork_and_rejects_child_model_overrides() {
|
||||
let (mut session, mut turn) = make_session_and_context().await;
|
||||
let manager = thread_manager();
|
||||
let root = manager
|
||||
.start_thread((*turn.config).clone())
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
session.services.agent_control = manager.agent_control();
|
||||
session.thread_id = root.thread_id;
|
||||
let mut config = (*turn.config).clone();
|
||||
config
|
||||
.features
|
||||
.enable(Feature::MultiAgentV2)
|
||||
.expect("test config should allow feature update");
|
||||
set_turn_config(&mut turn, config);
|
||||
|
||||
let err = SpawnAgentHandlerV2::default()
|
||||
.handle(invocation(
|
||||
Arc::new(session),
|
||||
Arc::new(turn),
|
||||
"spawn_agent",
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"task_name": "fork_context_v2",
|
||||
"model": "gpt-5-child-override",
|
||||
"reasoning_effort": "low"
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.err()
|
||||
.expect("default full fork should reject child model overrides");
|
||||
|
||||
assert_eq!(
|
||||
err,
|
||||
FunctionCallError::RespondToModel(
|
||||
"Full-history forked agents inherit the parent agent type, model, and reasoning effort; omit agent_type, model, and reasoning_effort, or spawn without a full-history fork.".to_string(),
|
||||
"Full-history forked agents inherit the parent agent type; omit agent_type, or spawn without a full-history fork.".to_string(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,26 +61,22 @@ async fn handle_spawn_agent(
|
||||
let child_depth = next_thread_spawn_depth(&session_source);
|
||||
let mut config =
|
||||
build_agent_spawn_config(&session.get_base_instructions().await, turn.as_ref())?;
|
||||
// TODO(jif): Apply `agents.default_subagent_model` as the default model here.
|
||||
// TODO(jif): Apply `agents.default_subagent_reasoning_effort` as the default effort here.
|
||||
if let Some(service_tier) = args.service_tier.as_ref() {
|
||||
config.service_tier = Some(service_tier.clone());
|
||||
}
|
||||
if matches!(fork_mode, Some(SpawnAgentForkMode::FullHistory)) {
|
||||
reject_full_fork_spawn_overrides(
|
||||
role_name,
|
||||
args.model.as_deref(),
|
||||
args.reasoning_effort.clone(),
|
||||
)?;
|
||||
} else {
|
||||
apply_requested_spawn_agent_model_overrides(
|
||||
&session,
|
||||
turn.as_ref(),
|
||||
&mut config,
|
||||
args.model.as_deref(),
|
||||
args.reasoning_effort.clone(),
|
||||
)
|
||||
.await?;
|
||||
let is_full_history_fork = matches!(fork_mode, Some(SpawnAgentForkMode::FullHistory));
|
||||
if is_full_history_fork {
|
||||
reject_full_fork_agent_type_override(role_name)?;
|
||||
}
|
||||
apply_requested_spawn_agent_model_overrides(
|
||||
&session,
|
||||
turn.as_ref(),
|
||||
&mut config,
|
||||
args.model.as_deref(),
|
||||
args.reasoning_effort.clone(),
|
||||
)
|
||||
.await?;
|
||||
if !is_full_history_fork {
|
||||
apply_role_to_config(&mut config, role_name)
|
||||
.await
|
||||
.map_err(FunctionCallError::RespondToModel)?;
|
||||
|
||||
Reference in new issue
Block a user