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>,
) -> AgentMessagesFuture {
Box::pin(async move {
let text_instruction = recipe
.instructions
let system_instructions = recipe.instructions.clone().unwrap_or_default();
let user_task = recipe
.prompt
.clone()
.or(recipe.prompt.clone())
.ok_or_else(|| anyhow!("Recipe has no instructions or prompt"))?;
.unwrap_or_else(|| "Begin.".to_string());
let agent_manager = AgentManager::instance()
.await
@@ -160,7 +160,7 @@ fn get_agent_messages(
.max_turns
.expect("TaskConfig always sets max_turns"),
subagent_id: session_id.clone(),
task_instructions: text_instruction.clone(),
task_instructions: system_instructions,
tool_count: tools.len(),
available_tools: tools
.iter()
@@ -172,7 +172,7 @@ fn get_agent_messages(
.map_err(|e| anyhow!("Failed to render subagent system prompt: {}", e))?;
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()]);
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))?;
// Merge prompt into instructions so the subagent gets the actual task.
// The subagent handler uses `instructions` as the user message.
let mut combined = String::new();
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");
if let Some(extra) = &params.instructions {
let mut current = recipe.instructions.take().unwrap_or_default();
if !current.is_empty() {
current.push_str("\n\n");
}
combined.push_str(prompt);
}
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);
current.push_str(extra);
recipe.instructions = Some(current);
}
Ok(recipe)
@@ -13,8 +13,10 @@ The maximum number of turns to respond is {{max_turns}}.
**Subagent ID**: {{subagent_id}}
{% endif %}
{% if task_instructions %}
# Task Instructions
{{task_instructions}}
{% endif %}
# 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: