Skip to content

WS-4 M2:对话后端关键路径 - #3

Merged
BSTester merged 5 commits into
mainfrom
ws-4-m2-conversation-backend
Jul 6, 2026
Merged

WS-4 M2:对话后端关键路径#3
BSTester merged 5 commits into
mainfrom
ws-4-m2-conversation-backend

Conversation

@BSTester

@BSTester BSTester commented Jul 6, 2026

Copy link
Copy Markdown
Owner

背景

WS-4 Stage 4 M2:对话后端关键路径。基于 ws-4-m1-m4,M2 完成后先暂停等待第二阶段调度前端 M3。

M2 完成范围

  • 会话/消息领域模型:新增 conversation_sessionsconversation_messages SQLAlchemy models。
  • 会话 CRUD:GET/POST/PATCH/DELETE /api/conversations
  • 消息 API:GET /api/conversations/{id}/messagesPOST /api/conversations/{id}/messagesPOST /api/conversations/{id}/messages/{mid}/follow-up
  • 对话编排:消息中识别标的代码,规范化市场/代码,创建 AnalysisRecord 并复用现有后台分析任务。
  • 对话流式 WS:新增 /ws/conversation/{session_id},支持 authstopretry_stagereconnectping;服务端事件使用契约 §5 命名:tokenstage_startstage_updatestage_completestage_warningstage_erroranalysis_completereport_readystop_ackerrorpong
  • 报告组装:新增 report_formatter.py,基于 M1 structured_report 输出契约 §6.1 的报告结构。
  • 报告 API:GET /api/reportsGET /api/reports/{id}GET /api/reports/{id}/export?format=md|json|pdf
  • 分析任务桥接:后台 analysis_task 会同步更新 conversation assistant message,并向 conversation channel 推送 contract events。

非目标

  • M5 后台 IA 与 M6 非功能尚未开始。
  • PDF 真二进制生成留到 M6;当前显式返回 pending JSON fallback,避免假 PDF。
  • 未实现交易、下单、排行榜;未复活 Futu / intraday / Trading Executor。

验证

  • python -m compileall -q web/backend tradingagents
  • report_formatter 纯 Python 检查通过。
  • 删除/下单/排行榜关键字扫描未发现可执行引用。
  • 当前运行时仍未安装 fastapi,FastAPI import/runtime 验证留 QA 环境。

Refs WS-4

Copilot AI added 5 commits July 6, 2026 07:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 6, 2026 10:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 聚焦 WS-4 Stage 4 M2「对话后端关键路径」,在现有分析任务体系上新增对话会话/消息、报告 API 与 Skills 数据采集抽象,同时清理/下线与“日内交易/下单/排行榜/快照”相关的旧路径,以收敛为“只做分析报告、不做自动交易执行”的后端形态。

Changes:

  • 新增对话会话与消息 CRUD(REST),并将对话消息触发的分析桥接到现有 analysis_task 流程。
  • 新增报告列表/详情/导出 API 与 report_formatter,基于 AnalysisRecord.final_state.structured_report 输出契约化结构。
  • 引入内部 Skills registry(market/news/fundamentals/indicators 等)并调整 TradingAgents 工具路由;同时移除 intraday scheduler、snapshot、leaderboard、trading executor 等旧代码路径与字段。

Reviewed changes

