fix: clean up subagent (#3565)
This commit is contained in:
@@ -40,18 +40,8 @@ fn format_task_metadata(task_info: &TaskInfo) -> String {
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
} else if task_info.task.task_type == "text_instruction" {
|
||||
// For text_instruction tasks, extract and display the instruction
|
||||
if let Some(text_instruction) = task_info.task.get_text_instruction() {
|
||||
// Truncate long instructions to keep the display clean
|
||||
if text_instruction.len() > 80 {
|
||||
format!("instruction={}...", &text_instruction[..77])
|
||||
} else {
|
||||
format!("instruction={}", text_instruction)
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
} else if let Some(text_instruction) = task_info.task.get_text_instruction() {
|
||||
format!("instruction={}", text_instruction)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use serde_json::Value;
|
||||
use std::ops::Deref;
|
||||
use std::process::Stdio;
|
||||
use std::sync::Arc;
|
||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||
@@ -89,37 +88,16 @@ async fn handle_text_instruction_task(
|
||||
// Start tracking the task
|
||||
task_execution_tracker.start_task(&task.id).await;
|
||||
|
||||
// Create arguments for the subagent task
|
||||
let task_arguments = serde_json::json!({
|
||||
"text_instruction": text_instruction,
|
||||
// "instructions": "You are a helpful assistant. Execute the given task and provide a clear, concise response.",
|
||||
});
|
||||
|
||||
let result = tokio::select! {
|
||||
result = run_complete_subagent_task(task_arguments, task_config) => result,
|
||||
result = run_complete_subagent_task(text_instruction.to_string(), task_config) => result,
|
||||
_ = cancellation_token.cancelled() => {
|
||||
return Err("Task cancelled".to_string());
|
||||
}
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(contents) => {
|
||||
// Extract the text content from the result
|
||||
let result_text = contents
|
||||
.into_iter()
|
||||
.filter_map(|content| match content.deref() {
|
||||
rmcp::model::RawContent::Text(raw_text_content) => {
|
||||
Some(raw_text_content.text.clone())
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
Ok(serde_json::json!({
|
||||
"result": result_text
|
||||
}))
|
||||
}
|
||||
Ok(result_text) => Ok(serde_json::json!({
|
||||
"result": result_text
|
||||
})),
|
||||
Err(e) => {
|
||||
let error_msg = format!("Subagent execution failed: {}", e);
|
||||
Err(error_msg)
|
||||
|
||||
Reference in New Issue
Block a user