Split DeveloperInstructions into individual fragments. (#18813)

Split DeveloperInstructions into individual fragments.
This commit is contained in:
pakrym-oai
2026-04-21 10:22:36 -07:00
committed by GitHub
parent 5fe767e8e1
commit 2a226096f6
55 changed files with 1410 additions and 1058 deletions

View File

@@ -5,17 +5,14 @@ use crate::agent::control::render_input_preview;
use crate::agent::next_thread_spawn_depth;
use crate::agent::role::DEFAULT_ROLE_NAME;
use crate::agent::role::apply_role_to_config;
use crate::context::ContextualUserFragment;
use crate::context::SpawnAgentInstructions;
use codex_protocol::AgentPath;
use codex_protocol::models::DeveloperInstructions;
use codex_protocol::protocol::InterAgentCommunication;
use codex_protocol::protocol::Op;
pub(crate) struct Handler;
pub(crate) const SPAWN_AGENT_DEVELOPER_INSTRUCTIONS: &str = r#"<spawned_agent_context>
You are a newly spawned agent in a team of agents collaborating to complete a task. You can spawn sub-agents to handle subtasks, and those sub-agents can spawn their own sub-agents. You are responsible for returning the response to your assigned task in the final channel. When you give your response, the contents of your response in the final channel will be immediately delivered back to your parent agent. The prior conversation history was forked from your parent agent. Treat the next user message as your assigned task, and use the forked history only as background context.
</spawned_agent_context>"#;
impl ToolHandler for Handler {
type Output = SpawnAgentResult;
@@ -91,15 +88,16 @@ impl ToolHandler for Handler {
}
apply_spawn_agent_runtime_overrides(&mut config, turn.as_ref())?;
apply_spawn_agent_overrides(&mut config, child_depth);
let spawn_agent_instructions = SpawnAgentInstructions.render();
config.developer_instructions = Some(
if let Some(existing_instructions) = config.developer_instructions.take() {
DeveloperInstructions::new(existing_instructions)
.concat(DeveloperInstructions::new(
SPAWN_AGENT_DEVELOPER_INSTRUCTIONS,
))
.into_text()
if let Some(mut existing_instructions) = config.developer_instructions.take() {
if !existing_instructions.ends_with('\n') {
existing_instructions.push('\n');
}
existing_instructions.push_str(&spawn_agent_instructions);
existing_instructions
} else {
DeveloperInstructions::new(SPAWN_AGENT_DEVELOPER_INSTRUCTIONS).into_text()
spawn_agent_instructions
},
);