mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Allow agent roles on full-history forks (#37252)
## Why Multi-agent v2 rejected `agent_type` when `fork_turns` was `all`, forcing callers to choose between a configured role and the parent's full conversation context. ## What changed - Apply an explicitly selected role to full-history forks, including its model and developer instructions. - Preserve the parent's developer instructions when the selected role does not define its own. - Keep the inherited conversation history and model-switch context intact. - Update the `spawn_agent` schema to clarify that roles apply independently of history inheritance. ## Testing - Cover full-history role overrides and developer-instruction precedence in multi-agent v2 tests. GitOrigin-RevId: cd4f35e31d75f56289760f245bff38dd0233abe6
This commit is contained in:
1 parent
74b8f8db93
commit
82b17bc724
5 files changed
+50
-28
No files matched your search
@@ -640,7 +640,7 @@ fn spawn_agent_common_properties_v2(agent_type_description: &str) -> BTreeMap<St
|
||||
(
|
||||
"agent_type".to_string(),
|
||||
JsonSchema::string(Some(format!(
|
||||
"Agent type override for the new agent. Omit unless explicitly asked. Set `fork_turns` to `none` or a positive integer when an explicit override is needed.\n{agent_type_description}"
|
||||
"Agent type override for the new agent. Omit unless explicitly asked. The selected role applies regardless of how much parent history is inherited.\n{agent_type_description}"
|
||||
))),
|
||||
),
|
||||
(
|
||||
|
||||
@@ -346,7 +346,7 @@ async fn spawn_agent_fork_context_rejects_agent_type_override() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn multi_agent_v2_spawn_fork_turns_all_rejects_agent_type_override() {
|
||||
async fn multi_agent_v2_spawn_fork_turns_all_applies_agent_type_override() {
|
||||
let (mut session, mut turn) = make_session_and_context().await;
|
||||
let role_name = install_role_with_model_override(&mut turn).await;
|
||||
let manager = thread_manager();
|
||||
@@ -367,7 +367,7 @@ async fn multi_agent_v2_spawn_fork_turns_all_rejects_agent_type_override() {
|
||||
..turn
|
||||
};
|
||||
|
||||
let err = SpawnAgentHandlerV2::default()
|
||||
SpawnAgentHandlerV2::default()
|
||||
.handle(invocation(
|
||||
Arc::new(session),
|
||||
Arc::new(turn),
|
||||
@@ -380,15 +380,7 @@ async fn multi_agent_v2_spawn_fork_turns_all_rejects_agent_type_override() {
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.err()
|
||||
.expect("fork_turns=all should reject agent_type overrides");
|
||||
|
||||
assert_eq!(
|
||||
err,
|
||||
FunctionCallError::RespondToModel(
|
||||
"Full-history forked agents inherit the parent agent type; omit agent_type, or spawn without a full-history fork.".to_string(),
|
||||
)
|
||||
);
|
||||
.expect("fork_turns=all should apply agent_type overrides");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -69,9 +69,6 @@ async fn handle_spawn_agent(
|
||||
config.service_tier = Some(service_tier.clone());
|
||||
}
|
||||
let is_full_history_fork = matches!(fork_mode, Some(SpawnAgentForkMode::FullHistory));
|
||||
if is_full_history_fork {
|
||||
reject_full_fork_agent_type_override(role_name)?;
|
||||
}
|
||||
apply_requested_spawn_agent_model_overrides(
|
||||
&session,
|
||||
turn.as_ref(),
|
||||
@@ -80,8 +77,13 @@ async fn handle_spawn_agent(
|
||||
args.reasoning_effort.clone(),
|
||||
)
|
||||
.await?;
|
||||
if !is_full_history_fork {
|
||||
if !is_full_history_fork || role_name.is_some() {
|
||||
apply_spawn_agent_role(&session, &mut config, role_name).await?;
|
||||
if is_full_history_fork && config.developer_instructions.is_none() {
|
||||
config
|
||||
.developer_instructions
|
||||
.clone_from(&turn.developer_instructions);
|
||||
}
|
||||
}
|
||||
apply_spawn_agent_service_tier(
|
||||
&session,
|
||||
|
||||
Reference in new issue
Block a user