mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Allow model catalogs to override the V2 spawn_agent description (#46123)
## What changed Read the static V2 `spawn_agent` description from `model_messages.tools.multi_agent.spawn_agent.description`, independently of the runtime tool namespace. Missing or null values retain the bundled description; an empty string suppresses it. Preserve generated model guidance, local usage hints, and tool parameters when applying an override. Resolve the description from the active model so it follows mid-turn model changes. ## Testing Add coverage for sparse and empty catalog values, preservation of generated context and outbound tool schemas, and description updates after mid-turn model changes. GitOrigin-RevId: 96cfa180f8f374dc868e4fabc337e49380e405da
This commit is contained in:
1 parent
a4ee536f01
commit
c5d079470e
11 files changed
+349
-74
No files matched your search
@@ -97,7 +97,10 @@ pub fn create_spawn_agent_tool_v1(options: SpawnAgentToolOptions) -> ToolSpec {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_spawn_agent_tool_v2(options: SpawnAgentToolOptions) -> ToolSpec {
|
||||
pub fn create_spawn_agent_tool_v2(
|
||||
options: SpawnAgentToolOptions,
|
||||
description_override: Option<&str>,
|
||||
) -> ToolSpec {
|
||||
let available_models_description = options.expose_spawn_agent_model_overrides.then(|| {
|
||||
spawn_agent_models_description(&options.available_models, options.multi_agent_version)
|
||||
});
|
||||
@@ -126,6 +129,7 @@ pub fn create_spawn_agent_tool_v2(options: SpawnAgentToolOptions) -> ToolSpec {
|
||||
available_models_description.as_deref(),
|
||||
inherited_model_guidance,
|
||||
options.usage_hint_text,
|
||||
description_override,
|
||||
),
|
||||
strict: false,
|
||||
defer_loading: None,
|
||||
@@ -738,12 +742,21 @@ fn spawn_agent_tool_description_v2(
|
||||
available_models_description: Option<&str>,
|
||||
inherited_model_guidance: Option<&str>,
|
||||
usage_hint_text: Option<String>,
|
||||
description: Option<&str>,
|
||||
) -> String {
|
||||
let agent_role_guidance = available_models_description.unwrap_or_default();
|
||||
let inherited_model_guidance = inherited_model_guidance.unwrap_or_default();
|
||||
|
||||
let tool_description = format!(
|
||||
r#"
|
||||
let tool_description = if let Some(description) = description {
|
||||
format!(
|
||||
r#"
|
||||
{agent_role_guidance}
|
||||
{description}
|
||||
{inherited_model_guidance}"#
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
r#"
|
||||
{agent_role_guidance}
|
||||
Spawns an agent to work on the specified task. If your current task is `/root/task1` and you spawn_agent with task_name "task_3" the agent will have canonical task name `/root/task1/task_3`.
|
||||
You are then able to refer to this agent as `task_3` or `/root/task1/task_3` interchangeably. However an agent `/root/task2/task_3` would only be able to communicate with this agent via its canonical name `/root/task1/task_3`.
|
||||
@@ -754,7 +767,8 @@ It will be able to send you and other running agents messages, and its final ans
|
||||
The new agent's canonical task name will be provided to it along with the message.
|
||||
|
||||
Note that passing `fork_turns="none"` will not pass any surrounding context to the spawned subagent, which may cause the agent to lack the context it needs to complete its task, whereas `fork_turns="all"` will provide the subagent with all surrounding context."#
|
||||
);
|
||||
)
|
||||
};
|
||||
|
||||
if let Some(usage_hint_text) = usage_hint_text {
|
||||
return format!(
|
||||
|
||||
@@ -45,20 +45,23 @@ fn spawn_agent_tool_v2_requires_task_name_and_lists_visible_models() {
|
||||
legacy.multi_agent_version = Some(MultiAgentVersion::V1);
|
||||
let mut disabled = model_preset("disabled", /*show_in_picker*/ true);
|
||||
disabled.multi_agent_version = Some(MultiAgentVersion::Disabled);
|
||||
let tool = create_spawn_agent_tool_v2(SpawnAgentToolOptions {
|
||||
available_models: vec![
|
||||
model_preset("visible", /*show_in_picker*/ true),
|
||||
model_preset("hidden", /*show_in_picker*/ false),
|
||||
legacy,
|
||||
disabled,
|
||||
],
|
||||
agent_type_description: "role help".to_string(),
|
||||
expose_agent_type: true,
|
||||
hide_agent_type_model_reasoning: false,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: None,
|
||||
});
|
||||
let tool = create_spawn_agent_tool_v2(
|
||||
SpawnAgentToolOptions {
|
||||
available_models: vec![
|
||||
model_preset("visible", /*show_in_picker*/ true),
|
||||
model_preset("hidden", /*show_in_picker*/ false),
|
||||
legacy,
|
||||
disabled,
|
||||
],
|
||||
agent_type_description: "role help".to_string(),
|
||||
expose_agent_type: true,
|
||||
hide_agent_type_model_reasoning: false,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: None,
|
||||
},
|
||||
/*description_override*/ None,
|
||||
);
|
||||
|
||||
let ToolSpec::Function(ResponsesApiTool {
|
||||
description,
|
||||
@@ -127,6 +130,47 @@ fn spawn_agent_tool_v2_requires_task_name_and_lists_visible_models() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawn_agent_catalog_description_preserves_generated_context() {
|
||||
let options = SpawnAgentToolOptions {
|
||||
available_models: vec![model_preset("visible", /*show_in_picker*/ true)],
|
||||
agent_type_description: "Available agent roles: explorer".to_string(),
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: Some("Local usage hint.".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
let ToolSpec::Function(default_tool) =
|
||||
create_spawn_agent_tool_v2(options.clone(), /*description_override*/ None)
|
||||
else {
|
||||
panic!("spawn_agent should be a function tool");
|
||||
};
|
||||
let ToolSpec::Function(mut configured_tool) =
|
||||
create_spawn_agent_tool_v2(options, Some("Catalog spawning guidance."))
|
||||
else {
|
||||
panic!("spawn_agent should be a function tool");
|
||||
};
|
||||
assert!(
|
||||
configured_tool
|
||||
.description
|
||||
.contains("Catalog spawning guidance.")
|
||||
);
|
||||
assert!(configured_tool.description.contains("`visible-model`"));
|
||||
assert!(
|
||||
configured_tool
|
||||
.description
|
||||
.contains(SPAWN_AGENT_INHERITED_MODEL_GUIDANCE)
|
||||
);
|
||||
assert!(configured_tool.description.ends_with("Local usage hint."));
|
||||
assert!(
|
||||
!configured_tool
|
||||
.description
|
||||
.contains("Spawns an agent to work on the specified task.")
|
||||
);
|
||||
configured_tool.description = default_tool.description.clone();
|
||||
assert_eq!(configured_tool, default_tool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawn_agent_tool_v1_keeps_legacy_fork_context_field() {
|
||||
let tool = create_spawn_agent_tool_v1(SpawnAgentToolOptions {
|
||||
@@ -182,22 +226,25 @@ fn spawn_agent_tool_v1_keeps_legacy_fork_context_field() {
|
||||
|
||||
#[test]
|
||||
fn spawn_agent_tool_caps_visible_model_summaries() {
|
||||
let tool = create_spawn_agent_tool_v2(SpawnAgentToolOptions {
|
||||
available_models: vec![
|
||||
model_preset("first", /*show_in_picker*/ true),
|
||||
model_preset("second", /*show_in_picker*/ true),
|
||||
model_preset("third", /*show_in_picker*/ true),
|
||||
model_preset("fourth", /*show_in_picker*/ true),
|
||||
model_preset("fifth", /*show_in_picker*/ true),
|
||||
model_preset("sixth", /*show_in_picker*/ true),
|
||||
],
|
||||
agent_type_description: "role help".to_string(),
|
||||
expose_agent_type: true,
|
||||
hide_agent_type_model_reasoning: false,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: None,
|
||||
});
|
||||
let tool = create_spawn_agent_tool_v2(
|
||||
SpawnAgentToolOptions {
|
||||
available_models: vec![
|
||||
model_preset("first", /*show_in_picker*/ true),
|
||||
model_preset("second", /*show_in_picker*/ true),
|
||||
model_preset("third", /*show_in_picker*/ true),
|
||||
model_preset("fourth", /*show_in_picker*/ true),
|
||||
model_preset("fifth", /*show_in_picker*/ true),
|
||||
model_preset("sixth", /*show_in_picker*/ true),
|
||||
],
|
||||
agent_type_description: "role help".to_string(),
|
||||
expose_agent_type: true,
|
||||
hide_agent_type_model_reasoning: false,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: None,
|
||||
},
|
||||
/*description_override*/ None,
|
||||
);
|
||||
|
||||
let ToolSpec::Function(ResponsesApiTool { description, .. }) = tool else {
|
||||
panic!("spawn_agent should be a function tool");
|
||||
@@ -235,15 +282,18 @@ fn spawn_agent_tool_caps_reasoning_effort_value_length() {
|
||||
|
||||
#[test]
|
||||
fn spawn_agent_tool_keeps_model_controls_when_spawn_metadata_is_hidden() {
|
||||
let tool = create_spawn_agent_tool_v2(SpawnAgentToolOptions {
|
||||
available_models: vec![model_preset("visible", /*show_in_picker*/ true)],
|
||||
agent_type_description: "role help".to_string(),
|
||||
expose_agent_type: false,
|
||||
hide_agent_type_model_reasoning: true,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: None,
|
||||
});
|
||||
let tool = create_spawn_agent_tool_v2(
|
||||
SpawnAgentToolOptions {
|
||||
available_models: vec![model_preset("visible", /*show_in_picker*/ true)],
|
||||
agent_type_description: "role help".to_string(),
|
||||
expose_agent_type: false,
|
||||
hide_agent_type_model_reasoning: true,
|
||||
expose_spawn_agent_model_overrides: true,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: None,
|
||||
},
|
||||
/*description_override*/ None,
|
||||
);
|
||||
|
||||
let ToolSpec::Function(ResponsesApiTool {
|
||||
description,
|
||||
@@ -268,15 +318,18 @@ fn spawn_agent_tool_keeps_model_controls_when_spawn_metadata_is_hidden() {
|
||||
|
||||
#[test]
|
||||
fn spawn_agent_tool_hides_model_controls_without_override_exposure() {
|
||||
let tool = create_spawn_agent_tool_v2(SpawnAgentToolOptions {
|
||||
available_models: vec![model_preset("visible", /*show_in_picker*/ true)],
|
||||
agent_type_description: "role help".to_string(),
|
||||
expose_agent_type: false,
|
||||
hide_agent_type_model_reasoning: true,
|
||||
expose_spawn_agent_model_overrides: false,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: None,
|
||||
});
|
||||
let tool = create_spawn_agent_tool_v2(
|
||||
SpawnAgentToolOptions {
|
||||
available_models: vec![model_preset("visible", /*show_in_picker*/ true)],
|
||||
agent_type_description: "role help".to_string(),
|
||||
expose_agent_type: false,
|
||||
hide_agent_type_model_reasoning: true,
|
||||
expose_spawn_agent_model_overrides: false,
|
||||
multi_agent_version: MultiAgentVersion::V2,
|
||||
usage_hint_text: None,
|
||||
},
|
||||
Some(""),
|
||||
);
|
||||
|
||||
let ToolSpec::Function(ResponsesApiTool {
|
||||
description,
|
||||
|
||||
@@ -25,11 +25,18 @@ use codex_tools::ToolSpec;
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Handler {
|
||||
options: SpawnAgentToolOptions,
|
||||
description_override: Option<String>,
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub(crate) fn new(options: SpawnAgentToolOptions) -> Self {
|
||||
Self { options }
|
||||
pub(crate) fn new(
|
||||
options: SpawnAgentToolOptions,
|
||||
description_override: Option<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
options,
|
||||
description_override,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +46,7 @@ impl ToolExecutor<ToolInvocation> for Handler {
|
||||
}
|
||||
|
||||
fn spec(&self) -> ToolSpec {
|
||||
create_spawn_agent_tool_v2(self.options.clone())
|
||||
create_spawn_agent_tool_v2(self.options.clone(), self.description_override.as_deref())
|
||||
}
|
||||
|
||||
fn handle<'a>(&'a self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'a>
|
||||
|
||||
Reference in new issue
Block a user