Copilot reviewed 66 out of 67 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
web/backend/tests/test_scheduler_recovery.py 删除旧的 intraday scheduler 恢复脚本测试
web/backend/services/user_intraday_scheduler.py 删除多用户 intraday scheduler manager
web/backend/services/user_config_cache.py 精简缓存字段,移除 intraday/Futu 相关配置输出
web/backend/services/task_executor.py 移除任务执行时对 trading executor/Futu 配置的写入与透传
web/backend/services/snapshot_scheduler.py 删除资产快照 scheduler 服务
web/backend/services/skills/registry.py 新增 Skills registry:数据采集能力路由与元数据
web/backend/services/skills/base.py 新增 Skills provider 协议与健康信息 DTO
web/backend/services/skills/init.py 导出 skills registry 入口
web/backend/services/report_formatter.py 新增报告格式化:preview/detail/markdown/json 输出
web/backend/services/prompt_loader.py 默认提示词改为“分析报告 agent”,保留旧函数别名兼容
web/backend/services/intraday_scheduler.py 删除 intraday scheduler 核心实现
web/backend/services/futu_async_wrapper.py 删除 Futu async wrapper(交易相关)
web/backend/schemas.py 移除 intraday/交易执行/排行榜字段与相关 schema
web/backend/routes/user_management_routes.py 移除 intraday 权限字段与更新路由
web/backend/routes/user_leaderboard_routes.py 删除用户排行榜开关路由
web/backend/routes/user_config_routes.py 移除 trading executor/Futu 配置读写
web/backend/routes/skills_routes.py 新增 skills health 路由(鉴权)
web/backend/routes/scheduled_task_routes.py 创建定时任务时移除 trading executor/Futu 字段
web/backend/routes/report_routes.py 新增 reports 列表/详情/导出(md/json/pdf pending)API
web/backend/routes/public_leaderboard_routes.py 删除公开排行榜 API
web/backend/routes/prompt_routes.py 校验提示词时改用动态变量文档生成(不再读 workflow.txt)
web/backend/routes/leaderboard_routes.py 删除 leaderboard API
web/backend/routes/conversation_routes.py 新增 conversations 与 messages API;消息触发分析任务桥接
web/backend/routes/analysis_routes.py 输出语义调整为“只给建议不下单”,移除 execution_report 拼装
web/backend/routes/account_snapshot_routes.py 删除账户快照查询 API
web/backend/routes/init.py 注册新增的 conversation/report/skills routes
web/backend/models.py 新增 ConversationSession/Message;移除 intraday/交易执行/快照/排行榜模型字段与表
web/backend/migrations/add_llm_providers_models.py 默认 provider 信息调整为 OneInfinity OpenAI-compatible
web/backend/migrations/005_update_tool_descriptions_english.py 移除下单工具描述(英)
web/backend/migrations/004_update_tool_descriptions_chinese.py 移除下单工具描述(中)
web/backend/migrations/003_init_default_prompts.py 默认提示词初始化改为 analysis_agent
web/backend/database.py init_db 注册模型集合更新(conversation + llm/prompt/tool)
web/backend/auth_routes.py 删除 require_intraday_access 依赖
web/backend/app.py 应用描述更新;移除 intraday/snapshot/leaderboard 启动与路由挂载;挂载 conversation/report/skills
tradingagents/utils/structured_outputs.py 新增 structured_report 归一化与证据快照工具
tradingagents/utils/security.py 新增安全路径拼接/组件清洗工具
tradingagents/utils/checkpoints.py 新增 checkpoint 读写(safe_join)
tradingagents/utils/init.py 新增 utils 包初始化
tradingagents/graph/trading_graph.py 移除自动交易执行节点;补齐 provider API key 注入;日志路径改为 safe_join
tradingagents/graph/setup.py trading_executor 流程移除,Trader 仅输出建议
tradingagents/graph/propagation.py 初始 state 增加 structured_report/grounded_evidence/stage_log/reflection 等字段
tradingagents/graph/conditional_logic.py 删除 trading_executor conditional logic
tradingagents/default_config.py 引入 TRADINGAGENTS_* 环境变量优先级与多 provider API key 配置
tradingagents/dataflows/interface.py vendor 支持扩展(含 baostock)与市场偏好调整
tradingagents/agents/utils/tool_registry.py 移除 Futu/下单工具注册,收敛为数据采集工具
tradingagents/agents/utils/technical_indicators_tools.py 技术指标工具改走 Skills registry
tradingagents/agents/utils/news_data_tools.py 新闻/舆情工具改走 Skills registry(但 insider* 路由存在语义问题)
tradingagents/agents/utils/fundamental_data_tools.py 基本面工具改走 Skills registry
tradingagents/agents/utils/core_stock_tools.py 行情历史工具改走 Skills registry(look_back_days 适配)
tradingagents/agents/utils/agent_states.py state 增加结构化报告/证据/反思字段,移除 execution_report
tradingagents/agents/trader/trading_executor.py 删除交易执行 agent
tradingagents/agents/trader/trader.py 加入 structured 输出要求与“只建议不下单”约束;注入 previous reflection
tradingagents/agents/trader/intraday_trader_workflow.txt 删除旧 intraday workflow 文档
tradingagents/agents/trader/intraday_trader_default_prompt.txt 删除旧 intraday 默认 prompt 文件
tradingagents/agents/managers/risk_manager.py 生成 structured_report 并写入 state;注入 reflection
tradingagents/agents/managers/research_manager.py 注入 structured 输出块与 reflection
tradingagents/agents/analysts/social_media_analyst.py 增加 grounded evidence 快照输出要求与 state 写入
scripts/init_llm_config.py 默认 provider base_url 与模型列表调整
.gitignore 忽略本地 .env*(保留 .env.example)
.env.local 删除包含本地密钥的环境文件

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +277 to +280
if before_id:
before = await db.get(ConversationMessage, before_id)
if before:
stmt = stmt.where(ConversationMessage.created_at < before.created_at)
Comment on lines +112 to +118
patterns = [
r"\b\d{6}\.(?:SH|SZ)\b",
r"\b\d{4,5}\.HK\b",
r"\b[A-Z]{1,5}\b",
r"\b\d{6}\b",
r"\b\d{4,5}\b",
]
Comment on lines +68 to +71
if date_from:
filters.append(AnalysisRecord.created_at >= datetime.fromisoformat(date_from))
if date_to:
filters.append(AnalysisRecord.created_at <= datetime.fromisoformat(date_to))
Comment on lines +56 to +60
filters = [(AnalysisRecord.user_id == current_user.id) | (AnalysisRecord.is_public == True)]
if ticker:
filters.append(AnalysisRecord.ticker.ilike(f"%{ticker}%"))
if market:
filters.append(AnalysisRecord.market == market)
Comment on lines +79 to +81
structured = _structured(record)
rating = int(structured.get("rating") or 3)
sections = structured.get("sections") if isinstance(structured.get("sections"), dict) else {}
Comment on lines +101 to +103
structured = _structured(record)
rating = int(structured.get("rating") or 3)
reflection = structured.get("reflection") if isinstance(structured.get("reflection"), dict) else {}
str: A report of insider sentiment data
"""
return route_to_vendor("get_insider_sentiment", ticker, curr_date)
return get_skill_registry().execute("social-sentiment", "sentiment", ticker=ticker, start_date=curr_date, end_date=curr_date)
str: A report of insider transaction data
"""
return route_to_vendor("get_insider_transactions", ticker, curr_date)
return get_skill_registry().execute("news", "company", ticker=ticker, start_date=curr_date, end_date=curr_date)
Comment on lines +73 to +78
count_result = await db.execute(select(func.count(AnalysisRecord.id)).where(*filters))
total = count_result.scalar() or 0
sort_column = AnalysisRecord.created_at
order_clause = sort_column.asc() if order == "asc" else desc(sort_column)
result = await db.execute(select(AnalysisRecord).where(*filters).order_by(order_clause).offset((page - 1) * limit).limit(limit))
records = result.scalars().all()
@BSTester
BSTester merged commit 9abe7ec into main Jul 6, 2026
1 check passed
@BSTester
BSTester deleted the ws-4-m2-conversation-backend branch July 7, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants