fix: stabilize tool error rendering
This commit is contained in:
parent
b39d7cc795
commit
79a90f4fad
@ -1378,6 +1378,13 @@ const appOptions = {
|
||||
|
||||
toolAction.tool.status = 'completed';
|
||||
toolAction.tool.result = result;
|
||||
if (result && typeof result === 'object') {
|
||||
if (result.error) {
|
||||
toolAction.tool.message = result.error;
|
||||
} else if (result.message && !toolAction.tool.message) {
|
||||
toolAction.tool.message = result.message;
|
||||
}
|
||||
}
|
||||
if (message.name === 'append_to_file' && result && result.message) {
|
||||
toolAction.tool.message = result.message;
|
||||
}
|
||||
|
||||
@ -3872,7 +3872,35 @@ async def handle_task_with_sender(terminal: WebTerminal, message, sender, client
|
||||
success, arguments, error_msg = web_terminal.api_client._safe_tool_arguments_parse(arguments_str, function_name)
|
||||
if not success:
|
||||
debug_log(f"安全解析失败: {error_msg}")
|
||||
sender('error', {'message': f'工具参数解析失败: {error_msg}'})
|
||||
error_text = f'工具参数解析失败: {error_msg}'
|
||||
error_payload = {
|
||||
"success": False,
|
||||
"error": error_text,
|
||||
"error_type": "parameter_format_error",
|
||||
"tool_name": function_name,
|
||||
"tool_call_id": tool_call_id,
|
||||
"message": error_text
|
||||
}
|
||||
sender('error', {'message': error_text})
|
||||
sender('update_action', {
|
||||
'preparing_id': tool_call_id,
|
||||
'status': 'completed',
|
||||
'result': error_payload,
|
||||
'message': error_text
|
||||
})
|
||||
error_content = json.dumps(error_payload, ensure_ascii=False)
|
||||
web_terminal.context_manager.add_conversation(
|
||||
"tool",
|
||||
error_content,
|
||||
tool_call_id=tool_call_id,
|
||||
name=function_name
|
||||
)
|
||||
messages.append({
|
||||
"role": "tool",
|
||||
"tool_call_id": tool_call_id,
|
||||
"name": function_name,
|
||||
"content": error_content
|
||||
})
|
||||
continue
|
||||
debug_log(f"使用安全解析成功,参数键: {list(arguments.keys())}")
|
||||
else:
|
||||
@ -3912,7 +3940,35 @@ async def handle_task_with_sender(terminal: WebTerminal, message, sender, client
|
||||
debug_log(f"JSON修复也失败: {repair_error}")
|
||||
debug_log(f"修复尝试: {repair_attempts}")
|
||||
debug_log(f"修复后内容前100字符: {repaired_str[:100]}")
|
||||
sender('error', {'message': f'工具参数解析失败: {e}'})
|
||||
error_text = f'工具参数解析失败: {e}'
|
||||
error_payload = {
|
||||
"success": False,
|
||||
"error": error_text,
|
||||
"error_type": "parameter_format_error",
|
||||
"tool_name": function_name,
|
||||
"tool_call_id": tool_call_id,
|
||||
"message": error_text
|
||||
}
|
||||
sender('error', {'message': error_text})
|
||||
sender('update_action', {
|
||||
'preparing_id': tool_call_id,
|
||||
'status': 'completed',
|
||||
'result': error_payload,
|
||||
'message': error_text
|
||||
})
|
||||
error_content = json.dumps(error_payload, ensure_ascii=False)
|
||||
web_terminal.context_manager.add_conversation(
|
||||
"tool",
|
||||
error_content,
|
||||
tool_call_id=tool_call_id,
|
||||
name=function_name
|
||||
)
|
||||
messages.append({
|
||||
"role": "tool",
|
||||
"tool_call_id": tool_call_id,
|
||||
"name": function_name,
|
||||
"content": error_content
|
||||
})
|
||||
continue
|
||||
|
||||
debug_log(f"执行工具: {function_name} (ID: {tool_call_id})")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user