prompt change

This commit is contained in:
Dhanji Prasanna
2025-10-11 15:07:47 +11:00
parent e89e1acf41
commit 658a335615

View File

@@ -24,7 +24,7 @@ use tracing::{debug, error, info, warn};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall { pub struct ToolCall {
pub tool: String, pub tool: String,
pub args: serde_json::Value, // Should be a JSON object with tool-specific arguments pub args: serde_json::Value, // Should be a JSON object with tool-specific arguments
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -176,16 +176,16 @@ impl StreamingToolParser {
// This would indicate a malformed tool call where the message // This would indicate a malformed tool call where the message
// got mixed into the args // got mixed into the args
let has_message_like_key = args_obj.keys().any(|key| { let has_message_like_key = args_obj.keys().any(|key| {
key.len() > 100 || key.len() > 100
key.contains('\n') || || key.contains('\n')
key.contains("I'll") || || key.contains("I'll")
key.contains("Let me") || || key.contains("Let me")
key.contains("Here's") || || key.contains("Here's")
key.contains("I can") || || key.contains("I can")
key.contains("I need") || || key.contains("I need")
key.contains("First") || || key.contains("First")
key.contains("Now") || || key.contains("Now")
key.contains("The ") || key.contains("The ")
}); });
if has_message_like_key { if has_message_like_key {
@@ -199,8 +199,11 @@ impl StreamingToolParser {
// Also check if the values look reasonable // Also check if the values look reasonable
// Tool arguments should typically be file paths, commands, or content // Tool arguments should typically be file paths, commands, or content
// Not entire agent messages // Not entire agent messages
debug!("Successfully parsed valid JSON tool call: {:?}", tool_call); debug!(
"Successfully parsed valid JSON tool call: {:?}",
tool_call
);
// Reset JSON parsing state // Reset JSON parsing state
self.in_json_tool_call = false; self.in_json_tool_call = false;
self.json_tool_start = None; self.json_tool_start = None;
@@ -708,10 +711,9 @@ You have access to tools. When you need to accomplish a task, you MUST use the a
IMPORTANT: You must call tools to achieve goals. When you receive a request: IMPORTANT: You must call tools to achieve goals. When you receive a request:
1. Analyze and identify what needs to be done 1. Analyze and identify what needs to be done
2. Call the appropriate tool with the required parameters 2. Call the appropriate tool with the required parameters
3. Wait for the tool result 3. Continue or complete the task based on the result
4. Continue or complete the task based on the result 4. If you repeatedly try something and it fails, try a different approach
5. If you repeatedly try something and it fails, try a different approach 5. Call the final_output tool with a detailed summary when done.
6. Call the final_output task with a detailed summary when done with all tasks.
For shell commands: Use the shell tool with the exact command needed. Avoid commands that produce a large amount of output, and consider piping those outputs to files. Example: If asked to list files, immediately call the shell tool with command parameter \"ls\". For shell commands: Use the shell tool with the exact command needed. Avoid commands that produce a large amount of output, and consider piping those outputs to files. Example: If asked to list files, immediately call the shell tool with command parameter \"ls\".
If you create temporary files or data for testing, place these in a subdir named 'tmp'. Do NOT pollute the current dir. If you create temporary files or data for testing, place these in a subdir named 'tmp'. Do NOT pollute the current dir.
@@ -1417,7 +1419,7 @@ The tool will execute immediately and you'll receive the result (success or erro
let filtered_content = filter_json_tool_calls(&clean_content); let filtered_content = filter_json_tool_calls(&clean_content);
let final_display_content = filtered_content.trim(); let final_display_content = filtered_content.trim();
// Display any new content before tool execution // Display any new content before tool execution
// We need to skip what was already shown (tracked in current_response) // We need to skip what was already shown (tracked in current_response)
// but also account for the fact that parser.text_buffer accumulates // but also account for the fact that parser.text_buffer accumulates
// across iterations and is never cleared until reset() // across iterations and is never cleared until reset()
@@ -1991,16 +1993,18 @@ The tool will execute immediately and you'll receive the result (success or erro
let start_boundary = if start == 0 { let start_boundary = if start == 0 {
0 0
} else { } else {
content.char_indices() content
.char_indices()
.find(|(i, _)| *i >= start) .find(|(i, _)| *i >= start)
.map(|(i, _)| i) .map(|(i, _)| i)
.unwrap_or(start) .unwrap_or(start)
}; };
let end_boundary = content.char_indices() let end_boundary = content
.char_indices()
.find(|(i, _)| *i >= end) .find(|(i, _)| *i >= end)
.map(|(i, _)| i) .map(|(i, _)| i)
.unwrap_or(content.len()); .unwrap_or(content.len());
let partial_content = &content[start_boundary..end_boundary]; let partial_content = &content[start_boundary..end_boundary];
let line_count = partial_content.lines().count(); let line_count = partial_content.lines().count();
let total_lines = content.lines().count(); let total_lines = content.lines().count();
@@ -2009,7 +2013,11 @@ The tool will execute immediately and you'll receive the result (success or erro
if start_char.is_some() || end_char.is_some() { if start_char.is_some() || end_char.is_some() {
Ok(format!( Ok(format!(
"📄 File content (chars {}-{}, {} lines of {} total):\n{}", "📄 File content (chars {}-{}, {} lines of {} total):\n{}",
start_boundary, end_boundary, line_count, total_lines, partial_content start_boundary,
end_boundary,
line_count,
total_lines,
partial_content
)) ))
} else { } else {
Ok(format!( Ok(format!(
@@ -2621,16 +2629,18 @@ pub fn apply_unified_diff_to_string(
let start_boundary = if search_start == 0 { let start_boundary = if search_start == 0 {
0 0
} else { } else {
content_norm.char_indices() content_norm
.char_indices()
.find(|(i, _)| *i >= search_start) .find(|(i, _)| *i >= search_start)
.map(|(i, _)| i) .map(|(i, _)| i)
.unwrap_or(search_start) .unwrap_or(search_start)
}; };
let end_boundary = content_norm.char_indices() let end_boundary = content_norm
.char_indices()
.find(|(i, _)| *i >= search_end) .find(|(i, _)| *i >= search_end)
.map(|(i, _)| i) .map(|(i, _)| i)
.unwrap_or(content_norm.len()); .unwrap_or(content_norm.len());
let mut region_content = content_norm[start_boundary..end_boundary].to_string(); let mut region_content = content_norm[start_boundary..end_boundary].to_string();
// Apply hunks in order // Apply hunks in order
@@ -2654,7 +2664,10 @@ pub fn apply_unified_diff_to_string(
} }
let range_note = if start_char.is_some() || end_char.is_some() { let range_note = if start_char.is_some() || end_char.is_some() {
format!(" (within character range {}:{})", start_boundary, end_boundary) format!(
" (within character range {}:{})",
start_boundary, end_boundary
)
} else { } else {
String::new() String::new()
}; };