improve tool call logging and error messaging
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user