#3865·WeKnora

[Bug]: 快速问答(KnowledgeQA)流式完成事件未返回 usage,智能推理正常返回

Author: manyao123Created Sep 29, 2026Updated Sep 30, 2026
Labelsbugneeds-triage

Affected Component

Backend Service & API

Bug Description

相关组件

Backend Service & API / KnowledgeQA(Quick Answer)流式响应

问题描述

在自建 WeKnora 环境中,快速问答(quick-answer / KnowledgeQA)可以正常生成回答,但 SSE 流结束时的 complete 事件不包含 Token 用量字段,导致前端无法按会话或用户记录 Token 消耗。

同一模型、同一部署中,智能推理(smart-reasoning / Agent)会正常返回顶层 usage 与 data.usage,因此推测问题位于快速问答的 KnowledgeQA 流式事件封装或用量透传环节。

Steps to Reproduce

复现步骤

  1. 新建会话;
  2. 选择内置“快速问答”智能体;
  3. 使用默认模型 qwen3.8-max;
  4. 发送最小问题,例如:请只回复:DONE。
  5. 读取 SSE 流的最终 complete 事件。

Expected Behavior

json
{
  "response_type": "complete",
  "usage": {
    "prompt_tokens": 21203,
    "completion_tokens": 27,
    "total_tokens": 21230
  },
  "data": {
    "usage": {
      "prompt_tokens": 21203,
      "completion_tokens": 27,
      "total_tokens": 21230
    }
  }
}

### Actual Behavior


快速问答回答正常,但最终事件如下:

```json
{
  "id": "25e1b55b-09f6-41cc-8f4b-7e46d74a2046",
  "response_type": "complete",
  "content": "",
  "done": true,
  "data": {
    "total_duration_ms": 0,
    "total_steps": 0
  }


### WeKnora Version

0.8.0

### Deployment Method

Docker Compose

### Operating System

CentOS Linux 7 (Core)

### Relevant Logs

```shell
{"id":"<request-id>","response_type":"agent_query","content":"","done":true,"session_id":"<session-id>","assistant_message_id":"<assistant-message-id>","data":{"assistant_created_at":"2026-09-29T09:53:56.052229441Z","assistant_message_id":"<assistant-message-id>","session_id":"<session-id>","user_created_at":"2026-09-29T09:53:56.050348733Z","user_message_id":"<user-message-id>"}}

{"id":"<request-id>","response_type":"tool_call","content":"Calling tool: query_understand","done":false,"data":{"arguments":{"query":"请只回答:TRACE_OK。"},"tool_call_id":"<tool-id>","tool_name":"query_understand"}}

{"id":"<request-id>","response_type":"session_title","content":"特定回复指令测试","done":true,"data":{"session_id":"<session-id>","title":"特定回复指令测试"}}

{"id":"<request-id>","response_type":"tool_result","content":"","done":false,"data":{"duration_ms":1112,"error":"","output":"已完成问题理解","success":true,"tool_call_id":"<tool-id>","tool_name":"query_understand"}}

{"id":"<request-id>","response_type":"tool_call","content":"Calling tool: knowledge_search","done":false,"data":{"arguments":{"query":"请只回答TRACE_OK","search_source":"mixed"},"tool_call_id":"<tool-id>","tool_name":"knowledge_search"}}

{"id":"<request-id>","response_type":"tool_result","content":"","done":false,"data":{"candidate_count":0,"count":0,"doc_count":0,"duration_ms":0,"error":"","output":"未检索到相关内容","search_source":"mixed","success":true,"tool_call_id":"<tool-id>","tool_name":"knowledge_search","web_count":0}}

{"id":"<request-id>","response_type":"thinking","content":"The","done":false,"data":{"event_id":"<thinking-id>"}}
{"id":"<request-id>","response_type":"thinking","content":" user is asking me","done":false,"data":{"event_id":"<thinking-id>"}}
{"id":"<request-id>","response_type":"thinking","content":" to respond with only","done":false,"data":{"event_id":"<thinking-id>"}}
{"id":"<request-id>","response_type":"thinking","content":" \"TRACE_OK\".","done":false,"data":{"event_id":"<thinking-id>"}}
{"id":"<request-id>","response_type":"thinking","content":" This appears to be a simple instruction to output a specific string. Let me comply with this request.","done":false,"data":{"event_id":"<thinking-id>"}}
{"id":"<request-id>","response_type":"thinking","content":"","done":true,"data":{"completed_at":1790675638,"duration_ms":764,"event_id":"<thinking-id>"}}

{"id":"<request-id>","response_type":"answer","content":"TRACE_OK","done":false,"data":{"event_id":"<answer-id>"}}
{"id":"<request-id>","response_type":"answer","content":"","done":true,"data":{"completed_at":1790675638,"duration_ms":32,"event_id":"<answer-id>"}}

{"id":"<request-id>","response_type":"complete","content":"","done":true,"data":{"total_duration_ms":0,"total_steps":0}}

Confirmation

  • I have searched existing issues and confirmed this is a new one