fix(chat): 修复工具调用状态判断和错误处理

改进工具调用状态的判断逻辑,使用status字段替代tool_call_result
前端增加错误状态显示,包括错误信息展示
后端确保tool_output为空时返回空字符串而非null
This commit is contained in:
Wenjie Zhang 2025-11-15 12:52:21 +08:00
parent 14bcb29d5b
commit 12c7aeb259
4 changed files with 13 additions and 8 deletions

View File

@ -17,7 +17,6 @@
### Bugs
- 部分异常状态下,智能体的模型名称出现重叠[#279](https://github.com/xerrors/Yuxi-Know/issues/279)
- DeepSeek 官方接口适配会出现问题
- 当前版本如果调用结果为空的时候,工具调用状态会一直处于调用状态,尽管调用是成功的
- 目前的知识库的图片存在公开访问风险
### 新增
@ -33,6 +32,7 @@
### 修复
- 修复重排序模型实际未生效的问题
- 修复消息中断后消息消失的问题,并改善异常效果
- 修复当前版本如果调用结果为空的时候,工具调用状态会一直处于调用状态,尽管调用是成功的
## v0.3

View File

@ -863,10 +863,11 @@ async def get_agent_history(
{
"id": str(tc.id),
"name": tc.tool_name,
"function": {"name": tc.tool_name}, # Frontend compatibility
"function": {"name": tc.tool_name},
"args": tc.tool_input or {},
"tool_call_result": {"content": tc.tool_output} if tc.tool_output else None,
"tool_call_result": {"content": (tc.tool_output or "")} if tc.status == "success" else None,
"status": tc.status,
"error_message": tc.error_message,
}
for tc in msg.tool_calls
]

View File

@ -43,14 +43,18 @@
<div v-for="(toolCall, index) in validToolCalls" :key="toolCall.id || index" class="tool-call-container">
<div v-if="toolCall" class="tool-call-display" :class="{ 'is-collapsed': !expandedToolCalls.has(toolCall.id) }">
<div class="tool-header" @click="toggleToolCall(toolCall.id)">
<span v-if="!toolCall.tool_call_result">
<span v-if="toolCall.status === 'success' || toolCall.tool_call_result">
<span><CircleCheckBig size="16" class="tool-loader tool-success" /></span> &nbsp; 工具 <span class="tool-name">{{ getToolNameByToolCall(toolCall) }}</span> 执行完成
</span>
<span v-else-if="toolCall.status === 'error'">
<span><CircleCheckBig size="16" class="tool-loader tool-error" /></span> &nbsp; 工具 <span class="tool-name">{{ getToolNameByToolCall(toolCall) }}</span> 执行失败
<span v-if="toolCall.error_message">{{ toolCall.error_message }}</span>
</span>
<span v-else>
<span><Loader size="16" class="tool-loader rotate tool-loading" /></span> &nbsp;
<span>正在调用工具: </span>
<span class="tool-name">{{ getToolNameByToolCall(toolCall) }}</span>
</span>
<span v-else>
<span><CircleCheckBig size="16" class="tool-loader tool-success" /></span> &nbsp; 工具 <span class="tool-name">{{ getToolNameByToolCall(toolCall) }}</span> 执行完成
</span>
</div>
<div class="tool-content" v-show="expandedToolCalls.has(toolCall.id)">
<div class="tool-params" v-if="toolCall.args || toolCall.function?.arguments">

View File

@ -242,7 +242,7 @@ export class ChatExporter {
const argsSource = toolCall?.args ?? toolCall?.function?.arguments;
const args = this.stringifyToolArgs(argsSource);
const result = this.normalizeToolResult(toolCall?.tool_call_result?.content);
const isFinished = Boolean(toolCall?.tool_call_result);
const isFinished = toolCall?.status === 'success';
const stateClass = isFinished ? 'done' : 'pending';
const stateLabel = isFinished ? '已完成' : '执行中';