Files
group_xinghuo_jinrong/docs/superpowers/specs/2026-09-11-query-interpret-split-design.md
T
zhanghongyu_0626 aea97a243c feat(analyst): Introduce interpret functionality and enhance chat API
- Added `interpret` flag to `AnalystChatRequest` for optional immediate interpretation of queries.
- Implemented new `POST /api/analyst/interpret` endpoint for on-demand data interpretation based on the latest query snapshot.
- Updated `AnalystAgent` to handle interpretation logic, including error handling and response formatting.
- Enhanced `AnalystQueryPage` to include a button for triggering interpretations, improving user interaction.
- Updated frontend API calls to support the new interpret functionality, ensuring seamless integration with existing workflows.

This update significantly enhances the analytical capabilities of the application, allowing users to request interpretations of their queries directly.
2026-09-11 12:15:18 +08:00

2.2 KiB
Raw Blame History

问数查表与「分析该数据」解读拆分(D-09 子集)

日期:2026-09-11 · 状态:已拍板(用户指令)

背景

问数工作台(POST /api/analyst/chat)原先一次返回 SQL + 表格 + LLM 解读。独立「分析对话」(/api/chat/stream + analyst)无 NL2SQL,与问数重复且易误导。

目标

  1. 问数只做 NL2SQL + 校验 + 执行 + 缓存(D-06),默认不自动生成解读。
  2. 各角色在同一问数页上,对最近一次问数结果点 「分析该数据」(客户文案:「解读我的数据」),才触发看图说话(表格 + 原问题 + SQL 摘要 → LLM + D-10 护栏)。
  3. 若问数已是 deny / clarify / error / escalate,不调用解读 API;前端直接展示问数返回的 answer(权限不够等同理)。
  4. 解读上下文仅本轮:question + 问数返回(status/table/sql/meta),不接 Chat 会话历史、不合并分析对话 stub。

非目标

  • 不删除 /app/analytics/chat 菜单(后续可强引导或下线)。
  • 不做 trace_id 服务端复验查数快照(Demo 信任同 token 提交的 snapshot;留痕仍以问数 run 为准)。

API

方法 路径 行为
POST /api/analyst/chat 请求体增 interpret: bool = false;false 时 answer 为空,status=success(有表)或早退 clarify/deny
POST /api/analyst/interpret body:question + 问数四件套快照;终态 status 原样 echo;success/degrade 路径跑解读 + 护栏

鉴权:与问数相同 get_platform_auth_context + assert_analyst_query_access。

前端

  • AnalystQueryPage:postAnalystChat(..., { interpret: false });成功出表后显示按钮;解读区独立 state。
  • 按钮文案按 auth.roleLabel 映射(客户 vs 其他角色)。
  • 顶栏 Alert 改为强调「先问数、再点解读」,不再主推分析对话。

文档

  • MEMORY.md §3 / §0、TODO.md(D-09 部分落地)、REQUIREMENTS D-01 补充一句。

测试

  • test_wave6_analyst_agent.py:query-only、interpret() echo deny、interpret 成功/降级。
  • 全量 pytest;web Vitest 若有 analyst API mock 则补一条(可选)。