Skip to content

WS-4 M5/M6:后台 IA 后端与非功能加固 - #4

Merged
BSTester merged 6 commits into
mainfrom
ws-4-m5-m6-backend-hardening
Jul 6, 2026
Merged

WS-4 M5/M6:后台 IA 后端与非功能加固#4
BSTester merged 6 commits into
mainfrom
ws-4-m5-m6-backend-hardening

Conversation

@BSTester

@BSTester BSTester commented Jul 6, 2026

Copy link
Copy Markdown
Owner

背景

WS-4 Stage 4 M5/M6:后台 IA 后端与非功能后端收尾。基于 ws-4-m2-conversation-backend

M5 后台 IA 后端

  • /api/scheduled-tasks 重做为契约 §7 响应结构:data/meta 包裹、last_reportnext_run/last_runstatus=enabled|disabled|allticker 过滤。
  • 新增 GET /api/scheduled-tasks/stats,返回 StatsBar 所需 running/paused/scheduled_today/failed
  • scheduled task create/update 支持契约字段默认值(OneInfinity + gpt-5.5)与 daily/weekly/monthly/interval 输入,内部兼容现有 scheduler。
  • /api/reports/public + /api/home/public-reports 作为首页公开报告数据源,替代排行榜/交易数据源。
  • 旧页面 /intraday-trading/leaderboard 308 重定向到 /;旧 API 路由保持 404(未复活)。
  • /api/config 改为公开配置端点,支持未登录引导。

M6 非功能后端

  • LoggingMiddleware 增加 X-Request-IDX-Process-Time,并输出 request id 日志。
  • 未捕获异常/HTTPException 统一为结构化 zh-CN 错误包:{ error: { code, message, request_id } }
  • WS 命名沿用 M2 契约 §5 事件名,没有引入 message.delta 等非契约名称。
  • 安全回归:删除/下单/排行榜关键字扫描无可执行引用;旧交易页面只重定向,不提供功能。

验证

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

Refs WS-4

Copilot AI added 6 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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 6, 2026 11:12

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 以“后台 IA 后端收尾 + 非功能加固”为目标,将系统从“可下单/排行榜/日内交易”形态收敛为“对话式入口 + 结构化分析报告”,并补齐 request-id/结构化错误包等运行期治理能力,同时引入 Skills 注册表以统一数据采集路由。

Changes:

  • 移除日内交易/下单/排行榜/账户快照等交易执行与排名相关后端能力,保留页面层 308 重定向与安全回归(无可执行引用)。
  • 新增对话会话 API、报告列表/详情/导出与首页公开报告数据源,并提供 report_formatter 将分析结果对齐契约结构。
  • 增加 Skills registry + 健康检查路由,完善 LoggingMiddleware(X-Request-ID / X-Process-Time)与默认配置/Prompt 的“只输出建议,不执行交易”定位。

Reviewed changes

Copilot reviewed 70 out of 71 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
web/backend/tests/test_scheduler_recovery.py 删除与 intraday scheduler 恢复相关的脚本式测试。
web/backend/services/user_intraday_scheduler.py 删除多用户日内 scheduler 管理器实现。
web/backend/services/user_config_cache.py 精简缓存字段,移除 intraday/交易执行相关配置缓存。
web/backend/services/task_executor.py 移除 scheduled task 执行时写入/传递交易执行与 Futu 配置字段。
web/backend/services/snapshot_scheduler.py 删除账户快照定时器服务。
web/backend/services/skills/registry.py 新增 Skills 注册表,集中定义数据采集能力与 vendor 路由。
web/backend/services/skills/base.py 新增 Skills provider 协议与 RoutedSkillProvider 执行/健康 DTO。
web/backend/services/skills/init.py 导出 skills registry 访问入口。
web/backend/services/report_formatter.py 新增 report contract 格式化工具(preview/detail/markdown/json)。
web/backend/services/prompt_loader.py 默认 Prompt 收敛为“分析报告 Agent”,并保留旧函数名作为兼容别名。
web/backend/services/futu_async_wrapper.py 删除 Futu 同步调用的 async wrapper。
web/backend/schemas.py 更新请求/任务 schema:默认值、移除交易执行字段、扩展 execution_cycle/update 字段。
web/backend/routes/user_management_routes.py 管理端用户返回字段收敛(移除 intraday 权限字段),移除对应 PATCH 路由。
web/backend/routes/user_leaderboard_routes.py 删除用户排行榜开关路由。
web/backend/routes/user_config_routes.py 用户配置路由移除交易执行/Futu 配置字段读写。
web/backend/routes/skills_routes.py 新增 /api/skills/health 路由用于技能健康/元数据。
web/backend/routes/report_routes.py 新增报告列表/公开流/详情/导出 API。
web/backend/routes/public_leaderboard_routes.py 删除公开排行榜 API。
web/backend/routes/prompt_routes.py Prompt 校验改用变量文档生成器,移除读取 workflow 文件。
web/backend/routes/page_routes.py 退役旧交易/排行榜页面,308 重定向到 /
web/backend/routes/leaderboard_routes.py 删除旧排行榜 API。
web/backend/routes/home_routes.py 新增首页公开报告 feed API(替代 legacy 排名数据源)。
web/backend/routes/conversation_routes.py 新增对话会话/消息 API,并在消息创建时触发分析任务入队。
web/backend/routes/config_routes.py /api/config 改为公开端点(不再依赖登录)。
web/backend/routes/analysis_routes.py 移除交易执行字段传递与“执行交易员”输出;保留建议输出。
web/backend/routes/account_snapshot_routes.py 删除账户快照相关 API。
web/backend/routes/init.py 汇总导出新增 routes(skills/conversation/report/home)。
web/backend/models.py 移除 intraday/排行榜/快照等模型字段与表;新增 ConversationSession/ConversationMessage。
web/backend/migrations/add_llm_providers_models.py 更新默认 provider/base_url 与默认模型条目。
web/backend/migrations/005_update_tool_descriptions_english.py 移除 place order 工具描述条目。
web/backend/migrations/004_update_tool_descriptions_chinese.py 移除下单工具描述条目。
web/backend/migrations/003_init_default_prompts.py 默认模板迁移改用 analysis_agent 与新默认 prompt。
web/backend/middleware.py LoggingMiddleware 增加 request-id、process-time 头与结构化错误包。
web/backend/database.py init_db 导入模型集合更新(加入会话/消息与 LLM/tool 模型)。
web/backend/auth_routes.py 移除 require_intraday_access 依赖。
web/backend/app.py 移除 intraday/snapshot/leaderboard 后台任务初始化;挂载 conversation/report/home/skills 路由。
tradingagents/utils/structured_outputs.py 新增 structured_report 构建与评级/推荐解析辅助。
tradingagents/utils/security.py 新增路径组件净化与 safe_join 防目录穿越。
tradingagents/utils/checkpoints.py 新增长流程 checkpoint 读写(JSON)。
tradingagents/utils/init.py 新增 utils 包声明。
tradingagents/graph/trading_graph.py LLM 初始化补齐 api_key;移除自动交易执行;日志输出改用 safe_join。
tradingagents/graph/setup.py 工作流移除 Trading Executor 节点,仅输出建议后结束。
tradingagents/graph/propagation.py 初始 state 增加 grounded_evidence/structured_report/reflection 等字段。
tradingagents/graph/conditional_logic.py 删除 trading_executor 的 conditional logic 分支。
tradingagents/default_config.py 统一 TRADINGAGENTS_* 环境变量读取与 provider key 注入。
tradingagents/dataflows/interface.py 增加 baostock vendor 支持与 market vendor 优先级调整。
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。
tradingagents/agents/utils/fundamental_data_tools.py 基本面工具改走 Skills registry。
tradingagents/agents/utils/core_stock_tools.py 行情工具改走 Skills registry。
tradingagents/agents/utils/agent_states.py AgentState 增加 structured report / evidence / reflection 字段。
tradingagents/agents/trader/trading_executor.py 删除交易执行 agent。
tradingagents/agents/trader/trader.py Trader prompt 增加 structured 输出要求并明确不下单。
tradingagents/agents/trader/intraday_trader_workflow.txt 删除日内交易强制工作流文档。
tradingagents/agents/trader/intraday_trader_default_prompt.txt 删除日内交易默认提示词文件。
tradingagents/agents/managers/risk_manager.py 风控输出构建 structured_report,并注入 reflection 字段。
tradingagents/agents/managers/research_manager.py 研究经理输出增加 structured block 与 reflection 写入。
tradingagents/agents/analysts/social_media_analyst.py 增加“数据快照”要求,并输出 grounded_evidence。
scripts/init_llm_config.py 初始化脚本更新 provider/base_url 与默认模型配置。
.gitignore 忽略 .env.*(保留 .env.example)以降低误提交风险。
.env.local 删除包含敏感信息的本地环境文件。
Comments suppressed due to low confidence (1)

