From 71a00056bfb59b6d1114755f9fb17d190f3a9093 Mon Sep 17 00:00:00 2001 From: kvtodev Date: Thu, 9 Jul 2026 20:02:59 +0800 Subject: [PATCH] improve tool call logging and error messaging --- .../crates/module-editor-agent/src/agent/run.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server-rs/crates/module-editor-agent/src/agent/run.rs b/server-rs/crates/module-editor-agent/src/agent/run.rs index 66e86cea7..5b254867c 100644 --- a/server-rs/crates/module-editor-agent/src/agent/run.rs +++ b/server-rs/crates/module-editor-agent/src/agent/run.rs @@ -142,7 +142,7 @@ where }); } - for (batch_idx, tc) in tool_calls.iter().enumerate() { + for (tc_id, tc) in tool_calls.iter().enumerate() { match run_hooks(&agent.hooks, &extra_hooks, tc) { Flow::Stop => { return Err(PromptError::ToolError( @@ -188,19 +188,24 @@ where match hook.after_tool_call(&tc.name, &mut json_output) { Flow::Stop => { return Err(PromptError::ToolError( - "tool call output rejected by hook".to_string(), + "tool call output caused this turn stopped by hook".to_string(), )); } Flow::Skip => { - json_output = Value::Null; + json_output = serde_json::json!({"message":"tool call is ignored by hook"}); break; } Flow::Continue => {} } } + let arg_json = serde_json::to_string(&tc.args) + .map_err(|e| PromptError::InternalError(e.to_string()))?; let output_json = serde_json::to_string(&json_output) .map_err(|e| PromptError::InternalError(e.to_string()))?; - let output_str = format!("[seq:{batch_idx}] {output_json}"); + + let output_str = format!( + "[tool_call:{tc_id}] args: {arg_json} output: {output_json}" + ); let msg = agent.model.tool_result_message(&tc.name, &output_str); memory.push(msg);