mirror of
https://github.com/openai/codex.git
synced 2026-12-04 00:51:02 +00:00
Add an option to disable multi-agent v2 direct messaging (#47540)
## What changed Add `features.multi_agent_v2.disable_direct_message`, defaulting to `false`. When enabled, omit `send_message` and `followup_task` while preserving spawning, automatic child results, and the remaining agent management tools. Require an available message-board `post` tool when this option is enabled for sessions using multi-agent v2 collaboration tools, exempting internal worker sessions. ## Testing Extend configuration parsing tests and run the message-board subscription/resume scenario with direct messaging both enabled and disabled. Verify post search, subscription behavior, and which collaboration tools are exposed. GitOrigin-RevId: 72ec22ef0b92fa81e02cdeb058d8b4f93aca3be6
This commit is contained in:
@@ -2663,6 +2663,10 @@
|
||||
"minimum": 0.0,
|
||||
"type": "integer"
|
||||
},
|
||||
"disable_direct_message": {
|
||||
"description": "Disable the model's direct-message tools; spawning and automatic child results remain available.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -12004,6 +12004,7 @@ tool_namespace = "agents"
|
||||
hide_spawn_agent_metadata = true
|
||||
expose_spawn_agent_model_overrides = false
|
||||
wait_agent_enabled = false
|
||||
disable_direct_message = true
|
||||
non_code_mode_only = true
|
||||
|
||||
[agents]
|
||||
@@ -12059,6 +12060,7 @@ max_concurrent_threads_per_session = 9
|
||||
assert!(config.multi_agent_v2.hide_spawn_agent_metadata);
|
||||
assert!(!config.multi_agent_v2.expose_spawn_agent_model_overrides);
|
||||
assert!(!config.multi_agent_v2.wait_agent_enabled);
|
||||
assert!(config.multi_agent_v2.disable_direct_message);
|
||||
assert!(config.multi_agent_v2.non_code_mode_only);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1322,6 +1322,7 @@ pub struct MultiAgentV2Config {
|
||||
pub hide_spawn_agent_metadata: bool,
|
||||
pub expose_spawn_agent_model_overrides: bool,
|
||||
pub wait_agent_enabled: bool,
|
||||
pub disable_direct_message: bool,
|
||||
pub non_code_mode_only: bool,
|
||||
}
|
||||
|
||||
@@ -1341,6 +1342,7 @@ impl MultiAgentV2Config {
|
||||
hide_spawn_agent_metadata: true,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
wait_agent_enabled: true,
|
||||
disable_direct_message: false,
|
||||
non_code_mode_only: true,
|
||||
}
|
||||
}
|
||||
@@ -2772,6 +2774,9 @@ fn resolve_multi_agent_v2_config(config_toml: &ConfigToml) -> MultiAgentV2Config
|
||||
let wait_agent_enabled = base
|
||||
.and_then(|config| config.wait_agent_enabled)
|
||||
.unwrap_or(default.wait_agent_enabled);
|
||||
let disable_direct_message = base
|
||||
.and_then(|config| config.disable_direct_message)
|
||||
.unwrap_or(default.disable_direct_message);
|
||||
let subagent_developer_instructions = base
|
||||
.and_then(|config| config.subagent_developer_instructions.as_ref())
|
||||
.map(|instructions| instructions.trim().to_string());
|
||||
@@ -2801,6 +2806,7 @@ fn resolve_multi_agent_v2_config(config_toml: &ConfigToml) -> MultiAgentV2Config
|
||||
hide_spawn_agent_metadata,
|
||||
expose_spawn_agent_model_overrides,
|
||||
wait_agent_enabled,
|
||||
disable_direct_message,
|
||||
non_code_mode_only,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ impl ToolRouter {
|
||||
}
|
||||
|
||||
// Answers if the tool plan lets the model invoke the tool directly, through code mode, or deferred tool search.
|
||||
fn exposes_tool(&self, name: &ToolName) -> bool {
|
||||
pub(super) fn exposes_tool(&self, name: &ToolName) -> bool {
|
||||
let name = name.clone().with_default_namespace();
|
||||
if self
|
||||
.code_mode_tool_names
|
||||
|
||||
@@ -481,14 +481,33 @@ pub(crate) fn finalize_tool_router(
|
||||
.filter(|info| !info.is_empty());
|
||||
let child_management_tools = required_child_management_tool_names(turn_context, model_info);
|
||||
|
||||
Ok(ToolRouter::from_parts(
|
||||
let router = ToolRouter::from_parts(
|
||||
registry,
|
||||
model_visible_specs,
|
||||
tool_mode,
|
||||
code_mode_tool_names,
|
||||
tool_namespaces_info,
|
||||
&child_management_tools,
|
||||
))
|
||||
);
|
||||
// Internal workers can inherit MAv2 configuration without using the board.
|
||||
if multi_agent_v2_enabled(turn_context)
|
||||
&& collab_tools_enabled(turn_context, model_info)
|
||||
&& turn_context.config.multi_agent_v2.disable_direct_message
|
||||
&& !turn_context.session_source.is_internal()
|
||||
{
|
||||
let post_tool = ToolName::new(
|
||||
turn_context.config.multi_agent_v2.tool_namespace.clone(),
|
||||
"post",
|
||||
);
|
||||
if !router.exposes_tool(&post_tool) {
|
||||
return Err(CodexErrorDetails::InvalidRequest(
|
||||
"disable_direct_message requires an available agent message board in this session"
|
||||
.to_owned(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
Ok(router)
|
||||
}
|
||||
|
||||
fn apply_direct_model_only_namespace_overrides(
|
||||
@@ -672,12 +691,16 @@ fn required_child_management_tool_names(
|
||||
namespace_tools_enabled(turn_context)
|
||||
.then_some(turn_context.config.multi_agent_v2.tool_namespace.as_deref())
|
||||
.flatten(),
|
||||
&[
|
||||
"send_message",
|
||||
"followup_task",
|
||||
"interrupt_agent",
|
||||
"list_agents",
|
||||
],
|
||||
if turn_context.config.multi_agent_v2.disable_direct_message {
|
||||
&["interrupt_agent", "list_agents"]
|
||||
} else {
|
||||
&[
|
||||
"send_message",
|
||||
"followup_task",
|
||||
"interrupt_agent",
|
||||
"list_agents",
|
||||
]
|
||||
},
|
||||
),
|
||||
};
|
||||
let mut tools = names
|
||||
@@ -1291,24 +1314,26 @@ fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, registry: &mut Too
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(
|
||||
SendMessageHandlerV2,
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("send_message"),
|
||||
model_messages.multi_agent_tool_parameters_override("send_message"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(
|
||||
FollowupTaskHandlerV2,
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("followup_task"),
|
||||
model_messages.multi_agent_tool_parameters_override("followup_task"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
if !turn_context.config.multi_agent_v2.disable_direct_message {
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(
|
||||
SendMessageHandlerV2,
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("send_message"),
|
||||
model_messages.multi_agent_tool_parameters_override("send_message"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(
|
||||
FollowupTaskHandlerV2,
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("followup_task"),
|
||||
model_messages.multi_agent_tool_parameters_override("followup_task"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
}
|
||||
if turn_context.config.multi_agent_v2.wait_agent_enabled {
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(
|
||||
|
||||
@@ -6,6 +6,7 @@ use codex_core::TurnInputRequest;
|
||||
use codex_features::Feature;
|
||||
use codex_protocol::items::TurnItem;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use core_test_support::context_snapshot;
|
||||
use core_test_support::context_snapshot::ContextSnapshotOptions;
|
||||
@@ -328,11 +329,21 @@ async fn board_is_shared_with_children_survives_resume_and_skips_idle_notices()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case(false; "direct_messages")]
|
||||
#[test_case::test_case(true; "channels_only")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn board_unsubscribe_survives_post_and_resume_until_resubscribed() -> anyhow::Result<()> {
|
||||
async fn board_unsubscribe_survives_post_and_resume_until_resubscribed(
|
||||
disable_direct_message: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let server = responses::start_mock_server().await;
|
||||
let root = test_codex()
|
||||
.with_config(configure)
|
||||
.with_config(move |config| {
|
||||
configure(config);
|
||||
config.multi_agent_v2.disable_direct_message = disable_direct_message;
|
||||
})
|
||||
.with_model_info_override("gpt-5.5", |model| {
|
||||
model.multi_agent_version = Some(MultiAgentVersion::V2);
|
||||
})
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
let posted = responses::mount_sse_sequence(
|
||||
@@ -343,6 +354,11 @@ async fn board_unsubscribe_survives_post_and_resume_until_resubscribed() -> anyh
|
||||
"post",
|
||||
json!({"new_channel_name":"design","text":"A shared decision."}),
|
||||
),
|
||||
tool(
|
||||
"read-discussion",
|
||||
"search_posts",
|
||||
json!({"channel_name":"design"}),
|
||||
),
|
||||
done(),
|
||||
],
|
||||
)
|
||||
@@ -353,6 +369,12 @@ async fn board_unsubscribe_survives_post_and_resume_until_resubscribed() -> anyh
|
||||
.function_call_output_text("start-discussion")
|
||||
.context("initial post result")?,
|
||||
)?;
|
||||
let read: Value = serde_json::from_str(
|
||||
&posted
|
||||
.function_call_output_text("read-discussion")
|
||||
.context("read result")?,
|
||||
)?;
|
||||
assert_eq!(read["results"][0]["message_id"], post["message_id"]);
|
||||
let thread_id = &post["thread_id"];
|
||||
let opted_out = responses::mount_sse_sequence(
|
||||
&server,
|
||||
@@ -450,12 +472,16 @@ async fn board_unsubscribe_survives_post_and_resume_until_resubscribed() -> anyh
|
||||
let resumed = test_codex()
|
||||
.with_config(move |config| {
|
||||
configure(config);
|
||||
config.multi_agent_v2.disable_direct_message = disable_direct_message;
|
||||
config.model_provider.base_url = Some(base_url);
|
||||
config
|
||||
.features
|
||||
.disable(Feature::EnableRequestCompression)
|
||||
.expect("read raw request bodies from the gated mock");
|
||||
})
|
||||
.with_model_info_override("gpt-5.5", |model| {
|
||||
model.multi_agent_version = Some(MultiAgentVersion::V2);
|
||||
})
|
||||
.restart(&server, &root)
|
||||
.await?;
|
||||
resumed
|
||||
@@ -594,6 +620,29 @@ async fn board_unsubscribe_survives_post_and_resume_until_resubscribed() -> anyh
|
||||
};
|
||||
assert_eq!(notices, expected, "phase: {phase}");
|
||||
}
|
||||
let requests = streaming.requests().await;
|
||||
for body in &requests {
|
||||
let request: Value = serde_json::from_slice(body)?;
|
||||
for name in ["send_message", "followup_task"] {
|
||||
assert_eq!(
|
||||
responses::namespace_child_tool(&request, "collaboration", name).is_some(),
|
||||
!disable_direct_message,
|
||||
"{name}",
|
||||
);
|
||||
}
|
||||
for name in [
|
||||
"spawn_agent",
|
||||
"wait_agent",
|
||||
"interrupt_agent",
|
||||
"list_agents",
|
||||
"post",
|
||||
] {
|
||||
assert!(
|
||||
responses::namespace_child_tool(&request, "collaboration", name).is_some(),
|
||||
"{name}"
|
||||
);
|
||||
}
|
||||
}
|
||||
child.shutdown_and_wait().await?;
|
||||
resumed.codex.shutdown_and_wait().await?;
|
||||
streaming.shutdown().await;
|
||||
|
||||
@@ -293,6 +293,9 @@ pub struct MultiAgentV2ConfigToml {
|
||||
/// Expose the multi-agent v2 `wait_agent` tool.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub wait_agent_enabled: Option<bool>,
|
||||
/// Disable the model's direct-message tools; spawning and automatic child results remain available.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_direct_message: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub non_code_mode_only: Option<bool>,
|
||||
}
|
||||
|
||||
@@ -735,6 +735,7 @@ tool_namespace = "agents"
|
||||
hide_spawn_agent_metadata = true
|
||||
expose_spawn_agent_model_overrides = true
|
||||
wait_agent_enabled = false
|
||||
disable_direct_message = true
|
||||
non_code_mode_only = true
|
||||
"#,
|
||||
)
|
||||
@@ -762,6 +763,7 @@ non_code_mode_only = true
|
||||
hide_spawn_agent_metadata: Some(true),
|
||||
expose_spawn_agent_model_overrides: Some(true),
|
||||
wait_agent_enabled: Some(false),
|
||||
disable_direct_message: Some(true),
|
||||
non_code_mode_only: Some(true),
|
||||
}))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user