tradingagents/agents/utils/news_data_tools.py:72

  • get_insider_transactions 当前调用的是 news/company,会返回公司新闻而不是 insider transaction 数据;这会让上层分析误用数据类型。建议改为调用专用的 transactions action(或直接路由到 get_insider_transactions)。
    Returns:
        str: A report of insider transaction data
    """
    return get_skill_registry().execute("news", "company", ticker=ticker, start_date=curr_date, end_date=curr_date)


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

Comment on lines +73 to +85
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()

items = []
for record in records:
preview = report_preview(record, await _source_session_id(db, record.analysis_id))
if rating and preview.get("rating") != rating:
continue
items.append(preview)
Comment thread web/backend/schemas.py
Comment on lines 326 to 330
@validator('interval_days')
def validate_interval_days(cls, v, values):
if values.get('execution_cycle') == 'every_n_days':
if values.get('execution_cycle') in ('every_n_days', 'interval'):
if not v or v < 1 or v > 365:
raise ValueError('interval_days must be between 1 and 365 when execution_cycle is every_n_days')
Comment on lines +108 to +126
"social-sentiment": RoutedSkillProvider(
name="social-sentiment",
display_name="社交舆情",
description="社交帖子、情绪分析,并要求结论锚定数据快照",
input_schema=_schema(["ticker", "start_date", "end_date"], {
"ticker": {"type": "string"},
"start_date": {"type": "string", "format": "date"},
"end_date": {"type": "string", "format": "date"},
}),
providers=["akshare", "baostock", "alpha_vantage", "google"],
primary_source="akshare",
fallback_source="alpha_vantage",
markets=["US", "HK", "CN"],
actions={
"sentiment": lambda ticker, start_date, end_date, **_: _route_to_vendor(
"get_news", ticker, start_date, end_date
),
},
),
Comment on lines +60 to +65
"grounded_evidence": evidence_snapshot(
ticker=ticker,
as_of=current_date,
report=report,
sources=["get_news", "social-sentiment"],
) if report else state.get("grounded_evidence", []),
Comment on lines 1 to 5
from langchain_core.tools import tool
from typing import Annotated
from tradingagents.dataflows.interface import route_to_vendor
from datetime import datetime
from web.backend.services.skills import get_skill_registry

Comment on lines 1 to +3
from langchain_core.tools import tool
from typing import Annotated
from tradingagents.dataflows.interface import route_to_vendor
from web.backend.services.skills import get_skill_registry
Comment on lines 1 to +3
from langchain_core.tools import tool
from typing import Annotated
from tradingagents.dataflows.interface import route_to_vendor
from web.backend.services.skills import get_skill_registry
Comment on lines 1 to +3
from langchain_core.tools import tool
from typing import Annotated
from tradingagents.dataflows.interface import route_to_vendor
from web.backend.services.skills import get_skill_registry
@BSTester
BSTester merged commit bea1f5c into main Jul 6, 2026
1 check passed
@BSTester
BSTester deleted the ws-4-m5-m6-backend-hardening 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