mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Allow per-subagent service tiers in spawn_agent (#63376)
## Why Subagents can inherit the root session's service tier or get one from their role. A per-spawn override lets a caller choose a tier for an individual child without changing those defaults. ## What changed Enable the optional `service_tier` argument for v1 and v2 `spawn_agent` with `multi_agent_v2.expose_spawn_agent_service_tier`. The setting is off by default, and tool schemas expose the argument alongside model selection. Omit the argument to use normal inheritance, pass `default` to request the default tier, or specify a tier available for the child's model and provider. Unavailable explicit tiers return a spawn error. Persist the child's choice across eviction and reload. Parent, sibling, and descendant agents continue to use their usual tier selection. ## Testing Extend coverage for tier selection in model requests, rejection of unadvertised Flex on Bedrock, and restoration after eviction without passing the override to grandchildren. GitOrigin-RevId: 2e9b92af44232b6a5682fe2cd97980f17cbb5d97
This commit is contained in:
BIN
Binary file not shown.
@@ -57,20 +57,6 @@ impl From<&ThreadSettingsSnapshot> for PersistedResumeSettings {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn latest_owned_thread_settings(
|
||||
history: &[RolloutItem],
|
||||
thread_id: ThreadId,
|
||||
) -> Option<&ThreadSettingsSnapshot> {
|
||||
history.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(thread_id) =>
|
||||
{
|
||||
Some(&event.thread_settings)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
fn latest_persisted_resume_settings(history: &[RolloutItem]) -> Option<PersistedResumeSettings> {
|
||||
history
|
||||
.iter()
|
||||
|
||||
@@ -33,6 +33,7 @@ fn settings_item(
|
||||
ThreadSettingsAppliedEvent {
|
||||
thread_id,
|
||||
thread_settings: ThreadSettingsSnapshot {
|
||||
spawn_service_tier_override: None,
|
||||
disabled_plugin_ids: Vec::new(),
|
||||
guardian_retention: None,
|
||||
model: "gpt-5".to_string(),
|
||||
|
||||
@@ -15,7 +15,6 @@ use resume_permit::ResumePermit;
|
||||
mod thread_resume_account;
|
||||
|
||||
use super::persisted_resume_settings::PersistedResumeSettings;
|
||||
use super::persisted_resume_settings::latest_owned_thread_settings;
|
||||
use super::persisted_resume_settings::latest_persisted_model_settings;
|
||||
use super::thread_enrichment::enrich_loaded_threads;
|
||||
use super::thread_fork_goal::inherit_thread_goal_snapshot;
|
||||
@@ -4315,11 +4314,7 @@ impl ThreadRequestProcessor {
|
||||
permit.finish_probe();
|
||||
// Copied or referenced history can contain another thread's settings. Only snapshots
|
||||
// explicitly owned by this thread can restore its cwd and workspace folders.
|
||||
let history_settings = if let InitialHistory::Resumed(resumed) = &thread_history {
|
||||
latest_owned_thread_settings(&resumed.history, resumed.conversation_id)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let history_settings = thread_history.resumed_thread_settings();
|
||||
let history_cwd = history_settings
|
||||
.map(|settings| settings.cwd.to_path_buf())
|
||||
.or_else(|| thread_history.session_cwd());
|
||||
|
||||
@@ -3520,6 +3520,10 @@
|
||||
"description": "Exposes `model` and `reasoning_effort` on the multi-agent v2 spawn tool and adds corresponding guidance to root and subagent usage hints.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"expose_spawn_agent_service_tier": {
|
||||
"description": "Allow V1 and V2 `spawn_agent` to select a `service_tier` for one child. Defaults to false.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"hide_spawn_agent_metadata": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -43,9 +43,12 @@ pub(crate) struct SpawnConfigOptions<'a> {
|
||||
pub(crate) role_name: Option<&'a str>,
|
||||
pub(crate) model: Option<&'a str>,
|
||||
pub(crate) reasoning_effort: Option<ReasoningEffort>,
|
||||
pub(crate) service_tier: Option<String>,
|
||||
}
|
||||
|
||||
pub(crate) struct PreparedSpawnConfig {
|
||||
/// The explicit choice for this child. Config retains the tier it would otherwise inherit.
|
||||
pub(crate) service_tier: Option<String>,
|
||||
pub(crate) config: Config,
|
||||
pub(crate) role_name: Option<String>,
|
||||
}
|
||||
@@ -74,7 +77,12 @@ pub(crate) async fn prepare_agent_spawn_config(
|
||||
AgentRuntimeServices::Controller => true,
|
||||
AgentRuntimeServices::Host(services) => services.service_tier.is_some(),
|
||||
};
|
||||
if !shares_service_tier {
|
||||
if !shares_service_tier
|
||||
&& turn
|
||||
.initial_settings
|
||||
.spawn_service_tier_override()
|
||||
.is_none()
|
||||
{
|
||||
// Inherit the parent's thread preference before applying child role overrides.
|
||||
config.service_tier = session.thread_settings_snapshot().await.service_tier;
|
||||
}
|
||||
@@ -91,8 +99,11 @@ pub(crate) async fn prepare_agent_spawn_config(
|
||||
.clone_from(&turn.developer_instructions);
|
||||
}
|
||||
}
|
||||
if shares_service_tier {
|
||||
apply_spawn_agent_service_tier(session, &mut config).await?;
|
||||
let requested_tier = options
|
||||
.service_tier
|
||||
.filter(|_| turn.config.multi_agent_v2.expose_spawn_agent_service_tier);
|
||||
if shares_service_tier || requested_tier.is_some() {
|
||||
apply_spawn_agent_service_tier(session, &mut config, requested_tier.as_deref()).await?;
|
||||
}
|
||||
apply_spawn_agent_runtime_overrides(&mut config, turn)?;
|
||||
|
||||
@@ -109,7 +120,11 @@ pub(crate) async fn prepare_agent_spawn_config(
|
||||
.then_some(DEFAULT_ROLE_NAME)
|
||||
})
|
||||
.map(str::to_owned);
|
||||
Ok(PreparedSpawnConfig { config, role_name })
|
||||
Ok(PreparedSpawnConfig {
|
||||
config,
|
||||
role_name,
|
||||
service_tier: requested_tier,
|
||||
})
|
||||
}
|
||||
|
||||
/// Builds the base config snapshot for a newly spawned sub-agent.
|
||||
@@ -144,6 +159,10 @@ pub(crate) fn build_agent_resume_config(turn: &TurnContext) -> Result<Config, St
|
||||
fn build_agent_shared_config(turn: &TurnContext) -> Result<Config, String> {
|
||||
let base_config = turn.config.clone();
|
||||
let mut config = (*base_config).clone();
|
||||
// Both spawn and resume need the ordinary tier, even when the caller uses its own.
|
||||
if let Some(tier) = turn.initial_settings.spawn_service_tier_override() {
|
||||
config.service_tier.clone_from(&tier.inherited_service_tier);
|
||||
}
|
||||
if config
|
||||
.features
|
||||
.enabled(Feature::SubagentDefaultContextLimits)
|
||||
@@ -281,15 +300,16 @@ async fn apply_requested_spawn_agent_model_overrides(
|
||||
pub(crate) async fn apply_spawn_agent_service_tier(
|
||||
session: &Session,
|
||||
config: &mut Config,
|
||||
requested: Option<&str>,
|
||||
) -> Result<(), String> {
|
||||
let Some(service_tier) =
|
||||
crate::agent::host::service_tier(session, config.service_tier.clone()).await
|
||||
else {
|
||||
config.service_tier = None;
|
||||
if requested.is_none() {
|
||||
config.service_tier =
|
||||
crate::agent::host::service_tier(session, config.service_tier.take()).await;
|
||||
}
|
||||
let Some(service_tier) = requested.or(config.service_tier.as_deref()) else {
|
||||
return Ok(());
|
||||
};
|
||||
if service_tier == SERVICE_TIER_DEFAULT_REQUEST_VALUE {
|
||||
config.service_tier = Some(service_tier);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -302,9 +322,23 @@ pub(crate) async fn apply_spawn_agent_service_tier(
|
||||
.get_model_info(model.as_str(), &config.to_models_manager_config())
|
||||
.await;
|
||||
|
||||
config.service_tier = model_info
|
||||
.supports_service_tier(service_tier.as_str())
|
||||
.then_some(service_tier);
|
||||
let supported = model_info.supports_service_tier(service_tier);
|
||||
if requested.is_some()
|
||||
&& (!supported
|
||||
|| !config.features.service_tier_enabled(service_tier)
|
||||
|| !crate::client_common::provider_allows_service_tier(
|
||||
&config.model_provider,
|
||||
&model_info,
|
||||
service_tier,
|
||||
))
|
||||
{
|
||||
return Err(format!(
|
||||
"Service tier `{service_tier}` is unavailable for model `{model}`. Omit service_tier to inherit the usual tier."
|
||||
));
|
||||
}
|
||||
if !supported {
|
||||
config.service_tier = None;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -257,6 +257,7 @@ async fn spawn_v2_subagent(
|
||||
control.clone(),
|
||||
Some(parent_thread_id),
|
||||
/*inherited_exec_policy*/ None,
|
||||
/*spawn_service_tier*/ None,
|
||||
)
|
||||
.await
|
||||
.expect("spawn v2 subagent")
|
||||
|
||||
@@ -927,6 +927,7 @@ impl LocalAgentControl {
|
||||
self.clone(),
|
||||
parent_thread_id,
|
||||
inherited_exec_policy,
|
||||
options.service_tier,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| err.with_agent_context(AgentErrorContext::ChildStartup))?;
|
||||
|
||||
@@ -2443,6 +2443,7 @@ async fn spawn_agent_fork_from_paginated_parent_uses_model_context_prefix(
|
||||
ThreadSettingsAppliedEvent {
|
||||
thread_id: Some(parent_thread_id),
|
||||
thread_settings: ThreadSettingsSnapshot {
|
||||
spawn_service_tier_override: None,
|
||||
disabled_plugin_ids: Vec::new(),
|
||||
guardian_retention: None,
|
||||
model: "parent-only-model".to_string(),
|
||||
|
||||
@@ -90,6 +90,7 @@ async fn prepare_spawn_inputs(
|
||||
thread_options.inherited_environments = options.environments;
|
||||
let client_metadata = parent.session.app_server_client_metadata().await;
|
||||
let inheritance = PreparedChildInheritance {
|
||||
spawn_service_tier: options.service_tier,
|
||||
instructions,
|
||||
exec_policy,
|
||||
originator: parent.session.originator().await,
|
||||
|
||||
@@ -138,6 +138,7 @@ async fn same_manager_creation_retains_step_executor_and_shares_exec_policy() ->
|
||||
);
|
||||
config.features.enable(Feature::MultiAgentV2)?;
|
||||
config.features.enable(Feature::DeferredExecutor)?;
|
||||
config.multi_agent_v2.expose_spawn_agent_service_tier = true;
|
||||
let environments = manager.environment_manager();
|
||||
// Leave the handshake pending so the registration stays attached throughout the spawn.
|
||||
let listener = TcpListener::bind(("127.0.0.1", 0))?;
|
||||
@@ -193,6 +194,7 @@ async fn same_manager_creation_retains_step_executor_and_shares_exec_policy() ->
|
||||
fork_mode: None,
|
||||
agent_type: None,
|
||||
model: None,
|
||||
service_tier: Some("flex".into()),
|
||||
reasoning_effort: None,
|
||||
},
|
||||
HostThreadSpawnReservation {
|
||||
@@ -204,6 +206,10 @@ async fn same_manager_creation_retains_step_executor_and_shares_exec_policy() ->
|
||||
)
|
||||
.await?;
|
||||
let child = manager.get_thread(child_id).await?;
|
||||
assert_eq!(
|
||||
child.config_snapshot().await.service_tier.as_deref(),
|
||||
Some("flex")
|
||||
);
|
||||
assert!(
|
||||
child
|
||||
.thread_extension_data()
|
||||
|
||||
@@ -88,6 +88,7 @@ pub struct PreparedChildContext {
|
||||
}
|
||||
|
||||
pub(crate) struct PreparedChildInheritance {
|
||||
pub(crate) spawn_service_tier: Option<String>,
|
||||
pub(crate) instructions: SessionInstructions,
|
||||
pub(crate) exec_policy: Option<Arc<ExecPolicyManager>>,
|
||||
pub(crate) originator: String,
|
||||
|
||||
@@ -34,6 +34,7 @@ pub enum SpawnProgramSource {
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct SpawnAgentOptions {
|
||||
pub service_tier: Option<String>,
|
||||
pub request_country: codex_protocol::RequestCountry,
|
||||
pub fork_parent_spawn_call_id: Option<String>,
|
||||
pub fork_mode: Option<SpawnAgentForkMode>,
|
||||
|
||||
@@ -131,6 +131,7 @@ use crate::client_common::Prompt;
|
||||
use crate::client_common::ResponseEvent;
|
||||
use crate::client_common::ResponseStream;
|
||||
use crate::client_common::SamplingStream;
|
||||
use crate::client_common::provider_allows_service_tier;
|
||||
use crate::context::BaseInstructionsFragment;
|
||||
use crate::context::ContextualUserFragment;
|
||||
use crate::cyber_access_program;
|
||||
@@ -1353,13 +1354,7 @@ impl ModelClient {
|
||||
let service_tier = model_info
|
||||
.service_tier_for_request(service_tier)
|
||||
.filter(|tier| {
|
||||
// Bedrock requires an advertised tier, including for flex, which the
|
||||
// generic OpenAI resolver permits without catalog support.
|
||||
!self.state.provider.info().is_amazon_bedrock()
|
||||
|| model_info
|
||||
.service_tiers
|
||||
.iter()
|
||||
.any(|supported| supported.id == *tier)
|
||||
provider_allows_service_tier(self.state.provider.info(), model_info, tier)
|
||||
});
|
||||
if !include_internal {
|
||||
let captures_result_bodies = self.captures_result_bodies();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub use codex_api::ResponseEvent;
|
||||
use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::Result;
|
||||
use codex_protocol::models::BaseInstructions;
|
||||
@@ -72,6 +73,19 @@ impl Prompt {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn provider_allows_service_tier(
|
||||
provider: &ModelProviderInfo,
|
||||
model: &ModelInfo,
|
||||
service_tier: &str,
|
||||
) -> bool {
|
||||
// Bedrock requires an advertised tier, even for Flex.
|
||||
!provider.is_amazon_bedrock()
|
||||
|| model
|
||||
.service_tiers
|
||||
.iter()
|
||||
.any(|tier| tier.id == service_tier)
|
||||
}
|
||||
|
||||
fn normalize_image_details(items: &mut [ResponseItem], model_info: &ModelInfo) {
|
||||
for item in items {
|
||||
match item {
|
||||
|
||||
@@ -112,6 +112,7 @@ pub(crate) async fn run_codex_thread_interactive(
|
||||
thread_extension_init.insert((*context).clone());
|
||||
}
|
||||
let spawn_result = Session::spawn(SessionSpawnArgs {
|
||||
child_service_tier: None,
|
||||
attached_thread: false,
|
||||
startup: Some(Arc::clone(&startup)),
|
||||
config,
|
||||
|
||||
@@ -1477,6 +1477,7 @@ pub struct MultiAgentV2Config {
|
||||
pub tool_namespace: Option<String>,
|
||||
pub hide_spawn_agent_metadata: bool,
|
||||
pub expose_spawn_agent_model_overrides: bool,
|
||||
pub expose_spawn_agent_service_tier: bool,
|
||||
pub wait_agent_enabled: bool,
|
||||
pub interrupt_at_item_boundary: bool,
|
||||
pub disable_native_tools: bool,
|
||||
@@ -1502,6 +1503,7 @@ impl MultiAgentV2Config {
|
||||
tool_namespace: Some(DEFAULT_MULTI_AGENT_V2_TOOL_NAMESPACE.to_string()),
|
||||
hide_spawn_agent_metadata: true,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
expose_spawn_agent_service_tier: false,
|
||||
wait_agent_enabled: true,
|
||||
interrupt_at_item_boundary: false,
|
||||
disable_native_tools: false,
|
||||
@@ -3034,6 +3036,9 @@ fn resolve_multi_agent_v2_config(config_toml: &ConfigToml) -> MultiAgentV2Config
|
||||
let expose_spawn_agent_model_overrides = base
|
||||
.and_then(|config| config.expose_spawn_agent_model_overrides)
|
||||
.unwrap_or(default.expose_spawn_agent_model_overrides);
|
||||
let expose_spawn_agent_service_tier = base
|
||||
.and_then(|config| config.expose_spawn_agent_service_tier)
|
||||
.unwrap_or(default.expose_spawn_agent_service_tier);
|
||||
let root_agent_usage_hint_text = base
|
||||
.and_then(|config| config.root_agent_usage_hint_text.as_ref())
|
||||
.cloned();
|
||||
@@ -3087,6 +3092,7 @@ fn resolve_multi_agent_v2_config(config_toml: &ConfigToml) -> MultiAgentV2Config
|
||||
tool_namespace,
|
||||
hide_spawn_agent_metadata,
|
||||
expose_spawn_agent_model_overrides,
|
||||
expose_spawn_agent_service_tier,
|
||||
wait_agent_enabled,
|
||||
interrupt_at_item_boundary,
|
||||
disable_native_tools,
|
||||
|
||||
@@ -161,6 +161,7 @@ use codex_protocol::protocol::PrivateSessionEvent;
|
||||
use codex_protocol::protocol::PrivateSessionEventPayload;
|
||||
use codex_protocol::protocol::RawResponseItemEvent;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::SpawnServiceTierOverride;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::ThreadSettingsAppliedEvent;
|
||||
@@ -525,7 +526,14 @@ impl From<CompactedHistoryMetadata> for CompactedHistoryInstallation<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum ChildServiceTier {
|
||||
Requested(String),
|
||||
/// Internal reload supplies the parent's defaults. Restore a child-owned choice from history.
|
||||
Reload,
|
||||
}
|
||||
|
||||
pub(crate) struct SessionSpawnArgs {
|
||||
pub(crate) child_service_tier: Option<ChildServiceTier>,
|
||||
pub(crate) attached_thread: bool,
|
||||
pub(crate) startup: Option<Arc<startup::SessionStartup>>,
|
||||
pub(crate) config: Config,
|
||||
@@ -724,6 +732,7 @@ impl Session {
|
||||
attached_thread,
|
||||
startup,
|
||||
config,
|
||||
child_service_tier,
|
||||
request_country,
|
||||
prompt_cache_key,
|
||||
allow_provider_model_fallback,
|
||||
@@ -984,19 +993,10 @@ impl Session {
|
||||
});
|
||||
// TODO (aibrahim): Consolidate config.model and config.model_reasoning_effort into config.collaboration_mode
|
||||
// to avoid extracting these fields separately and constructing CollaborationMode here.
|
||||
let saved_settings = conversation_history.resumed_thread_settings();
|
||||
let persisted_collaboration_mode = match &conversation_history {
|
||||
InitialHistory::Resumed(resumed) => resumed
|
||||
.history
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(resumed.conversation_id) =>
|
||||
{
|
||||
Some(&event.thread_settings.collaboration_mode)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
InitialHistory::Resumed(resumed) => saved_settings
|
||||
.map(|settings| &settings.collaboration_mode)
|
||||
.or_else(|| {
|
||||
resumed
|
||||
.history
|
||||
@@ -1027,8 +1027,23 @@ impl Session {
|
||||
/*developer_instructions*/ None,
|
||||
)
|
||||
});
|
||||
let mut spawn_service_tier_override =
|
||||
saved_settings.and_then(|settings| settings.spawn_service_tier_override.clone());
|
||||
let service_tier = match child_service_tier {
|
||||
Some(ChildServiceTier::Requested(tier)) => {
|
||||
spawn_service_tier_override = Some(SpawnServiceTierOverride {
|
||||
inherited_service_tier: config.service_tier.clone(),
|
||||
});
|
||||
Some(tier)
|
||||
}
|
||||
Some(ChildServiceTier::Reload) if spawn_service_tier_override.is_some() => {
|
||||
saved_settings.and_then(|settings| settings.service_tier.clone())
|
||||
}
|
||||
// A caller resuming a thread can explicitly change or clear its tier.
|
||||
Some(ChildServiceTier::Reload) | None => config.service_tier.clone(),
|
||||
};
|
||||
let initial_service_tier_warning = unsupported_service_tier_warning(
|
||||
config.service_tier.as_deref(),
|
||||
service_tier.as_deref(),
|
||||
&config.features,
|
||||
&model_info,
|
||||
);
|
||||
@@ -1068,7 +1083,8 @@ impl Session {
|
||||
request_country,
|
||||
collaboration_mode,
|
||||
reasoning_summary: config.model_reasoning_summary,
|
||||
service_tier: config.service_tier.clone(),
|
||||
service_tier,
|
||||
spawn_service_tier_override,
|
||||
personality: config.personality,
|
||||
approval_policy: config.permissions.approval_policy.clone(),
|
||||
approvals_reviewer: config.approvals_reviewer,
|
||||
@@ -4412,10 +4428,17 @@ impl Session {
|
||||
.await
|
||||
}
|
||||
|
||||
fn inherits_root_service_tier(&self, session_source: &SessionSource) -> bool {
|
||||
fn inherits_root_service_tier(&self, turn_context: &TurnContext) -> bool {
|
||||
if turn_context
|
||||
.initial_settings
|
||||
.spawn_service_tier_override()
|
||||
.is_some()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
match &self.agent_runtime {
|
||||
crate::agent::host::AgentRuntimeServices::Controller => matches!(
|
||||
session_source,
|
||||
turn_context.session_source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. })
|
||||
),
|
||||
crate::agent::host::AgentRuntimeServices::Host(_) => {
|
||||
@@ -4458,7 +4481,7 @@ impl Session {
|
||||
.then(|| self.services.turn_environments.configured_snapshot_now()),
|
||||
)
|
||||
};
|
||||
if self.inherits_root_service_tier(&turn_context.session_source) {
|
||||
if self.inherits_root_service_tier(&turn_context) {
|
||||
let root_service_tier = tokio::select! {
|
||||
biased;
|
||||
tier = crate::agent::host::service_tier(self, settings.selected().service_tier.clone()) => tier,
|
||||
|
||||
@@ -333,6 +333,7 @@ impl SessionConfiguration {
|
||||
environment_selections: &[TurnEnvironmentSelection],
|
||||
) -> ThreadSettingsSnapshot {
|
||||
ThreadSettingsSnapshot {
|
||||
spawn_service_tier_override: self.step_settings.spawn_service_tier_override.clone(),
|
||||
model: self.step_settings.collaboration_mode.model().to_string(),
|
||||
model_provider_id: self.original_config_do_not_use.model_provider_id.clone(),
|
||||
service_tier: self.step_settings.service_tier.clone(),
|
||||
|
||||
@@ -386,8 +386,7 @@ async fn schedule_startup_prewarm_inner(
|
||||
let preconnect_model_info = Arc::clone(startup_turn_context.model_info());
|
||||
// Spawned subagents inherit the root's selection, with the same feature and model filtering
|
||||
// that capture applies to the actual request.
|
||||
let inherits_root_service_tier =
|
||||
session.inherits_root_service_tier(&startup_turn_context.session_source);
|
||||
let inherits_root_service_tier = session.inherits_root_service_tier(&startup_turn_context);
|
||||
let preconnect_service_tier = if inherits_root_service_tier {
|
||||
crate::session::get_service_tier(
|
||||
crate::agent::host::service_tier(
|
||||
|
||||
@@ -19,6 +19,7 @@ use codex_protocol::config_types::ServiceTier;
|
||||
use codex_protocol::openai_models::CatalogModel;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::SpawnServiceTierOverride;
|
||||
use codex_protocol::protocol::TurnContextItem;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -33,6 +34,8 @@ pub(crate) struct StepSettings {
|
||||
pub(crate) reasoning_summary: Option<ReasoningSummary>,
|
||||
/// Normalized requested tier; resolution filters it against the pinned model.
|
||||
pub(crate) service_tier: Option<String>,
|
||||
/// Present when this child owns its tier. Descendants inherit the saved preference.
|
||||
pub(crate) spawn_service_tier_override: Option<SpawnServiceTierOverride>,
|
||||
pub(crate) personality: Option<Personality>,
|
||||
pub(crate) approval_policy: Constrained<AskForApproval>,
|
||||
pub(crate) approvals_reviewer: ApprovalsReviewer,
|
||||
@@ -58,6 +61,10 @@ pub(crate) struct ResolvedStepSettings {
|
||||
}
|
||||
|
||||
impl ResolvedStepSettings {
|
||||
pub(crate) fn spawn_service_tier_override(&self) -> Option<&SpawnServiceTierOverride> {
|
||||
self.selected.spawn_service_tier_override.as_ref()
|
||||
}
|
||||
|
||||
pub(crate) fn request_country(&self) -> &RequestCountry {
|
||||
&self.selected.request_country
|
||||
}
|
||||
|
||||
@@ -304,6 +304,7 @@ fn configured_settings() -> StepSettings {
|
||||
},
|
||||
reasoning_summary: Some(ReasoningSummary::Concise),
|
||||
service_tier: None,
|
||||
spawn_service_tier_override: None,
|
||||
personality: Some(Personality::Friendly),
|
||||
approval_policy: Constrained::allow_any(AskForApproval::OnRequest),
|
||||
approvals_reviewer: ApprovalsReviewer::User,
|
||||
|
||||
@@ -5000,6 +5000,7 @@ pub(crate) async fn make_session_configuration_for_tests() -> SessionConfigurati
|
||||
collaboration_mode,
|
||||
reasoning_summary: config.model_reasoning_summary,
|
||||
service_tier: None,
|
||||
spawn_service_tier_override: None,
|
||||
personality: config.personality,
|
||||
approval_policy: config.permissions.approval_policy.clone(),
|
||||
approvals_reviewer: config.approvals_reviewer,
|
||||
@@ -6587,6 +6588,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
collaboration_mode,
|
||||
reasoning_summary: config.model_reasoning_summary,
|
||||
service_tier: None,
|
||||
spawn_service_tier_override: None,
|
||||
personality: config.personality,
|
||||
approval_policy: config.permissions.approval_policy.clone(),
|
||||
approvals_reviewer: config.approvals_reviewer,
|
||||
@@ -6938,6 +6940,7 @@ async fn make_session_with_config_and_rx(
|
||||
collaboration_mode,
|
||||
reasoning_summary: config.model_reasoning_summary,
|
||||
service_tier: None,
|
||||
spawn_service_tier_override: None,
|
||||
personality: config.personality,
|
||||
approval_policy: config.permissions.approval_policy.clone(),
|
||||
approvals_reviewer: config.approvals_reviewer,
|
||||
@@ -7079,6 +7082,7 @@ async fn make_session_with_history_source_and_agent_control_and_rx(
|
||||
collaboration_mode,
|
||||
reasoning_summary: config.model_reasoning_summary,
|
||||
service_tier: None,
|
||||
spawn_service_tier_override: None,
|
||||
personality: config.personality,
|
||||
approval_policy: config.permissions.approval_policy.clone(),
|
||||
approvals_reviewer: config.approvals_reviewer,
|
||||
@@ -8953,6 +8957,7 @@ where
|
||||
collaboration_mode,
|
||||
reasoning_summary: config.model_reasoning_summary,
|
||||
service_tier: None,
|
||||
spawn_service_tier_override: None,
|
||||
personality: config.personality,
|
||||
approval_policy: config.permissions.approval_policy.clone(),
|
||||
approvals_reviewer: config.approvals_reviewer,
|
||||
|
||||
@@ -1330,6 +1330,7 @@ async fn guardian_subagent_does_not_inherit_parent_exec_policy_rules() {
|
||||
let mut thread_extension_init = codex_extension_api::ExtensionDataInit::default();
|
||||
thread_extension_init.insert(codex_extension_api::SessionIsolation::Isolated);
|
||||
let (session, io) = Session::spawn(SessionSpawnArgs {
|
||||
child_service_tier: None,
|
||||
attached_thread: false,
|
||||
startup: None,
|
||||
config,
|
||||
|
||||
@@ -35,6 +35,7 @@ use crate::exec_policy::ExecPolicyManager;
|
||||
use crate::exec_policy::InheritedExecPolicy;
|
||||
use crate::mcp::McpManager;
|
||||
use crate::rollout::truncation;
|
||||
use crate::session::ChildServiceTier;
|
||||
use crate::session::ForkPersistence;
|
||||
use crate::session::GitEnrichmentPolicy;
|
||||
use crate::session::INITIAL_SUBMIT_ID;
|
||||
@@ -513,6 +514,7 @@ struct PreparedChildOrigin {
|
||||
}
|
||||
|
||||
struct ThreadSpawnRequest {
|
||||
child_service_tier: Option<ChildServiceTier>,
|
||||
ready_notification: ThreadReadyNotification,
|
||||
startup: Option<Arc<crate::session::startup::SessionStartup>>,
|
||||
options: StartThreadOptions,
|
||||
@@ -537,6 +539,7 @@ impl ThreadSpawnRequest {
|
||||
agent_control: impl Into<AgentControlInit>,
|
||||
) -> Self {
|
||||
Self {
|
||||
child_service_tier: None,
|
||||
ready_notification: ThreadReadyNotification::Emit,
|
||||
startup: None,
|
||||
options,
|
||||
@@ -2447,6 +2450,7 @@ impl ThreadManagerState {
|
||||
agent_control: LocalAgentControl,
|
||||
parent_thread_id: Option<ThreadId>,
|
||||
inherited_exec_policy: Option<Arc<crate::exec_policy::ExecPolicyManager>>,
|
||||
spawn_service_tier: Option<String>,
|
||||
) -> CodexResult<NewThread> {
|
||||
(options.client_mcp_extensions, options.prompt_cache_key) =
|
||||
self.inherited_child_settings(parent_thread_id).await;
|
||||
@@ -2456,6 +2460,7 @@ impl ThreadManagerState {
|
||||
request.inherited_runtime_auth = Some(runtime_auth);
|
||||
request.parent_thread_id = parent_thread_id;
|
||||
request.inherited_exec_policy = inherited_exec_policy;
|
||||
request.child_service_tier = spawn_service_tier.map(ChildServiceTier::Requested);
|
||||
if forked {
|
||||
request.forked_from_thread_id = parent_thread_id;
|
||||
request.fork_persistence = ForkPersistence::CopiedDeferred;
|
||||
@@ -2494,6 +2499,9 @@ impl ThreadManagerState {
|
||||
};
|
||||
request.inherited_instructions = Some(inheritance.instructions);
|
||||
request.inherited_exec_policy = inheritance.exec_policy;
|
||||
request.child_service_tier = inheritance
|
||||
.spawn_service_tier
|
||||
.map(ChildServiceTier::Requested);
|
||||
request.prepared_child = Some(PreparedChildOrigin {
|
||||
history_initialization,
|
||||
originator: inheritance.originator,
|
||||
@@ -2543,6 +2551,7 @@ impl ThreadManagerState {
|
||||
let mut request =
|
||||
ThreadSpawnRequest::new(options, Arc::clone(&self.auth_manager), agent_control);
|
||||
request.parent_thread_id = parent_thread_id;
|
||||
request.child_service_tier = Some(ChildServiceTier::Reload);
|
||||
request.inherited_environments = inherited_environments;
|
||||
request.inherited_instructions = inherited_instructions;
|
||||
request.inherited_exec_policy = inherited_exec_policy;
|
||||
@@ -2627,6 +2636,7 @@ impl ThreadManagerState {
|
||||
let startup_guard =
|
||||
owns_startup.then(|| SessionStartupGuard::new(Arc::clone(&startup_state)));
|
||||
let ThreadSpawnRequest {
|
||||
child_service_tier,
|
||||
ready_notification,
|
||||
startup,
|
||||
options,
|
||||
@@ -3089,6 +3099,7 @@ impl ThreadManagerState {
|
||||
let registered = Arc::new(AtomicBool::new(false));
|
||||
thread_extension_init.insert(ThreadRegistrationReceipt(Arc::clone(®istered)));
|
||||
let spawn_result = Session::spawn(SessionSpawnArgs {
|
||||
child_service_tier,
|
||||
attached_thread,
|
||||
startup,
|
||||
config,
|
||||
|
||||
@@ -983,6 +983,7 @@ async fn child_session_inherits_resumed_parent_auth(host_child: bool) {
|
||||
control.into(),
|
||||
parent.thread_id,
|
||||
crate::agent::host::PreparedChildInheritance {
|
||||
spawn_service_tier: None,
|
||||
instructions: parent.thread.session.inherited_instructions().await,
|
||||
exec_policy: None,
|
||||
originator: parent.thread.session.originator().await,
|
||||
@@ -998,6 +999,7 @@ async fn child_session_inherits_resumed_parent_auth(host_child: bool) {
|
||||
control,
|
||||
Some(parent.thread_id),
|
||||
/*inherited_exec_policy*/ None,
|
||||
/*spawn_service_tier*/ None,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@@ -3744,6 +3746,7 @@ async fn new_uses_active_provider_for_model_refresh(with_cache: bool) {
|
||||
.control(started.thread.session.session_id()),
|
||||
Some(started.thread_id),
|
||||
/*inherited_exec_policy*/ None,
|
||||
/*spawn_service_tier*/ None,
|
||||
)
|
||||
.await
|
||||
.expect("spawn child with the parent's provider headers");
|
||||
|
||||
@@ -37,6 +37,7 @@ pub struct ThreadCreateRequest {
|
||||
pub agent_type: Option<String>,
|
||||
pub model: Option<String>,
|
||||
pub reasoning_effort: Option<ReasoningEffort>,
|
||||
pub service_tier: Option<String>,
|
||||
}
|
||||
|
||||
pub(crate) struct ThreadSpawnRequest {
|
||||
@@ -48,6 +49,7 @@ pub(crate) struct ThreadSpawnRequest {
|
||||
pub agent_type: Option<String>,
|
||||
pub model: Option<String>,
|
||||
pub reasoning_effort: Option<ReasoningEffort>,
|
||||
pub service_tier: Option<String>,
|
||||
}
|
||||
|
||||
impl ThreadSpawnRequest {
|
||||
@@ -69,6 +71,7 @@ impl ThreadSpawnRequest {
|
||||
agent_type: self.agent_type,
|
||||
model: self.model,
|
||||
reasoning_effort: self.reasoning_effort,
|
||||
service_tier: self.service_tier,
|
||||
},
|
||||
self.message,
|
||||
))
|
||||
@@ -150,6 +153,7 @@ pub(crate) async fn prepare(
|
||||
agent_type,
|
||||
model,
|
||||
reasoning_effort,
|
||||
service_tier,
|
||||
} = request;
|
||||
let role_name = agent_type
|
||||
.as_deref()
|
||||
@@ -164,6 +168,7 @@ pub(crate) async fn prepare(
|
||||
role_name,
|
||||
model: model.as_deref(),
|
||||
reasoning_effort,
|
||||
service_tier,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -212,6 +217,7 @@ pub(crate) async fn prepare(
|
||||
config,
|
||||
source: spawn_source,
|
||||
options: SpawnAgentOptions {
|
||||
service_tier: prepared.service_tier,
|
||||
request_country: step_context.settings.request_country().clone(),
|
||||
fork_parent_spawn_call_id: fork_mode.as_ref().map(|_| call_id.to_string()),
|
||||
fork_mode,
|
||||
|
||||
@@ -85,6 +85,20 @@ async fn handle_spawn_agent(
|
||||
.into_iter()
|
||||
.map(ResolvedUserInput::from_client)
|
||||
.collect();
|
||||
let prepared = prepare_agent_spawn_config(
|
||||
&session,
|
||||
step_context.as_ref(),
|
||||
SpawnConfigOptions {
|
||||
version: SpawnConfigVersion::V1,
|
||||
full_history_fork: args.fork_context,
|
||||
role_name,
|
||||
model: args.model.as_deref(),
|
||||
reasoning_effort: args.reasoning_effort.clone(),
|
||||
service_tier: args.service_tier,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(FunctionCallError::RespondToModel)?;
|
||||
session
|
||||
.emit_turn_item_started(
|
||||
turn,
|
||||
@@ -102,19 +116,6 @@ async fn handle_spawn_agent(
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
let prepared = prepare_agent_spawn_config(
|
||||
&session,
|
||||
step_context.as_ref(),
|
||||
SpawnConfigOptions {
|
||||
version: SpawnConfigVersion::V1,
|
||||
full_history_fork: args.fork_context,
|
||||
role_name,
|
||||
model: args.model.as_deref(),
|
||||
reasoning_effort: args.reasoning_effort.clone(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(FunctionCallError::RespondToModel)?;
|
||||
let config = prepared.config;
|
||||
let fork_mode = args.fork_context.then_some(SpawnAgentForkMode::FullHistory);
|
||||
let result = session
|
||||
@@ -132,6 +133,7 @@ async fn handle_spawn_agent(
|
||||
/*task_name*/ None,
|
||||
)?,
|
||||
options: SpawnAgentOptions {
|
||||
service_tier: prepared.service_tier,
|
||||
request_country: step_context.settings.request_country().clone(),
|
||||
fork_parent_spawn_call_id: fork_mode.as_ref().map(|_| call_id.to_string()),
|
||||
fork_mode: fork_mode.clone(),
|
||||
@@ -240,6 +242,7 @@ struct SpawnAgentArgs {
|
||||
agent_type: Option<String>,
|
||||
model: Option<String>,
|
||||
reasoning_effort: Option<ReasoningEffort>,
|
||||
service_tier: Option<String>,
|
||||
#[serde(default)]
|
||||
fork_context: bool,
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ pub struct SpawnAgentToolOptions {
|
||||
pub expose_agent_type: bool,
|
||||
pub hide_agent_type_model_reasoning: bool,
|
||||
pub expose_spawn_agent_model_overrides: bool,
|
||||
pub expose_service_tier: bool,
|
||||
pub multi_agent_version: MultiAgentVersion,
|
||||
pub model_catalog_in_context: bool,
|
||||
pub usage_hint_text: Option<String>,
|
||||
@@ -43,6 +44,7 @@ impl Default for SpawnAgentToolOptions {
|
||||
expose_agent_type: true,
|
||||
hide_agent_type_model_reasoning: false,
|
||||
expose_spawn_agent_model_overrides: false,
|
||||
expose_service_tier: false,
|
||||
multi_agent_version: MultiAgentVersion::Disabled,
|
||||
model_catalog_in_context: false,
|
||||
usage_hint_text: None,
|
||||
@@ -83,6 +85,8 @@ pub fn create_spawn_agent_tool_v1(options: SpawnAgentToolOptions) -> ToolSpec {
|
||||
}
|
||||
if options.hide_agent_type_model_reasoning {
|
||||
hide_spawn_agent_metadata_options(&mut properties);
|
||||
} else if options.expose_service_tier {
|
||||
properties.insert("service_tier".to_string(), spawn_service_tier_schema());
|
||||
}
|
||||
|
||||
ToolSpec::Namespace(ResponsesApiNamespace {
|
||||
@@ -129,6 +133,8 @@ pub fn create_spawn_agent_tool_v2(
|
||||
if !options.expose_spawn_agent_model_overrides {
|
||||
properties.remove("model");
|
||||
properties.remove("reasoning_effort");
|
||||
} else if options.expose_service_tier {
|
||||
properties.insert("service_tier".to_string(), spawn_service_tier_schema());
|
||||
}
|
||||
properties.insert(
|
||||
"task_name".to_string(),
|
||||
@@ -607,6 +613,12 @@ fn create_collab_input_items_schema() -> JsonSchema {
|
||||
))
|
||||
}
|
||||
|
||||
fn spawn_service_tier_schema() -> JsonSchema {
|
||||
JsonSchema::string(Some(
|
||||
"Service tier override for this agent. Use `default` or a tier supported by its model. Omit unless explicitly requested.".to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn spawn_agent_common_properties_v1(agent_type_description: &str) -> BTreeMap<String, JsonSchema> {
|
||||
BTreeMap::from([
|
||||
(
|
||||
|
||||
@@ -12,6 +12,7 @@ fn spawn_agent_tool_v2_requires_task_name() {
|
||||
expose_agent_type: true,
|
||||
hide_agent_type_model_reasoning: false,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
expose_service_tier: true,
|
||||
usage_hint_text: None,
|
||||
..Default::default()
|
||||
},
|
||||
@@ -62,7 +63,7 @@ fn spawn_agent_tool_v2_requires_task_name() {
|
||||
.and_then(|schema| schema.description.as_deref()),
|
||||
Some("Reasoning effort override for the new agent. Omit to inherit the parent effort.")
|
||||
);
|
||||
assert!(!properties.contains_key("service_tier"));
|
||||
assert!(properties.contains_key("service_tier"));
|
||||
assert_eq!(
|
||||
parameters.required.as_deref(),
|
||||
Some(["task_name".to_string(), "message".to_string()].as_slice())
|
||||
@@ -118,6 +119,7 @@ fn spawn_agent_tool_v1_keeps_legacy_fork_context_field() {
|
||||
expose_agent_type: true,
|
||||
hide_agent_type_model_reasoning: false,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
expose_service_tier: true,
|
||||
usage_hint_text: None,
|
||||
..Default::default()
|
||||
});
|
||||
@@ -160,7 +162,7 @@ fn spawn_agent_tool_v1_keeps_legacy_fork_context_field() {
|
||||
.and_then(|schema| schema.description.as_deref()),
|
||||
Some(SPAWN_AGENT_MODEL_OVERRIDE_DESCRIPTION)
|
||||
);
|
||||
assert!(!properties.contains_key("service_tier"));
|
||||
assert!(properties.contains_key("service_tier"));
|
||||
}
|
||||
|
||||
#[test_case::test_case(false; "inline_catalog")]
|
||||
@@ -174,6 +176,7 @@ fn spawn_agent_tool_keeps_model_controls_when_spawn_metadata_is_hidden(
|
||||
expose_agent_type: false,
|
||||
hide_agent_type_model_reasoning: true,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
expose_service_tier: true,
|
||||
model_catalog_in_context,
|
||||
usage_hint_text: None,
|
||||
..Default::default()
|
||||
@@ -197,7 +200,7 @@ fn spawn_agent_tool_keeps_model_controls_when_spawn_metadata_is_hidden(
|
||||
assert!(!properties.contains_key("agent_type"));
|
||||
assert!(properties.contains_key("model"));
|
||||
assert!(properties.contains_key("reasoning_effort"));
|
||||
assert!(!properties.contains_key("service_tier"));
|
||||
assert!(properties.contains_key("service_tier"));
|
||||
assert!(!description.contains(SPAWN_AGENT_INHERITED_MODEL_GUIDANCE));
|
||||
assert_eq!(
|
||||
description.contains(SPAWN_AGENT_INHERITED_MODEL_GUIDANCE_V2),
|
||||
@@ -213,6 +216,7 @@ fn spawn_agent_tool_hides_model_controls_without_override_exposure() {
|
||||
expose_agent_type: false,
|
||||
hide_agent_type_model_reasoning: true,
|
||||
expose_spawn_agent_model_overrides: false,
|
||||
expose_service_tier: true,
|
||||
usage_hint_text: None,
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
@@ -543,9 +543,13 @@ async fn spawn_agent_service_tier_uses_root_preference_when_root_model_cannot_su
|
||||
assert_eq!(root.thread.config_snapshot().await.service_tier, None);
|
||||
|
||||
config.model = Some("gpt-5.5".to_string());
|
||||
apply_spawn_agent_service_tier(root.thread.session.as_ref(), &mut config)
|
||||
.await
|
||||
.expect("root preference should be resolved against the child model");
|
||||
apply_spawn_agent_service_tier(
|
||||
root.thread.session.as_ref(),
|
||||
&mut config,
|
||||
/*requested*/ None,
|
||||
)
|
||||
.await
|
||||
.expect("root preference should be resolved against the child model");
|
||||
|
||||
assert_eq!(
|
||||
config.service_tier,
|
||||
@@ -594,10 +598,13 @@ async fn spawn_agent_service_tier_inheritance_uses_root_preference_and_child_mod
|
||||
Arc::new(session),
|
||||
Arc::new(turn),
|
||||
"spawn_agent",
|
||||
function_payload(json!({"message": "inspect this repo"})),
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"service_tier": "default"
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.expect("spawn_agent should inherit a supported parent service tier");
|
||||
.expect("spawn_agent should ignore a tier argument by default");
|
||||
let (content, _) = expect_text_output(output);
|
||||
let result: SpawnAgentResult =
|
||||
serde_json::from_str(&content).expect("spawn_agent result should be json");
|
||||
|
||||
@@ -132,6 +132,7 @@ async fn handle_spawn_agent(
|
||||
agent_type: args.agent_type.clone(),
|
||||
model: args.model,
|
||||
reasoning_effort: args.reasoning_effort,
|
||||
service_tier: args.service_tier,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -206,6 +207,7 @@ struct SpawnAgentArgs {
|
||||
agent_type: Option<String>,
|
||||
model: Option<String>,
|
||||
reasoning_effort: Option<ReasoningEffort>,
|
||||
service_tier: Option<String>,
|
||||
fork_turns: Option<String>,
|
||||
fork_context: Option<bool>,
|
||||
}
|
||||
|
||||
@@ -28,8 +28,24 @@ pub(super) fn multi_agent_v2_handler(
|
||||
let parameters_override = parameters_override.map(|parameters| -> Result<JsonSchema, &str> {
|
||||
let mut parameters = codex_tools::parse_catalog_tool_parameters(parameters)?;
|
||||
if let ToolSpec::Function(tool) = handler.spec()
|
||||
&& let Some(properties) = tool.parameters.properties
|
||||
&& let Some(mut properties) = tool.parameters.properties
|
||||
{
|
||||
if tool.name == "spawn_agent"
|
||||
&& let Some(catalog) = parameters.properties.as_mut()
|
||||
{
|
||||
if let Some(tier) = properties.remove("service_tier")
|
||||
&& catalog.contains_key("model")
|
||||
{
|
||||
catalog.entry("service_tier".to_string()).or_insert(tier);
|
||||
} else {
|
||||
catalog.remove("service_tier");
|
||||
if let Some(required) = parameters.required.take() {
|
||||
let mut required = required.into_vec();
|
||||
required.retain(|name| name != "service_tier");
|
||||
parameters.required = Some(required.into_boxed_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Argument transport requires these markers even without server encryption config.
|
||||
for (name, schema) in *properties {
|
||||
if schema.encrypted == Some(true) {
|
||||
|
||||
@@ -1420,6 +1420,10 @@ fn add_core_utility_tools(context: &CoreToolPlanContext<'_>, registry: &mut Tool
|
||||
fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, registry: &mut ToolRegistry) {
|
||||
let turn_context = context.turn_context;
|
||||
if collab_tools_enabled(turn_context, context.model_info) {
|
||||
let expose_service_tier = turn_context
|
||||
.config
|
||||
.multi_agent_v2
|
||||
.expose_spawn_agent_service_tier;
|
||||
if multi_agent_v2_enabled(turn_context) {
|
||||
let model_messages = ResolvedModelMessages::from_model(context.model_info);
|
||||
let spawn_agent_description =
|
||||
@@ -1451,6 +1455,7 @@ fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, registry: &mut Too
|
||||
SpawnAgentHandlerV2::new(
|
||||
SpawnAgentToolOptions {
|
||||
available_models: turn_context.available_models.clone(),
|
||||
expose_service_tier,
|
||||
multi_agent_version: turn_context.multi_agent_version,
|
||||
model_catalog_in_context: turn_context
|
||||
.config
|
||||
@@ -1552,6 +1557,7 @@ fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, registry: &mut Too
|
||||
expose_agent_type: !turn_context.config.agent_roles.is_empty(),
|
||||
hide_agent_type_model_reasoning: false,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
expose_service_tier,
|
||||
usage_hint_text: turn_context.config.multi_agent_v2.usage_hint_text.clone(),
|
||||
}),
|
||||
exposure,
|
||||
|
||||
@@ -2797,6 +2797,7 @@ async fn multi_agent_feature_selects_one_agent_tool_family() {
|
||||
);
|
||||
}
|
||||
assert!(!properties.contains_key("agent_type"));
|
||||
assert!(!properties.contains_key("service_tier"));
|
||||
|
||||
let v2 = probe(|turn| {
|
||||
set_feature(turn, Feature::MultiAgentV2, /*enabled*/ true);
|
||||
@@ -2855,9 +2856,8 @@ async fn multi_agent_feature_selects_one_agent_tool_family() {
|
||||
for property in ["model", "reasoning_effort"] {
|
||||
assert!(spawn_agent_properties.contains_key(property));
|
||||
}
|
||||
for property in ["agent_type", "service_tier"] {
|
||||
assert!(!spawn_agent_properties.contains_key(property));
|
||||
}
|
||||
assert!(!spawn_agent_properties.contains_key("agent_type"));
|
||||
assert!(!spawn_agent_properties.contains_key("service_tier"));
|
||||
let spawn_agent_description = spawn_agent.description.as_str();
|
||||
assert!(!spawn_agent_description.contains("max_concurrent_threads_per_session"));
|
||||
assert!(spawn_agent_description.contains(
|
||||
|
||||
@@ -54,18 +54,26 @@ use tokio::sync::watch;
|
||||
|
||||
const WS_V2_BETA_HEADER_VALUE: &str = "responses_websockets=2026-02-06";
|
||||
|
||||
#[test_case::test_case("priority", true, false; "fast mode enabled")]
|
||||
#[test_case::test_case("priority", false, true; "fast mode disabled")]
|
||||
#[test_case::test_case("ultrafast", false, true; "ultrafast mode enabled")]
|
||||
#[test_case::test_case("ultrafast", true, false; "ultrafast mode disabled")]
|
||||
#[test_case::test_case("ultrafast", true, true, Some("default"); "child requests ultrafast from default root")]
|
||||
#[test_case::test_case("priority", true, false, None; "fast mode enabled")]
|
||||
#[test_case::test_case("priority", false, true, None; "fast mode disabled")]
|
||||
#[test_case::test_case("ultrafast", false, true, None; "ultrafast mode enabled")]
|
||||
#[test_case::test_case("ultrafast", true, false, None; "ultrafast mode disabled")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn spawned_agent_prewarm_handshake_inherits_effective_root_service_tier(
|
||||
async fn spawned_agent_uses_effective_service_tier_from_handshake_through_first_request(
|
||||
tier: &'static str,
|
||||
fast_mode_enabled: bool,
|
||||
ultrafast_mode_enabled: bool,
|
||||
different_root_tier: Option<&'static str>,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let mut args = json!({ "message": "hello", "task_name": "worker", "fork_turns": "none" });
|
||||
if different_root_tier.is_some() {
|
||||
args["service_tier"] = json!(tier);
|
||||
args["fork_turns"] = json!("all");
|
||||
}
|
||||
let root_tier = different_root_tier.unwrap_or(tier);
|
||||
let server = start_websocket_server(vec![
|
||||
vec![
|
||||
vec![ev_response_created("root-warm"), ev_completed("root-warm")],
|
||||
@@ -75,8 +83,7 @@ async fn spawned_agent_prewarm_handshake_inherits_effective_root_service_tier(
|
||||
"spawn-worker",
|
||||
"collaboration",
|
||||
"spawn_agent",
|
||||
&json!({ "message": "hello", "task_name": "worker", "fork_turns": "none" })
|
||||
.to_string(),
|
||||
&args.to_string(),
|
||||
),
|
||||
ev_completed("root-spawn"),
|
||||
],
|
||||
@@ -110,6 +117,7 @@ async fn spawned_agent_prewarm_handshake_inherits_effective_root_service_tier(
|
||||
});
|
||||
})
|
||||
.with_config(move |config| {
|
||||
config.multi_agent_v2.expose_spawn_agent_service_tier = different_root_tier.is_some();
|
||||
for feature in [Feature::Collab, Feature::MultiAgentV2] {
|
||||
config.features.enable(feature).expect("spawn feature");
|
||||
}
|
||||
@@ -128,7 +136,7 @@ async fn spawned_agent_prewarm_handshake_inherits_effective_root_service_tier(
|
||||
.features
|
||||
.set_enabled(Feature::UltrafastMode, ultrafast_mode_enabled)
|
||||
.expect("configure Ultra Fast mode");
|
||||
config.service_tier = Some(tier.to_string());
|
||||
config.service_tier = Some(root_tier.to_string());
|
||||
})
|
||||
.build_with_websocket_server(&server)
|
||||
.await?;
|
||||
@@ -145,7 +153,7 @@ async fn spawned_agent_prewarm_handshake_inherits_effective_root_service_tier(
|
||||
text_elements: Vec::new(),
|
||||
}])
|
||||
.with_thread_settings(ThreadSettingsOverrides {
|
||||
service_tier: Some(Some(tier.to_string())),
|
||||
service_tier: Some(Some(root_tier.to_string())),
|
||||
..Default::default()
|
||||
}),
|
||||
)
|
||||
@@ -181,6 +189,16 @@ async fn spawned_agent_prewarm_handshake_inherits_effective_root_service_tier(
|
||||
child_warmup["service_tier"].as_str(),
|
||||
tier_enabled.then_some(tier)
|
||||
);
|
||||
let child_request = tokio::time::timeout(
|
||||
Duration::from_secs(5),
|
||||
server.wait_for_request(/*connection_index*/ 1, /*request_index*/ 1),
|
||||
)
|
||||
.await?
|
||||
.body_json();
|
||||
assert_eq!(
|
||||
child_request["service_tier"].as_str(),
|
||||
tier_enabled.then_some(tier)
|
||||
);
|
||||
assert_eq!(server.handshakes().len(), 2);
|
||||
child.shutdown_and_wait().await?;
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Verifies default Bedrock catalogs select V2 and expose its collaboration tools.
|
||||
//! Exercises collaboration tools with Bedrock model catalogs.
|
||||
|
||||
use codex_features::Feature;
|
||||
use codex_login::CodexAuth;
|
||||
@@ -15,15 +15,28 @@ use pretty_assertions::assert_eq;
|
||||
#[test_case::test_case(AMAZON_BEDROCK_PROVIDER_ID, "openai.gpt-5.6-sol"; "mantle")]
|
||||
#[test_case::test_case(AMAZON_BEDROCK_RUNTIME_PROVIDER_ID, "global.openai.gpt-5.6-sol"; "runtime")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn bedrock_catalog_selects_v2_by_default(
|
||||
async fn bedrock_catalog_selects_v2_and_rejects_unadvertised_flex(
|
||||
provider_id: &'static str,
|
||||
model: &'static str,
|
||||
) -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = responses::start_mock_server().await;
|
||||
let mock = responses::mount_sse_once(
|
||||
const CALL_ID: &str = "spawn-worker";
|
||||
let mock = responses::mount_sse_sequence(
|
||||
&server,
|
||||
responses::sse(vec![responses::ev_completed("done")]),
|
||||
vec![
|
||||
responses::sse(vec![
|
||||
responses::ev_response_created("spawn"),
|
||||
responses::ev_function_call_with_namespace(
|
||||
CALL_ID,
|
||||
"collaboration",
|
||||
"spawn_agent",
|
||||
r#"{"message":"Do the task","task_name":"worker","service_tier":"flex"}"#,
|
||||
),
|
||||
responses::ev_completed("spawn"),
|
||||
]),
|
||||
responses::sse(vec![responses::ev_completed("done")]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let test = test_codex()
|
||||
@@ -33,6 +46,7 @@ async fn bedrock_catalog_selects_v2_by_default(
|
||||
}))
|
||||
.with_model(model)
|
||||
.with_config(move |config| {
|
||||
config.multi_agent_v2.expose_spawn_agent_service_tier = true;
|
||||
let base_url = config.model_provider.base_url.clone();
|
||||
config.model_provider_id = provider_id.to_string();
|
||||
config.model_provider = built_in_model_providers(/*openai_base_url*/ None)
|
||||
@@ -45,14 +59,15 @@ async fn bedrock_catalog_selects_v2_by_default(
|
||||
assert!(!test.config.features.enabled(Feature::MultiAgentV2));
|
||||
assert!(test.config.model_catalog.is_none());
|
||||
|
||||
test.submit_text_turn("Hello").await?;
|
||||
test.submit_text_turn("Spawn a worker on Flex").await?;
|
||||
|
||||
assert_eq!(
|
||||
test.codex.multi_agent_version(),
|
||||
Some(MultiAgentVersion::V2)
|
||||
);
|
||||
let request = mock.single_request();
|
||||
let declarations = request.inputs_of_type("additional_tools");
|
||||
let requests = mock.requests();
|
||||
assert_eq!(requests.len(), 2);
|
||||
let declarations = requests[0].inputs_of_type("additional_tools");
|
||||
for tool in ["spawn_agent", "followup_task"] {
|
||||
assert!(
|
||||
declarations
|
||||
@@ -61,5 +76,14 @@ async fn bedrock_catalog_selects_v2_by_default(
|
||||
"default Bedrock catalog should expose collaboration.{tool}",
|
||||
);
|
||||
}
|
||||
let (output, _) = requests[1]
|
||||
.function_call_output_content_and_success(CALL_ID)
|
||||
.expect("spawn_agent error output");
|
||||
assert_eq!(
|
||||
output,
|
||||
Some(format!(
|
||||
"Service tier `flex` is unavailable for model `{model}`. Omit service_tier to inherit the usual tier."
|
||||
))
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -48,9 +48,13 @@ const EXPECTED_CATALOG_PARAMETERS: &str = r#"{
|
||||
"$defs": {"unused": {"type": "string"}}
|
||||
}"#;
|
||||
|
||||
const CATALOG_SPAWN_MODEL: &str = r#"{"type":"object","properties":{"message":{"type":"string"},"model":{"type":"string"}},"required":["message"]}"#;
|
||||
const CATALOG_SPAWN_TIER: &str = r#"{"type":"object","properties":{"message":{"type":"string"},"model":{"type":"string"},"service_tier":{"type":"string"}},"required":["message","service_tier"]}"#;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Exposure {
|
||||
Namespaced,
|
||||
NamespacedWithSpawnTier,
|
||||
Plain,
|
||||
CodeMode,
|
||||
V1,
|
||||
@@ -103,6 +107,8 @@ fn all_tool_messages(message: Value) -> Value {
|
||||
"followup_task": {"parameters": r#"{"type":"object"}"#}
|
||||
}}), Exposure::Namespaced, None; "missing_encrypted_parameters_fall_back")]
|
||||
#[test_case(json!({"multi_agent": {"send_message": {"parameters": CATALOG_PARAMETERS}}}), Exposure::Namespaced, Some(EXPECTED_CATALOG_PARAMETERS); "sparse_parameters")]
|
||||
#[test_case(json!({"multi_agent": {"spawn_agent": {"parameters": CATALOG_SPAWN_MODEL}}}), Exposure::NamespacedWithSpawnTier, Some(CATALOG_SPAWN_MODEL); "catalog_spawn_model_exposes_service_tier_when_enabled")]
|
||||
#[test_case(json!({"multi_agent": {"spawn_agent": {"parameters": CATALOG_SPAWN_TIER}}}), Exposure::Namespaced, Some(CATALOG_SPAWN_MODEL); "catalog_spawn_service_tier_is_hidden_by_default")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn multi_agent_catalog_messages_change_only_selected_tool_fields(
|
||||
tool_messages: Value,
|
||||
@@ -143,6 +149,8 @@ async fn multi_agent_catalog_messages_change_only_selected_tool_fields(
|
||||
.enable(Feature::MultiAgentV2)
|
||||
.expect("enable V2");
|
||||
}
|
||||
config.multi_agent_v2.expose_spawn_agent_service_tier =
|
||||
matches!(exposure, Exposure::NamespacedWithSpawnTier);
|
||||
if matches!(exposure, Exposure::CodeMode) {
|
||||
config
|
||||
.features
|
||||
@@ -247,7 +255,17 @@ async fn multi_agent_catalog_messages_change_only_selected_tool_fields(
|
||||
if let Some(parameters) = expected_parameters
|
||||
&& tool_messages["multi_agent"][name]["parameters"].is_string()
|
||||
{
|
||||
let tier = expected_tool["parameters"]["properties"]["service_tier"].clone();
|
||||
expected_tool["parameters"] = serde_json::from_str(parameters)?;
|
||||
if matches!(exposure, Exposure::NamespacedWithSpawnTier)
|
||||
&& name == "spawn_agent"
|
||||
&& expected_tool["parameters"]["properties"]
|
||||
.get("model")
|
||||
.is_some()
|
||||
{
|
||||
assert!(tier.is_object());
|
||||
expected_tool["parameters"]["properties"]["service_tier"] = tier;
|
||||
}
|
||||
if matches!(name, "spawn_agent" | "send_message" | "followup_task") {
|
||||
expected_tool["parameters"]["properties"]["message"]["encrypted"] = json!(true);
|
||||
}
|
||||
|
||||
@@ -2387,6 +2387,7 @@ async fn multi_agent_catalog_parameters(
|
||||
let test = test_codex()
|
||||
.with_config(move |config| {
|
||||
configure_scenario_catalog(config);
|
||||
config.multi_agent_v2.expose_spawn_agent_service_tier = true;
|
||||
config.multi_agent_v2.disable_native_tools = disable_native_tools;
|
||||
config.workspace_roots = vec![config.cwd.clone()];
|
||||
})
|
||||
|
||||
@@ -162,6 +162,7 @@ fn create_request(name: &str, fork_history: bool) -> ThreadCreateRequest {
|
||||
fork_mode: fork_history.then_some(SpawnAgentForkMode::FullHistory),
|
||||
agent_type: None,
|
||||
model: None,
|
||||
service_tier: None,
|
||||
reasoning_effort: None,
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ Settings:
|
||||
text: {"verbosity":"low"}
|
||||
tool_choice: "auto"
|
||||
-- request 1 (turn) --
|
||||
00:additional_tools/developer (3; hash=5133d148141b321a):
|
||||
00:additional_tools/developer (3; hash=66d05cb35c31b776):
|
||||
- namespace/functions; hash=81846de5bc4e7474
|
||||
- custom/exec
|
||||
- function/wait
|
||||
@@ -24,7 +24,7 @@ Settings:
|
||||
- function/request_user_input_async
|
||||
- namespace/clock: Tools for reading and waiting on time.; hash=f402e8c5e9b5e317
|
||||
- function/sleep
|
||||
- namespace/collaboration: Tools for spawning and managing sub-agents.; hash=bcd67096347e246f
|
||||
- namespace/collaboration: Tools for spawning and managing sub-agents.; hash=617bfb6a066417b3
|
||||
- function/followup_task
|
||||
- function/interrupt_agent
|
||||
- function/list_agents
|
||||
|
||||
@@ -2047,8 +2047,7 @@ async fn spawned_full_history_v2_child_uses_model_precedence_without_dropping_co
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn spawn_agent_requested_model_and_reasoning_override_inherited_settings_without_role()
|
||||
-> Result<()> {
|
||||
async fn spawn_agent_overrides_inherited_model_settings_without_role() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
@@ -2057,17 +2056,30 @@ async fn spawn_agent_requested_model_and_reasoning_override_inherited_settings_w
|
||||
json!({
|
||||
"message": CHILD_PROMPT,
|
||||
"model": REQUESTED_MODEL,
|
||||
"service_tier": "flex",
|
||||
"reasoning_effort": REQUESTED_REASONING_EFFORT,
|
||||
}),
|
||||
|builder| {
|
||||
builder.with_config(|config| {
|
||||
config.agent_default_subagent_model = Some(INHERITED_MODEL.to_string());
|
||||
config.agent_default_subagent_reasoning_effort = Some(ReasoningEffort::High);
|
||||
})
|
||||
builder
|
||||
.with_pre_build_hook(|home| {
|
||||
std::fs::write(
|
||||
home.join("config.toml"),
|
||||
"[features.multi_agent_v2]
|
||||
enabled = false
|
||||
expose_spawn_agent_service_tier = true
|
||||
",
|
||||
)
|
||||
.expect("write V1 spawn settings");
|
||||
})
|
||||
.with_config(|config| {
|
||||
config.agent_default_subagent_model = Some(INHERITED_MODEL.to_string());
|
||||
config.agent_default_subagent_reasoning_effort = Some(ReasoningEffort::High);
|
||||
})
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
assert_eq!(child_snapshot.service_tier.as_deref(), Some("flex"));
|
||||
assert_eq!(child_snapshot.model, REQUESTED_MODEL);
|
||||
assert_eq!(
|
||||
child_snapshot.reasoning_effort,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//! Verifies that root service-tier changes reach existing child turns and future work.
|
||||
//! Verifies service-tier inheritance, overrides, and reloads for child agents.
|
||||
|
||||
use super::agent_control::HostRuntime;
|
||||
use anyhow::Result;
|
||||
use codex_core::AgentRuntimeOwnership;
|
||||
use codex_core::ThreadEvictionOutcome;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_core::config::AgentRoleConfig;
|
||||
use codex_core::config::Config;
|
||||
@@ -13,6 +14,7 @@ use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::ThreadSettingsOverrides;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use core_test_support::ThreadIdle;
|
||||
use core_test_support::responses::ResponseMock;
|
||||
use core_test_support::responses::ev_assistant_message;
|
||||
use core_test_support::responses::ev_completed;
|
||||
@@ -92,14 +94,14 @@ async fn wait_for_turn_complete(thread: &codex_core::CodexThread) {
|
||||
wait_for_event(thread, |event| matches!(event, EventMsg::TurnComplete(_))).await;
|
||||
}
|
||||
|
||||
async fn mount_root_collaboration_call(
|
||||
async fn mount_spawn_agent_turn(
|
||||
server: &wiremock::MockServer,
|
||||
prompt: &'static str,
|
||||
call_id: &'static str,
|
||||
arguments: serde_json::Value,
|
||||
) {
|
||||
let response_id = format!("root-{call_id}");
|
||||
mount_sse_once_match(
|
||||
) -> ResponseMock {
|
||||
let response_id = format!("spawn-{call_id}");
|
||||
let spawn_request = mount_sse_once_match(
|
||||
server,
|
||||
move |request: &wiremock::Request| {
|
||||
body_contains(request, prompt) && !body_contains(request, call_id)
|
||||
@@ -117,7 +119,7 @@ async fn mount_root_collaboration_call(
|
||||
)
|
||||
.await;
|
||||
|
||||
let completion_id = format!("root-{call_id}-finished");
|
||||
let completion_id = format!("spawn-{call_id}-finished");
|
||||
mount_sse_once_match(
|
||||
server,
|
||||
move |request: &wiremock::Request| {
|
||||
@@ -130,6 +132,7 @@ async fn mount_root_collaboration_call(
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
spawn_request
|
||||
}
|
||||
|
||||
async fn mount_completed_child(
|
||||
@@ -173,7 +176,7 @@ async fn root_service_tier_change_updates_existing_subagent(
|
||||
assert!(!test.config.features.enabled(Feature::StepModelSwitching));
|
||||
let mut created_threads = test.thread_manager.subscribe_thread_created();
|
||||
|
||||
mount_root_collaboration_call(
|
||||
mount_spawn_agent_turn(
|
||||
&server,
|
||||
ROOT_PROMPT,
|
||||
SPAWN_CALL_ID,
|
||||
@@ -286,7 +289,7 @@ async fn root_service_tier_change_updates_existing_subagent(
|
||||
wait_for_turn_complete(&child).await;
|
||||
assert_request_service_tier(&future_child_request, updated_request_service_tier);
|
||||
|
||||
mount_root_collaboration_call(
|
||||
mount_spawn_agent_turn(
|
||||
&server,
|
||||
FRESH_ROOT_PROMPT,
|
||||
FRESH_SPAWN_CALL_ID,
|
||||
@@ -308,15 +311,19 @@ async fn root_service_tier_change_updates_existing_subagent(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(AgentRuntimeOwnership::Controller, None; "controller")]
|
||||
#[test_case(AgentRuntimeOwnership::Host, Some("priority"); "host without a tier provider")]
|
||||
#[test_case(AgentRuntimeOwnership::Controller, Some("flex"), Some("flex"); "explicit tier survives eviction and root changes")]
|
||||
#[test_case(AgentRuntimeOwnership::Controller, None, None; "controller")]
|
||||
#[test_case(AgentRuntimeOwnership::Host, None, Some("priority"); "host without a tier provider")]
|
||||
#[test_case(AgentRuntimeOwnership::Host, Some("flex"), Some("flex"); "host without a tier provider scopes override to one child")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn evicted_role_subagent_uses_owned_service_tier_after_reload(
|
||||
owner: AgentRuntimeOwnership,
|
||||
requested: Option<&str>,
|
||||
expected: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let server = start_mock_server().await;
|
||||
let mut extensions = ExtensionRegistryBuilder::new();
|
||||
extensions.thread_lifecycle_contributor(Arc::new(ThreadIdle));
|
||||
if owner == AgentRuntimeOwnership::Host {
|
||||
extensions.thread_lifecycle_contributor(Arc::new(HostRuntime));
|
||||
}
|
||||
@@ -328,13 +335,14 @@ async fn evicted_role_subagent_uses_owned_service_tier_after_reload(
|
||||
AgentRuntimeOwnership::Controller => "priority".to_string(),
|
||||
AgentRuntimeOwnership::Host => SERVICE_TIER_DEFAULT_REQUEST_VALUE.to_string(),
|
||||
});
|
||||
config.multi_agent_v2.max_concurrent_threads_per_session = 2;
|
||||
config.multi_agent_v2.max_concurrent_threads_per_session = 3;
|
||||
configure_priority_role(config);
|
||||
config.multi_agent_v2.expose_spawn_agent_service_tier = true;
|
||||
});
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
let mut created_threads = test.thread_manager.subscribe_thread_created();
|
||||
|
||||
mount_root_collaboration_call(
|
||||
mount_spawn_agent_turn(
|
||||
&server,
|
||||
ROOT_PROMPT,
|
||||
SPAWN_CALL_ID,
|
||||
@@ -342,6 +350,7 @@ async fn evicted_role_subagent_uses_owned_service_tier_after_reload(
|
||||
"message": CHILD_PROMPT,
|
||||
"task_name": "original",
|
||||
"agent_type": PRIORITY_ROLE,
|
||||
"service_tier": requested,
|
||||
"fork_turns": "none",
|
||||
}),
|
||||
)
|
||||
@@ -351,28 +360,14 @@ async fn evicted_role_subagent_uses_owned_service_tier_after_reload(
|
||||
let original_thread_id = created_threads.recv().await?;
|
||||
let original_thread = test.thread_manager.get_thread(original_thread_id).await?;
|
||||
wait_for_turn_complete(&original_thread).await;
|
||||
assert_request_service_tier(&original_request, Some("priority"));
|
||||
drop(original_thread);
|
||||
|
||||
mount_root_collaboration_call(
|
||||
&server,
|
||||
FRESH_ROOT_PROMPT,
|
||||
FRESH_SPAWN_CALL_ID,
|
||||
json!({
|
||||
"message": FRESH_CHILD_PROMPT,
|
||||
"task_name": "replacement",
|
||||
"fork_turns": "none",
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
mount_completed_child(&server, FRESH_CHILD_PROMPT, FRESH_ROOT_PROMPT).await;
|
||||
test.submit_text_turn(FRESH_ROOT_PROMPT).await?;
|
||||
let replacement_thread_id = created_threads.recv().await?;
|
||||
let replacement_thread = test
|
||||
.thread_manager
|
||||
.get_thread(replacement_thread_id)
|
||||
.await?;
|
||||
wait_for_turn_complete(&replacement_thread).await;
|
||||
assert_request_service_tier(&original_request, requested.or(Some("priority")));
|
||||
ThreadIdle::wait(&original_thread).await;
|
||||
assert_eq!(
|
||||
test.thread_manager
|
||||
.try_evict_v2_thread(original_thread)
|
||||
.await?,
|
||||
ThreadEvictionOutcome::Evicted,
|
||||
);
|
||||
assert!(
|
||||
test.thread_manager
|
||||
.get_thread(original_thread_id)
|
||||
@@ -393,7 +388,11 @@ async fn evicted_role_subagent_uses_owned_service_tier_after_reload(
|
||||
.await?;
|
||||
let reloaded_thread = test.thread_manager.get_thread(original_thread_id).await?;
|
||||
let expected_configured_tier = match owner {
|
||||
AgentRuntimeOwnership::Controller => test.codex.config_snapshot().await.service_tier,
|
||||
AgentRuntimeOwnership::Controller => {
|
||||
requested
|
||||
.map(str::to_owned)
|
||||
.or(test.codex.config_snapshot().await.service_tier)
|
||||
}
|
||||
AgentRuntimeOwnership::Host => expected.map(str::to_string),
|
||||
};
|
||||
assert_eq!(
|
||||
@@ -401,7 +400,21 @@ async fn evicted_role_subagent_uses_owned_service_tier_after_reload(
|
||||
expected_configured_tier,
|
||||
);
|
||||
|
||||
let reloaded_request = mount_completed_child(&server, FOLLOWUP_PROMPT, ROOT_PROMPT).await;
|
||||
let grandchild_prompt = "finish the service-tier grandchild";
|
||||
let reloaded_request = mount_spawn_agent_turn(
|
||||
&server,
|
||||
FOLLOWUP_PROMPT,
|
||||
"spawn-service-tier-grandchild",
|
||||
json!({
|
||||
"message": grandchild_prompt,
|
||||
"task_name": "grandchild",
|
||||
"fork_turns": "none",
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
let grandchild_request =
|
||||
mount_completed_child(&server, grandchild_prompt, FOLLOWUP_PROMPT).await;
|
||||
let mut created_threads = test.thread_manager.subscribe_thread_created();
|
||||
reloaded_thread
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: FOLLOWUP_PROMPT.to_string(),
|
||||
@@ -410,6 +423,15 @@ async fn evicted_role_subagent_uses_owned_service_tier_after_reload(
|
||||
.await?;
|
||||
wait_for_turn_complete(&reloaded_thread).await;
|
||||
assert_request_service_tier(&reloaded_request, expected);
|
||||
let grandchild_thread_id = created_threads.try_recv()?;
|
||||
let grandchild = test.thread_manager.get_thread(grandchild_thread_id).await?;
|
||||
wait_for_turn_complete(&grandchild).await;
|
||||
let expected_grandchild_tier = match owner {
|
||||
AgentRuntimeOwnership::Host => Some("priority"),
|
||||
AgentRuntimeOwnership::Controller => None,
|
||||
};
|
||||
assert_request_service_tier(&grandchild_request, expected_grandchild_tier);
|
||||
grandchild.shutdown_and_wait().await?;
|
||||
reloaded_thread.shutdown_and_wait().await?;
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
|
||||
|
||||
@@ -418,6 +418,9 @@ pub struct MultiAgentV2ConfigToml {
|
||||
/// corresponding guidance to root and subagent usage hints.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub expose_spawn_agent_model_overrides: Option<bool>,
|
||||
/// Allow V1 and V2 `spawn_agent` to select a `service_tier` for one child. Defaults to false.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub expose_spawn_agent_service_tier: Option<bool>,
|
||||
/// Expose the multi-agent v2 `wait_agent` tool.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub wait_agent_enabled: Option<bool>,
|
||||
|
||||
@@ -888,6 +888,7 @@ multi_agent_mode_hint_text = "Custom mode guidance."
|
||||
tool_namespace = "agents"
|
||||
hide_spawn_agent_metadata = true
|
||||
expose_spawn_agent_model_overrides = true
|
||||
expose_spawn_agent_service_tier = true
|
||||
wait_agent_enabled = false
|
||||
disable_native_tools = true
|
||||
disable_direct_message = true
|
||||
@@ -919,6 +920,7 @@ non_code_mode_only = true
|
||||
tool_namespace: Some("agents".to_string()),
|
||||
hide_spawn_agent_metadata: Some(true),
|
||||
expose_spawn_agent_model_overrides: Some(true),
|
||||
expose_spawn_agent_service_tier: Some(true),
|
||||
wait_agent_enabled: Some(false),
|
||||
interrupt_at_item_boundary: None,
|
||||
disable_native_tools: Some(true),
|
||||
|
||||
@@ -39,6 +39,7 @@ use codex_protocol::protocol::SessionMeta;
|
||||
use codex_protocol::protocol::SessionMetaLine;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::ThreadSettingsSnapshot;
|
||||
use codex_protocol::protocol::ThreadSource;
|
||||
use codex_protocol::protocol::TokenUsageRecord;
|
||||
use codex_protocol::protocol::TurnContextItem;
|
||||
@@ -781,6 +782,20 @@ impl InitialHistory {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resumed_thread_settings(&self) -> Option<&ThreadSettingsSnapshot> {
|
||||
let Self::Resumed(resumed) = self else {
|
||||
return None;
|
||||
};
|
||||
resumed.history.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(resumed.conversation_id) =>
|
||||
{
|
||||
Some(&event.thread_settings)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
fn get_resumed_session_meta(&self) -> Option<&SessionMeta> {
|
||||
match self {
|
||||
Self::New | Self::Cleared | Self::Forked(_) => None,
|
||||
|
||||
@@ -2564,8 +2564,19 @@ pub struct ThreadSettingsAppliedEvent {
|
||||
pub thread_settings: ThreadSettingsSnapshot,
|
||||
}
|
||||
|
||||
/// A child with a spawn override keeps the ordinary tier for its descendants.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, JsonSchema, TS)]
|
||||
pub struct SpawnServiceTierOverride {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub inherited_service_tier: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, JsonSchema, TS)]
|
||||
pub struct ThreadSettingsSnapshot {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub spawn_service_tier_override: Option<SpawnServiceTierOverride>,
|
||||
pub model: String,
|
||||
pub model_provider_id: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
||||
@@ -734,6 +734,7 @@ mod tests {
|
||||
ThreadSettingsAppliedEvent {
|
||||
thread_id: None,
|
||||
thread_settings: ThreadSettingsSnapshot {
|
||||
spawn_service_tier_override: None,
|
||||
disabled_plugin_ids: Vec::new(),
|
||||
guardian_retention: None,
|
||||
model: "gpt-5.2-codex".to_string(),
|
||||
|
||||
@@ -749,6 +749,7 @@ mod tests {
|
||||
ThreadSettingsAppliedEvent {
|
||||
thread_id: None,
|
||||
thread_settings: ThreadSettingsSnapshot {
|
||||
spawn_service_tier_override: None,
|
||||
disabled_plugin_ids: Vec::new(),
|
||||
guardian_retention: None,
|
||||
model: "gpt-5.2-codex".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user