fix: use instructions for system prompt and prompt for user message in subagents (#6121)

This commit is contained in:
tlongwell-block
2025-12-16 14:53:06 -05:00
committed by GitHub
parent bd00ca2db0
commit 6d33cbc078
3 changed files with 14 additions and 30 deletions
+6 -6
View File
@@ -117,11 +117,11 @@ fn get_agent_messages(
cancellation_token: Option<CancellationToken>, cancellation_token: Option<CancellationToken>,
) -> AgentMessagesFuture { ) -> AgentMessagesFuture {
Box::pin(async move { Box::pin(async move {
let text_instruction = recipe let system_instructions = recipe.instructions.clone().unwrap_or_default();
.instructions let user_task = recipe
.prompt
.clone() .clone()
.or(recipe.prompt.clone()) .unwrap_or_else(|| "Begin.".to_string());
.ok_or_else(|| anyhow!("Recipe has no instructions or prompt"))?;
let agent_manager = AgentManager::instance() let agent_manager = AgentManager::instance()
.await .await
@@ -160,7 +160,7 @@ fn get_agent_messages(
.max_turns .max_turns
.expect("TaskConfig always sets max_turns"), .expect("TaskConfig always sets max_turns"),
subagent_id: session_id.clone(), subagent_id: session_id.clone(),
task_instructions: text_instruction.clone(), task_instructions: system_instructions,
tool_count: tools.len(), tool_count: tools.len(),
available_tools: tools available_tools: tools
.iter() .iter()
@@ -172,7 +172,7 @@ fn get_agent_messages(
.map_err(|e| anyhow!("Failed to render subagent system prompt: {}", e))?; .map_err(|e| anyhow!("Failed to render subagent system prompt: {}", e))?;
agent.override_system_prompt(subagent_prompt).await; agent.override_system_prompt(subagent_prompt).await;
let user_message = Message::user().with_text(text_instruction); let user_message = Message::user().with_text(user_task);
let mut conversation = Conversation::new_unvalidated(vec![user_message.clone()]); let mut conversation = Conversation::new_unvalidated(vec![user_message.clone()]);
if let Some(activities) = recipe.activities { if let Some(activities) = recipe.activities {
+6 -24
View File
@@ -347,31 +347,13 @@ fn build_subrecipe(
) )
.map_err(|e| anyhow!("Failed to build subrecipe: {}", e))?; .map_err(|e| anyhow!("Failed to build subrecipe: {}", e))?;
// Merge prompt into instructions so the subagent gets the actual task. if let Some(extra) = &params.instructions {
// The subagent handler uses `instructions` as the user message. let mut current = recipe.instructions.take().unwrap_or_default();
let mut combined = String::new(); if !current.is_empty() {
current.push_str("\n\n");
if let Some(instructions) = &recipe.instructions {
combined.push_str(instructions);
}
if let Some(prompt) = &recipe.prompt {
if !combined.is_empty() {
combined.push_str("\n\n");
} }
combined.push_str(prompt); current.push_str(extra);
} recipe.instructions = Some(current);
if let Some(extra_instructions) = &params.instructions {
if !combined.is_empty() {
combined.push_str("\n\n");
}
combined.push_str("Additional context from parent agent:\n");
combined.push_str(extra_instructions);
}
if !combined.is_empty() {
recipe.instructions = Some(combined);
} }
Ok(recipe) Ok(recipe)
@@ -13,8 +13,10 @@ The maximum number of turns to respond is {{max_turns}}.
**Subagent ID**: {{subagent_id}} **Subagent ID**: {{subagent_id}}
{% endif %} {% endif %}
{% if task_instructions %}
# Task Instructions # Task Instructions
{{task_instructions}} {{task_instructions}}
{% endif %}
# Tool Usage Guidelines # Tool Usage Guidelines
**CRITICAL**: Be efficient with tool usage. Use tools only when absolutely necessary to complete your task. Here are the available tools you have access to: **CRITICAL**: Be efficient with tool usage. Use tools only when absolutely necessary to complete your task. Here are the available tools you have access to: