mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Preserve base and developer instructions in host child preparation (#62128)
## Why Hosts preparing a child thread lacked the parent's effective base instructions and the developer instructions a native subagent would inherit. Hosts also need the base instruction provenance to preserve custom text while letting model-owned instructions resolve for the child's model. ## What changed Include effective base instruction text and provenance in `PreparedChildContext`. Share developer instruction selection with native subagent creation so host preparation uses the configured V2 subagent override when present and falls back to the parent turn's developer instructions otherwise. ## Testing Add integration coverage that starts a child on a different model and checks that custom base instructions persist, model-owned instructions resolve for the child model, and the V2 override takes precedence over the parent developer instructions. GitOrigin-RevId: 0e151e343e58d995c8901a9ba819cb7f60d248f5
This commit is contained in:
@@ -167,21 +167,21 @@ fn build_agent_shared_config(turn: &TurnContext) -> Result<Config, String> {
|
||||
.or(turn.model_info().default_reasoning_level.as_ref())
|
||||
.cloned();
|
||||
config.model_reasoning_summary = Some(turn.reasoning_summary());
|
||||
config.developer_instructions = turn.developer_instructions.clone();
|
||||
if turn.multi_agent_version == MultiAgentVersion::V2
|
||||
&& let Some(developer_instructions) = turn
|
||||
.config
|
||||
.multi_agent_v2
|
||||
.subagent_developer_instructions
|
||||
.clone()
|
||||
{
|
||||
config.developer_instructions = Some(developer_instructions);
|
||||
}
|
||||
config.developer_instructions = inherited_developer_instructions(turn);
|
||||
apply_spawn_agent_runtime_overrides(&mut config, turn)?;
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub(crate) fn inherited_developer_instructions(turn: &TurnContext) -> Option<String> {
|
||||
if turn.multi_agent_version == MultiAgentVersion::V2
|
||||
&& let Some(instructions) = &turn.config.multi_agent_v2.subagent_developer_instructions
|
||||
{
|
||||
return Some(instructions.clone());
|
||||
}
|
||||
turn.developer_instructions.clone()
|
||||
}
|
||||
|
||||
fn reject_full_fork_agent_type_override(agent_type: Option<&str>) -> Result<(), String> {
|
||||
if agent_type.is_some() {
|
||||
return Err(
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use super::spawn::create_spawn;
|
||||
use super::types::HostThreadSpawnReservation;
|
||||
use super::types::PreparedChildContext;
|
||||
use crate::agent::child_config::inherited_developer_instructions;
|
||||
use crate::agent::control::inherited_dynamic_tools;
|
||||
use crate::codex_thread::CodexThread;
|
||||
use crate::function_tool::FunctionCallError;
|
||||
@@ -229,6 +230,8 @@ pub(crate) async fn prepare(
|
||||
thread.session.services.exec_policy.snapshot();
|
||||
Ok(PreparedChildContext {
|
||||
originator: turn.originator.clone(),
|
||||
base_instructions: thread.session.get_base_instructions().await,
|
||||
developer_instructions: inherited_developer_instructions(turn),
|
||||
user_instructions: instructions
|
||||
.and_then(|md| md.user_instructions.as_ref())
|
||||
.map(|entry| entry.text.clone()),
|
||||
|
||||
@@ -12,6 +12,7 @@ use codex_protocol::ThreadId;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::dynamic_tools::DynamicToolSpec;
|
||||
use codex_protocol::models::BaseInstructions;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::TurnEnvironmentRequest;
|
||||
@@ -62,6 +63,13 @@ pub struct HostThreadSpawnReservation {
|
||||
/// Repository instructions are discovered at the destination.
|
||||
pub struct PreparedChildContext {
|
||||
pub originator: String,
|
||||
/// Effective parent base instructions, including whether they are custom or model-owned.
|
||||
/// Apply both `text` and `provenance` to the destination config so model-owned instructions
|
||||
/// retain their normal model-switch behavior. Apply requested child overrides afterwards.
|
||||
pub base_instructions: BaseInstructions,
|
||||
/// Developer instructions under native inheritance rules, including the V2 subagent override.
|
||||
/// Requested child role overrides are applied after this inherited value.
|
||||
pub developer_instructions: Option<String>,
|
||||
pub user_instructions: Option<String>,
|
||||
pub thread_instructions: Option<String>,
|
||||
pub cwd: AbsolutePathBuf,
|
||||
|
||||
Reference in New Issue
Block a user