mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Allow model metadata to control multi-agent tools in code mode (#61854)
## What changed Add optional `multi_agent_tools_in_code_mode` model metadata to control whether native multi-agent tools follow the model's `tool_mode`. When `true`, expose them according to `Direct`, `CodeMode`, or `CodeModeOnly`; when `false`, keep them direct-only. When omitted, preserve the `multi_agent_v2.non_code_mode_only` runtime setting. ## Testing Add coverage for metadata overrides and runtime fallback across all three tool modes, plus serialization and deserialization of absent, null, and boolean metadata values. Update the namespace-prefix integration scenario to enable code-mode tools through model metadata. GitOrigin-RevId: be90f436066226bf9971cbd17f28c396341bb83a
This commit is contained in:
@@ -78,6 +78,7 @@ fn preset_to_info(preset: &ModelPreset, priority: i32) -> ModelInfo {
|
||||
tool_mode: None,
|
||||
multi_agent_version: preset.multi_agent_version,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,7 @@ async fn models_client_hits_models_endpoint() {
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
}],
|
||||
};
|
||||
|
||||
|
||||
@@ -1517,10 +1517,14 @@ fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, registry: &mut Too
|
||||
let model_messages = ResolvedModelMessages::from_model(context.model_info);
|
||||
let spawn_agent_description =
|
||||
model_messages.multi_agent_tool_description_override("spawn_agent");
|
||||
let exposure = if turn_context.config.multi_agent_v2.non_code_mode_only {
|
||||
ToolExposure::DirectModelOnly
|
||||
} else {
|
||||
let tools_in_code_mode = context
|
||||
.model_info
|
||||
.multi_agent_tools_in_code_mode
|
||||
.unwrap_or(!turn_context.config.multi_agent_v2.non_code_mode_only);
|
||||
let exposure = if tools_in_code_mode {
|
||||
ToolExposure::Direct
|
||||
} else {
|
||||
ToolExposure::DirectModelOnly
|
||||
};
|
||||
let tool_namespace = turn_context.config.multi_agent_v2.tool_namespace.as_deref();
|
||||
let native_review = if turn_context
|
||||
|
||||
@@ -3144,6 +3144,55 @@ async fn multi_agent_v2_bedrock_workers_only_delegate_when_model_supports_v2() {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn multi_agent_catalog_code_mode_follows_tool_mode_and_preserves_runtime_fallback() {
|
||||
for (catalog, non_code_mode_only, follows_tool_mode) in [
|
||||
(None, true, false),
|
||||
(None, false, true),
|
||||
(Some(true), true, true),
|
||||
(Some(false), false, false),
|
||||
] {
|
||||
for tool_mode in [ToolMode::Direct, ToolMode::CodeMode, ToolMode::CodeModeOnly] {
|
||||
let plan = probe(|turn| {
|
||||
set_feature(turn, Feature::MultiAgentV2, /*enabled*/ true);
|
||||
update_config(turn, |config| {
|
||||
config.multi_agent_v2.non_code_mode_only = non_code_mode_only;
|
||||
config.multi_agent_v2.tool_namespace = Some("agents".to_string());
|
||||
});
|
||||
update_turn_settings_for_test(turn, |settings| {
|
||||
let model = Arc::make_mut(&mut settings.model_info);
|
||||
model.tool_mode = Some(tool_mode);
|
||||
model.multi_agent_tools_in_code_mode = catalog;
|
||||
});
|
||||
})
|
||||
.await;
|
||||
for name in [
|
||||
"spawn_agent",
|
||||
"send_message",
|
||||
"followup_task",
|
||||
"wait_agent",
|
||||
"interrupt_agent",
|
||||
"list_agents",
|
||||
] {
|
||||
assert_eq!(
|
||||
(
|
||||
plan.namespace_function_names("agents")
|
||||
.iter()
|
||||
.any(|tool| tool == name),
|
||||
plan.code_mode_tool_names
|
||||
.contains_key(&format!("agents__{name}")),
|
||||
),
|
||||
(
|
||||
!follows_tool_mode || tool_mode != ToolMode::CodeModeOnly,
|
||||
follows_tool_mode && tool_mode != ToolMode::Direct,
|
||||
),
|
||||
"{name}: catalog={catalog:?}, non_code_mode_only={non_code_mode_only}, mode={tool_mode:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn code_mode_only_can_expose_namespaced_multi_agent_v2_as_normal_tools() {
|
||||
let plan = probe(|turn| {
|
||||
|
||||
@@ -656,6 +656,7 @@ fn remote_model_with_auto_review_override(slug: &str, review_model: &str) -> Mod
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
priority: 1,
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers: Vec::new(),
|
||||
|
||||
@@ -135,6 +135,7 @@ fn test_model_info(
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
priority: 1,
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers: Vec::new(),
|
||||
@@ -1282,6 +1283,7 @@ async fn model_switch_to_smaller_model_updates_token_context_window() -> Result<
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
priority: 1,
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers: Vec::new(),
|
||||
|
||||
@@ -748,5 +748,6 @@ fn test_remote_model(slug: &str, priority: i32) -> ModelInfo {
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -837,6 +837,7 @@ async fn remote_models_remote_model_uses_unified_exec() -> Result<()> {
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
priority: 1,
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers: Vec::new(),
|
||||
@@ -1112,6 +1113,7 @@ async fn remote_models_apply_legacy_instructions(auth: CodexAuth) -> Result<()>
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
priority: 1,
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers: Vec::new(),
|
||||
@@ -1701,6 +1703,7 @@ fn test_remote_model_with_policy(
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
priority,
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers: Vec::new(),
|
||||
|
||||
@@ -3704,6 +3704,7 @@ async fn stdio_image_responses_are_sanitized_for_text_only_model() -> anyhow::Re
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
}],
|
||||
},
|
||||
)
|
||||
|
||||
@@ -46,7 +46,6 @@ async fn catalog_namespace_prefixes_follow_the_selected_model(
|
||||
.features
|
||||
.enable(Feature::MultiAgentV2)
|
||||
.expect("enable MAv2");
|
||||
config.multi_agent_v2.non_code_mode_only = false;
|
||||
config.multi_agent_v2.root_agent_usage_hint_text = Some("Coordinate sub-agents.".into());
|
||||
config
|
||||
.mcp_servers
|
||||
@@ -86,6 +85,7 @@ async fn catalog_namespace_prefixes_follow_the_selected_model(
|
||||
] {
|
||||
builder = builder.with_model_info_override(slug, move |model| {
|
||||
model.tool_mode = Some(tool_mode);
|
||||
model.multi_agent_tools_in_code_mode = Some(true);
|
||||
model.supports_search_tool = include_search;
|
||||
model.model_messages.as_mut().expect("model messages").tools = Some(
|
||||
serde_json::from_value(json!({
|
||||
|
||||
@@ -102,6 +102,7 @@ fn test_model_info(
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
priority: 1,
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers,
|
||||
|
||||
@@ -1638,6 +1638,7 @@ async fn view_image_tool_returns_unsupported_message_for_text_only_model() -> an
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
priority: 1,
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers: Vec::new(),
|
||||
|
||||
@@ -145,6 +145,7 @@ pub fn model_info_from_slug(slug: &str) -> ModelInfo {
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ fn test_model(model_messages: Option<ModelMessages>) -> ModelInfo {
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -529,6 +529,10 @@ pub struct ModelInfo {
|
||||
/// Reasoning effort used for multi-agent work when the user selects Ultra.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub multi_agent_reasoning_effort: Option<ReasoningEffort>,
|
||||
/// Whether native multi-agent tools follow the model's tool mode instead of staying direct-only.
|
||||
/// When absent, preserve the runtime's `multi_agent_v2.non_code_mode_only` setting.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub multi_agent_tools_in_code_mode: Option<bool>,
|
||||
}
|
||||
|
||||
/// Where model metadata was obtained during local catalog resolution.
|
||||
@@ -1246,6 +1250,7 @@ mod tests {
|
||||
tool_mode: None,
|
||||
multi_agent_version: None,
|
||||
multi_agent_reasoning_effort: None,
|
||||
multi_agent_tools_in_code_mode: None,
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
@@ -1948,6 +1953,24 @@ mod tests {
|
||||
assert_eq!(model.multi_agent_reasoning_effort, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_info_preserves_multi_agent_code_mode_presence() {
|
||||
let base = test_model(/*spec*/ None);
|
||||
let base_json = serde_json::to_value(&base).expect("serialize model");
|
||||
assert!(base_json.get("multi_agent_tools_in_code_mode").is_none());
|
||||
assert_eq!(
|
||||
serde_json::from_value::<ModelInfo>(base_json.clone()).unwrap(),
|
||||
base
|
||||
);
|
||||
for value in [None, Some(false), Some(true)] {
|
||||
let mut json = base_json.clone();
|
||||
json["multi_agent_tools_in_code_mode"] = serde_json::to_value(value).unwrap();
|
||||
let mut expected = base.clone();
|
||||
expected.multi_agent_tools_in_code_mode = value;
|
||||
assert_eq!(serde_json::from_value::<ModelInfo>(json).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_info_deserializes_multi_agent_reasoning_effort() {
|
||||
let mut value =
|
||||
|
||||
Reference in New Issue
Block a user