mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Support catalog descriptions for all multi-agent V2 tools (#46297)
## Why Model catalog description overrides only covered `spawn_agent`, leaving the other multi-agent V2 tools with fixed descriptions. ## What changed Extend `model_messages.tools.multi_agent` description overrides to `send_message`, `followup_task`, `wait_agent`, `interrupt_agent`, and `list_agents`. Resolve each override by tool name across namespaced, plain, and Code Mode exposure. Missing or null descriptions retain bundled text; empty strings suppress static text without disabling tools. Preserve `spawn_agent` runtime guidance, tool schemas, and execution behavior. Descriptions follow mid-turn model changes. ## Testing Expand integration coverage to all six tools, including missing, null, empty, and sparse overrides; plain, namespaced, and Code Mode exposure; unchanged V1 behavior; and mid-turn model changes. GitOrigin-RevId: a2c47eb8efb28c3eeebcc6482e36c188c38a6dd1
This commit is contained in:
1 parent
17baabd01b
commit
3e581ebca8
10 files changed
+401
-191
No files matched your search
@@ -9,6 +9,7 @@ pub(crate) mod handlers;
|
||||
pub(crate) mod hook_names;
|
||||
pub(crate) mod hosted_spec;
|
||||
pub(crate) mod lifecycle;
|
||||
mod multi_agent_tool;
|
||||
pub(crate) mod network_approval;
|
||||
pub(crate) mod orchestrator;
|
||||
pub(crate) mod parallel;
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
//! Applies captured Multi-Agent V2 description and namespace overrides to tool specifications.
|
||||
//! Execution and parameter schemas are delegated unchanged to the underlying runtime.
|
||||
|
||||
use crate::session::session::Session;
|
||||
use crate::tools::context::ToolInvocation;
|
||||
use crate::tools::registry::CoreToolRuntime;
|
||||
use codex_tools::ResponsesApiNamespace;
|
||||
use codex_tools::ResponsesApiNamespaceTool;
|
||||
use codex_tools::ToolExecutor;
|
||||
use codex_tools::ToolExposure;
|
||||
use codex_tools::ToolName;
|
||||
use codex_tools::ToolSearchInfo;
|
||||
use codex_tools::ToolSpec;
|
||||
use futures::future::BoxFuture;
|
||||
use std::sync::Arc;
|
||||
|
||||
const MULTI_AGENT_V2_NAMESPACE_DESCRIPTION: &str = "Tools for spawning and managing sub-agents.";
|
||||
|
||||
pub(super) fn multi_agent_v2_handler(
|
||||
handler: impl CoreToolRuntime + 'static,
|
||||
namespace: Option<&str>,
|
||||
description_override: Option<&str>,
|
||||
) -> Arc<dyn CoreToolRuntime> {
|
||||
if namespace.is_none() && description_override.is_none() {
|
||||
return Arc::new(handler);
|
||||
}
|
||||
Arc::new(MultiAgentV2ToolOverrides {
|
||||
handler: Arc::new(handler),
|
||||
namespace: namespace.map(str::to_owned),
|
||||
description_override: description_override.map(str::to_owned),
|
||||
})
|
||||
}
|
||||
|
||||
struct MultiAgentV2ToolOverrides {
|
||||
handler: Arc<dyn CoreToolRuntime>,
|
||||
namespace: Option<String>,
|
||||
description_override: Option<String>,
|
||||
}
|
||||
|
||||
impl ToolExecutor<ToolInvocation> for MultiAgentV2ToolOverrides {
|
||||
fn tool_name(&self) -> ToolName {
|
||||
let tool_name = self.handler.tool_name();
|
||||
match &self.namespace {
|
||||
Some(namespace) => ToolName::namespaced(namespace.clone(), tool_name.name),
|
||||
None => tool_name,
|
||||
}
|
||||
}
|
||||
|
||||
fn spec(&self) -> ToolSpec {
|
||||
let mut spec = self.handler.spec();
|
||||
if let ToolSpec::Function(tool) = &mut spec
|
||||
&& let Some(description) = &self.description_override
|
||||
{
|
||||
tool.description.clone_from(description);
|
||||
}
|
||||
match (&self.namespace, spec) {
|
||||
(Some(namespace), ToolSpec::Function(tool)) => {
|
||||
ToolSpec::Namespace(ResponsesApiNamespace {
|
||||
name: namespace.clone(),
|
||||
description: MULTI_AGENT_V2_NAMESPACE_DESCRIPTION.to_string(),
|
||||
tools: vec![ResponsesApiNamespaceTool::Function(tool)],
|
||||
})
|
||||
}
|
||||
(_, spec) => spec,
|
||||
}
|
||||
}
|
||||
|
||||
fn exposure(&self) -> ToolExposure {
|
||||
self.handler.exposure()
|
||||
}
|
||||
|
||||
fn supports_parallel_tool_calls(&self) -> bool {
|
||||
self.handler.supports_parallel_tool_calls()
|
||||
}
|
||||
|
||||
fn search_info(&self) -> Option<ToolSearchInfo> {
|
||||
self.handler.search_info()
|
||||
}
|
||||
|
||||
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
|
||||
where
|
||||
ToolInvocation: 'a,
|
||||
{
|
||||
self.handler.handle(invocation)
|
||||
}
|
||||
}
|
||||
|
||||
impl CoreToolRuntime for MultiAgentV2ToolOverrides {
|
||||
fn wait_until_ready<'a>(&'a self, session: &'a Arc<Session>) -> Option<BoxFuture<'a, ()>> {
|
||||
self.handler.wait_until_ready(session)
|
||||
}
|
||||
|
||||
fn matches_kind(&self, payload: &crate::tools::context::ToolPayload) -> bool {
|
||||
self.handler.matches_kind(payload)
|
||||
}
|
||||
|
||||
fn create_diff_consumer(
|
||||
&self,
|
||||
) -> Option<Box<dyn crate::tools::registry::ToolArgumentDiffConsumer>> {
|
||||
self.handler.create_diff_consumer()
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ use crate::image_preparation::unified_image_budget_enabled;
|
||||
use crate::session::session::Session;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
use crate::tools::code_mode::execute_spec::create_code_mode_tool;
|
||||
use crate::tools::context::ToolInvocation;
|
||||
use crate::tools::effective_tool_mode;
|
||||
use crate::tools::handlers::ApplyPatchHandler;
|
||||
use crate::tools::handlers::CodeModeExecuteHandler;
|
||||
@@ -54,7 +53,7 @@ use crate::tools::handlers::tool_search_spec::ToolSearchSourceListing;
|
||||
use crate::tools::handlers::view_image_spec::ViewImageToolOptions;
|
||||
use crate::tools::hosted_spec::WebSearchToolOptions;
|
||||
use crate::tools::hosted_spec::create_web_search_tool;
|
||||
use crate::tools::registry::CoreToolRuntime;
|
||||
use crate::tools::multi_agent_tool::multi_agent_v2_handler;
|
||||
#[cfg(test)]
|
||||
use crate::tools::registry::RegisteredTool;
|
||||
use crate::tools::registry::ToolExposure;
|
||||
@@ -81,7 +80,6 @@ use codex_protocol::openai_models::InputModality;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
use codex_protocol::openai_models::ToolMode;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_tools::ResponsesApiNamespace;
|
||||
use codex_tools::ResponsesApiNamespaceTool;
|
||||
use codex_tools::TOOL_SEARCH_TOOL_NAME;
|
||||
use codex_tools::ToolCall as ExtensionToolCall;
|
||||
@@ -89,7 +87,6 @@ use codex_tools::ToolEnvironmentMode;
|
||||
use codex_tools::ToolExecutor;
|
||||
use codex_tools::ToolExposures;
|
||||
use codex_tools::ToolName;
|
||||
use codex_tools::ToolSearchInfo;
|
||||
use codex_tools::ToolSpec;
|
||||
use codex_tools::UnifiedExecShellMode;
|
||||
use codex_tools::can_request_original_image_detail;
|
||||
@@ -97,7 +94,6 @@ use codex_tools::collect_code_mode_exec_prompt_tool_definitions;
|
||||
use codex_tools::collect_request_plugin_install_entries;
|
||||
use codex_tools::default_namespace_description;
|
||||
use codex_tools::request_user_input_available_modes;
|
||||
use futures::future::BoxFuture;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
@@ -105,7 +101,6 @@ use std::collections::btree_map::Entry;
|
||||
use std::sync::Arc;
|
||||
use tracing::instrument;
|
||||
|
||||
const MULTI_AGENT_V2_NAMESPACE_DESCRIPTION: &str = "Tools for spawning and managing sub-agents.";
|
||||
const IMAGE_GEN_NAMESPACE: &str = "image_gen";
|
||||
const IMAGEGEN_TOOL_NAME: &str = "imagegen";
|
||||
|
||||
@@ -1248,8 +1243,9 @@ fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, registry: &mut Too
|
||||
let turn_context = context.turn_context;
|
||||
if collab_tools_enabled(turn_context, context.model_info) {
|
||||
if multi_agent_v2_enabled(turn_context) {
|
||||
let spawn_agent_description = ResolvedModelMessages::from_model(context.model_info)
|
||||
.spawn_agent_description_override();
|
||||
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 {
|
||||
@@ -1284,15 +1280,26 @@ fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, registry: &mut Too
|
||||
spawn_agent_description.map(str::to_owned),
|
||||
),
|
||||
tool_namespace,
|
||||
// Spawn composes the selected description with runtime model and usage guidance.
|
||||
/*description_override*/
|
||||
None,
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(SendMessageHandlerV2, tool_namespace),
|
||||
multi_agent_v2_handler(
|
||||
SendMessageHandlerV2,
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("send_message"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(FollowupTaskHandlerV2, tool_namespace),
|
||||
multi_agent_v2_handler(
|
||||
FollowupTaskHandlerV2,
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("followup_task"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
if turn_context.config.multi_agent_v2.wait_agent_enabled {
|
||||
@@ -1300,16 +1307,25 @@ fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, registry: &mut Too
|
||||
multi_agent_v2_handler(
|
||||
WaitAgentHandlerV2::new(context.wait_agent_timeouts),
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("wait_agent"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
}
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(InterruptAgentHandler, tool_namespace),
|
||||
multi_agent_v2_handler(
|
||||
InterruptAgentHandler,
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("interrupt_agent"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
registry.register_trusted_with_exposure(
|
||||
multi_agent_v2_handler(ListAgentsHandlerV2, tool_namespace),
|
||||
multi_agent_v2_handler(
|
||||
ListAgentsHandlerV2,
|
||||
tool_namespace,
|
||||
model_messages.multi_agent_tool_description_override("list_agents"),
|
||||
),
|
||||
exposure,
|
||||
);
|
||||
} else {
|
||||
@@ -1423,76 +1439,6 @@ fn append_extension_tool_executors(
|
||||
standalone_web_search_tool
|
||||
}
|
||||
|
||||
fn multi_agent_v2_handler(
|
||||
handler: impl CoreToolRuntime + 'static,
|
||||
namespace: Option<&str>,
|
||||
) -> Arc<dyn CoreToolRuntime> {
|
||||
match namespace {
|
||||
Some(namespace) => Arc::new(MultiAgentV2NamespaceOverride {
|
||||
handler: Arc::new(handler),
|
||||
namespace: namespace.to_string(),
|
||||
}),
|
||||
None => Arc::new(handler),
|
||||
}
|
||||
}
|
||||
|
||||
struct MultiAgentV2NamespaceOverride {
|
||||
handler: Arc<dyn CoreToolRuntime>,
|
||||
namespace: String,
|
||||
}
|
||||
|
||||
impl ToolExecutor<ToolInvocation> for MultiAgentV2NamespaceOverride {
|
||||
fn tool_name(&self) -> ToolName {
|
||||
ToolName::namespaced(self.namespace.clone(), self.handler.tool_name().name)
|
||||
}
|
||||
|
||||
fn spec(&self) -> ToolSpec {
|
||||
match self.handler.spec() {
|
||||
ToolSpec::Function(tool) => ToolSpec::Namespace(ResponsesApiNamespace {
|
||||
name: self.namespace.clone(),
|
||||
description: MULTI_AGENT_V2_NAMESPACE_DESCRIPTION.to_string(),
|
||||
tools: vec![ResponsesApiNamespaceTool::Function(tool)],
|
||||
}),
|
||||
spec => spec,
|
||||
}
|
||||
}
|
||||
|
||||
fn exposure(&self) -> ToolExposure {
|
||||
self.handler.exposure()
|
||||
}
|
||||
|
||||
fn supports_parallel_tool_calls(&self) -> bool {
|
||||
self.handler.supports_parallel_tool_calls()
|
||||
}
|
||||
|
||||
fn search_info(&self) -> Option<ToolSearchInfo> {
|
||||
self.handler.search_info()
|
||||
}
|
||||
|
||||
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
|
||||
where
|
||||
ToolInvocation: 'a,
|
||||
{
|
||||
self.handler.handle(invocation)
|
||||
}
|
||||
}
|
||||
|
||||
impl CoreToolRuntime for MultiAgentV2NamespaceOverride {
|
||||
fn wait_until_ready<'a>(&'a self, session: &'a Arc<Session>) -> Option<BoxFuture<'a, ()>> {
|
||||
self.handler.wait_until_ready(session)
|
||||
}
|
||||
|
||||
fn matches_kind(&self, payload: &crate::tools::context::ToolPayload) -> bool {
|
||||
self.handler.matches_kind(payload)
|
||||
}
|
||||
|
||||
fn create_diff_consumer(
|
||||
&self,
|
||||
) -> Option<Box<dyn crate::tools::registry::ToolArgumentDiffConsumer>> {
|
||||
self.handler.create_diff_consumer()
|
||||
}
|
||||
}
|
||||
|
||||
fn compare_code_mode_tools(
|
||||
left: &codex_code_mode::ToolDefinition,
|
||||
right: &codex_code_mode::ToolDefinition,
|
||||
|
||||
Reference in new issue
Block a user