feat: Improved coloring of LLM tool invocation outputs to make LLM output more readable and cohesive
This commit is contained in:
+15
-10
@@ -150,7 +150,9 @@ pub async fn eval_tool_calls(
|
|||||||
let dup_msg = format!("{{\"tool_call_loop_alert\":{}}}", msg.trim());
|
let dup_msg = format!("{{\"tool_call_loop_alert\":{}}}", msg.trim());
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
warning_text(format!("{}: ⚠️ Tool-call loop detected! ⚠️", call.name).as_str())
|
muted_warning_text(
|
||||||
|
format!("{}: ⚠️ Tool-call loop detected! ⚠️", call.name).as_str()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
let val = json!(dup_msg);
|
let val = json!(dup_msg);
|
||||||
output.push(ToolResult::new(call, val));
|
output.push(ToolResult::new(call, val));
|
||||||
@@ -1098,7 +1100,7 @@ impl ToolCall {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
let error_msg = format!("MCP search failed: {e}");
|
let error_msg = format!("MCP search failed: {e}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
eprintln!("{}", muted_warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
||||||
json!({"tool_call_error": error_msg})
|
json!({"tool_call_error": error_msg})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1107,7 +1109,7 @@ impl ToolCall {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
let error_msg = format!("MCP describe failed: {e}");
|
let error_msg = format!("MCP describe failed: {e}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
eprintln!("{}", muted_warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
||||||
json!({"tool_call_error": error_msg})
|
json!({"tool_call_error": error_msg})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1116,21 +1118,21 @@ impl ToolCall {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
let error_msg = format!("MCP tool invocation failed: {e}");
|
let error_msg = format!("MCP tool invocation failed: {e}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
eprintln!("{}", muted_warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
||||||
json!({"tool_call_error": error_msg})
|
json!({"tool_call_error": error_msg})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ if cmd_name.starts_with(TODO_FUNCTION_PREFIX) => {
|
_ if cmd_name.starts_with(TODO_FUNCTION_PREFIX) => {
|
||||||
todo::handle_todo_tool(ctx, &cmd_name, &json_data).unwrap_or_else(|e| {
|
todo::handle_todo_tool(ctx, &cmd_name, &json_data).unwrap_or_else(|e| {
|
||||||
let error_msg = format!("Todo tool failed: {e}");
|
let error_msg = format!("Todo tool failed: {e}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
eprintln!("{}", muted_warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
||||||
json!({"tool_call_error": error_msg})
|
json!({"tool_call_error": error_msg})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ if cmd_name.starts_with(MEMORY_FUNCTION_PREFIX) => {
|
_ if cmd_name.starts_with(MEMORY_FUNCTION_PREFIX) => {
|
||||||
memory::handle_memory_tool(ctx, &cmd_name, &json_data).unwrap_or_else(|e| {
|
memory::handle_memory_tool(ctx, &cmd_name, &json_data).unwrap_or_else(|e| {
|
||||||
let error_msg = format!("Memory tool failed: {e}");
|
let error_msg = format!("Memory tool failed: {e}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
eprintln!("{}", muted_warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
||||||
json!({"tool_call_error": error_msg})
|
json!({"tool_call_error": error_msg})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1139,7 +1141,7 @@ impl ToolCall {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
let error_msg = format!("Skill tool failed: {e}");
|
let error_msg = format!("Skill tool failed: {e}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
eprintln!("{}", muted_warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
||||||
json!({"tool_call_error": error_msg})
|
json!({"tool_call_error": error_msg})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1148,7 +1150,7 @@ impl ToolCall {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
let error_msg = format!("Supervisor tool failed: {e}");
|
let error_msg = format!("Supervisor tool failed: {e}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
eprintln!("{}", muted_warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
||||||
json!({"tool_call_error": error_msg})
|
json!({"tool_call_error": error_msg})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1157,7 +1159,7 @@ impl ToolCall {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
let error_msg = format!("User interaction failed: {e}");
|
let error_msg = format!("User interaction failed: {e}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
eprintln!("{}", muted_warning_text(&format!("⚠️ {error_msg} ⚠️")));
|
||||||
json!({"tool_call_error": error_msg})
|
json!({"tool_call_error": error_msg})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1417,7 +1419,10 @@ pub fn run_llm_function(
|
|||||||
let stderr = String::from_utf8_lossy(&stderr_bytes).trim().to_string();
|
let stderr = String::from_utf8_lossy(&stderr_bytes).trim().to_string();
|
||||||
let stdout = String::from_utf8_lossy(&stdout_bytes).trim().to_string();
|
let stdout = String::from_utf8_lossy(&stdout_bytes).trim().to_string();
|
||||||
let tool_error_message = format!("Tool call '{command_name}' exited with code {exit_code}");
|
let tool_error_message = format!("Tool call '{command_name}' exited with code {exit_code}");
|
||||||
eprintln!("{}", warning_text(&format!("⚠️ {tool_error_message} ⚠️")));
|
eprintln!(
|
||||||
|
"{}",
|
||||||
|
muted_warning_text(&format!("⚠️ {tool_error_message} ⚠️"))
|
||||||
|
);
|
||||||
let mut error_json = json!({"tool_call_error": tool_error_message});
|
let mut error_json = json!({"tool_call_error": tool_error_message});
|
||||||
if !stderr.is_empty() {
|
if !stderr.is_empty() {
|
||||||
error_json["stderr"] = json!(stderr);
|
error_json["stderr"] = json!(stderr);
|
||||||
|
|||||||
+7
-3
@@ -148,6 +148,10 @@ pub fn warning_text(input: &str) -> String {
|
|||||||
color_text(input, nu_ansi_term::Color::Yellow)
|
color_text(input, nu_ansi_term::Color::Yellow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn muted_warning_text(input: &str) -> String {
|
||||||
|
color_text(input, nu_ansi_term::Color::Fixed(136))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn color_text(input: &str, color: nu_ansi_term::Color) -> String {
|
pub fn color_text(input: &str, color: nu_ansi_term::Color) -> String {
|
||||||
if *NO_COLOR {
|
if *NO_COLOR {
|
||||||
return input.to_string();
|
return input.to_string();
|
||||||
@@ -162,7 +166,7 @@ pub fn dimmed_text(input: &str) -> String {
|
|||||||
if *NO_COLOR {
|
if *NO_COLOR {
|
||||||
return input.to_string();
|
return input.to_string();
|
||||||
}
|
}
|
||||||
nu_ansi_term::Style::new().dimmed().paint(input).to_string()
|
nu_ansi_term::Color::Fixed(243).paint(input).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cyan_bold_text(input: &str) -> String {
|
pub fn cyan_bold_text(input: &str) -> String {
|
||||||
@@ -170,14 +174,14 @@ pub fn cyan_bold_text(input: &str) -> String {
|
|||||||
return input.to_string();
|
return input.to_string();
|
||||||
}
|
}
|
||||||
nu_ansi_term::Style::new()
|
nu_ansi_term::Style::new()
|
||||||
.fg(nu_ansi_term::Color::Cyan)
|
.fg(nu_ansi_term::Color::Fixed(73))
|
||||||
.bold()
|
.bold()
|
||||||
.paint(input)
|
.paint(input)
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn magenta_text(input: &str) -> String {
|
pub fn magenta_text(input: &str) -> String {
|
||||||
color_text(input, nu_ansi_term::Color::Magenta)
|
color_text(input, nu_ansi_term::Color::Fixed(133))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn multiline_text(input: &str) -> String {
|
pub fn multiline_text(input: &str) -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user