22 Commits

Author SHA1 Message Date
Elvis Wang
972c314656 feat: Web/API 指数入口与共享 canonical 去重基础 (#2312)
* feat: Web/API 指数入口与共享 canonical 去重基础

为 Issue #2303 Phase 2 PR1 落地 Web/API 指数入口适配:

- API 使用 parse_analysis_target 构造结构化 AnalysisTarget 并贯通到 pipeline
- API 与 TaskQueue 去重按 asset_type 分支(指数用 canonical_id,个股用 legacy code)
- BatchTaskAcceptedResponse 追加可选 rejected 字段,未登记 CSI 单股 400、批量仅该目标失败
- TaskInfo 固化 dedupe_key,避免指数与同码个股折叠及 _analyzing_stocks 残留
- Web 移除 assetType=index 全局过滤,Chat 名称识别保护指数 canonical
- 补齐 Pipeline 指数 DecisionSignal market_override=cn 真实分支测试

* fix: 收敛指数 canonical 身份与批量响应契约

PR #2312 review 修复:报告 meta 补充 asset_type 隐藏指数自选;/analyze 在解析前限制非空原始 token;is_single 统一驱动 metadata/409/单任务 202;HomePage 三元计数继续后续 chunk。

* fix: avoid double space in index news search query

* fix: preserve canonical index identity

* fix: validate legacy task asset type

* fix: preserve canonical index identity in chat

* fix: preserve index identity across chat backends
2026-09-01 19:25:15 +08:00
Alfred
628c5b6ef7 feat: add Codex App Server agent prototype (#2004) 2026-07-19 16:31:54 +08:00
Alfred
4c678850e2 feat: add Claude Code and OpenCode generation backends (#1850)
Co-authored-by: zhulinsen <42829555+ZhuLinsen@users.noreply.github.com>
2026-06-30 22:33:02 +08:00
Alfred
4fa81a421c feat: add legacy LLM usage telemetry (#1698) 2026-06-17 18:46:01 +08:00
mumu
0db0c78da8 feat: 个股分析接入当日大盘上下文 (#1623)
* feat: add daily market context for stock analysis

* fix(review-feedback-1623): Share the market context service across worker threads and Use the

* fix(review-feedback-1623): Avoid overwriting per-region context reports and Expand history lookup

* fix(review-feedback-1623): add position even though the guardrail supposedly softened the

* fix(review-feedback-1623): Avoid generating the CLI market review twice

* fix(review-feedback-1623): 修正

* fix(review-feedback-1623): 修复普通 CLI/调度运行中大盘复盘被上下文预热摘要替代的问题,并收敛 PR 描述与当前实现范围

* fix(review-feedback-1623): 修正保守护栏的误判风险,并同步收敛 PR 描述范围

* fix(review-feedback-1623): 处理并发生成大盘上下文的锁语义风险,并澄清/补充外部模型或运行时配置风险检测的依据

* fix(review-feedback-1623): 收敛大盘上下文预热对用户可见大盘复盘的行为影响,并补齐外部模型/API 与运行时配置检测风险的澄清或验证证据

* fix(review-feedback-1623): Do not skip multi-market reviews after one cached context and Do not

* fix(review-feedback-1623): Prime context with the effective trading date

* fix(review-feedback-1623): 收敛 PR 描述与实际 diff 的范围不一致,并澄清结构化检测提示的 provider/model/base

* fix(review-feedback-1623): 补一句“本 PR 不修改 LLM provider/model/base url、默认模型、配置清理或迁移逻辑”,避免后续审查继续误判

* fix(review-feedback-1623): 收敛 PR 描述与实际 diff 的范围矛盾

* fix(review-feedback-1623): 补齐这些承诺的实现

* fix(review-feedback-1623): 收敛 PR 描述与实际 diff 范围,避免以未实现能力作为验收项

* fix(review-feedback-1623): 收敛 PR 描述与实际范围,并澄清外部模型/API 与运行时配置检测风险

* fix(review-feedback-1623): Match freshly saved reviews to the target trade date

* fix(review-feedback-1623): preserve structured market-light risk signals

* fix(review-feedback-1623): Escape market-summary sentinels before prompting

* fix(review-feedback-1623): 修复同日缓存复用时把低敏摘要当完整大盘复盘输出的行为风险,并收敛 PR 描述与实际 diff

* fix(review-feedback-1623): 收敛

* fix(review-feedback-1623): 收敛 PR 描述与实际 scope

* fix(review-feedback-1623): 修正大盘复盘复用语义,并让 PR 描述与实际 scope 对齐

* fix(review-feedback-1623): 修正同日大盘上下文缓存复用语义,并让 PR 描述与实际 scope 对齐

* fix(review-feedback-1623): Disable cached market context when skipping market review

* fix(review-feedback-1623): 收敛 PR 描述与实际 scope,并补充外部模型/API 与运行时配置语义未变化的可核验证据

* fix(review-feedback-1623): 修正 PR 描述与实际 scope 的实质性不一致,并补齐或澄清 LLM/provider/model/base URL

* fix(review-feedback-1623): 修正 operation advice 契约漂移,并让 PR 描述/验收范围与当前实际 diff 对齐

* fix(review-feedback-1623): 收敛 main.py 中大盘复盘复用导致的通知/执行语义变化,并补对应回归测试

* fix(review-feedback-1623): 修复生成型大盘上下文未绑定当前 query id 的行为风险,并收敛 PR body 与实际 diff 范围

* fix(review-feedback-1623): 修复缓存语言匹配问题,并收敛 PR 描述与实际 diff/验收范围的一致性

* fix(review-feedback-1623): 收敛当前实现与描述/文档中的验收边界,并澄清 schedule/CLI 首次运行无历史大盘复盘时是否应生成并注入上下文

* fix(review-feedback-1623): 收敛 PR 描述与 docs/CHANGELOG.md 中关于验收边界的表述,避免与实际 diff 实质性矛盾

* fix(review-feedback-1623): 修正 PR 描述与实际 diff 的范围漂移

* fix(review-feedback-1623): Reuse the cached runtime market context on fallback

* fix(review-feedback-1623): PR 描述:当前完整改动文件列表没有 api/ 、apps/dsa-web/ 、日报状态表或四阶段日报持久化相关实现,但 PR

* fix(review-feedback-1623): 收敛描述范围

* fix(review-feedback-1623): 收敛并发生成复用路径的正确性风险,并修正 PR 描述的实际范围与验收项

* fix(review-feedback-1623): 收敛描述和验收范围

* fix(review-feedback-1623): PR 描述的 Background / Acceptance Criteria 仍包含独立 API、Web

* fix(review-feedback-1623): 收敛 PR 描述与实际实现边界,并补齐 LLM/provider/base url 相关兼容性说明或验证证据

* fix(review-feedback-1623): PR 描述与实际 diff 范围不一致:描述和验收项仍写有独立 API、Web

* fix(review-feedback-1623): Wait long enough for in-flight market reviews

* fix(review-feedback-1623): 修复共享 market review lock 释放后仍不生成匹配上下文的行为风险,并同步收敛 PR description 的实际范围

* fix(review-feedback-1623): 修复锁竞争 fallback 下丢失运行时服务的问题,并同步收敛 PR description 与实际 diff 范围

* fix(review-feedback-1623): 收敛 PR description 与实际改动范围

* fix(review-feedback-1623): PR 描述与实际 diff 存在实质性矛盾:描述声称提供独立 API、Web

* fix(review-feedback-1623): reuse runtime market context and handle English negations

* fix: honor daily market context config

* docs: remove unrelated changelog entries

* fix(review-feedback-1623): preserve the skipped market-review artifact

* fix(review-feedback-1623): add low position cap and are not in CONSERVATIVE TEXT MARKERS , so an
2026-06-13 10:33:04 +08:00
Alfred
da274f7061 fix: 锁定问股追问的当前标的上下文 P2 (#1619)
* fix: keep ask-stock follow-ups scoped

* fix: normalize watchlist stock comparisons

* docs: document watchlist stock code equivalence

* fix: tighten ask-stock tool scope guard

* fix: close ask-stock review gaps

* fix: close ask-stock review gaps
2026-06-10 22:45:58 +08:00
Alfred
3ea007ceb1 feat: 盘中决策护栏与 phase_decision 质量校验 P5 (#1563)
* feat: add phase decision guardrails

* fix: neutralize non-intraday immediate actions

* test: cover low-confidence non-intraday actions
2026-06-02 23:19:10 +08:00
Alfred
3e98dfd9bc feat: add analysis context data quality scoring (#1539) 2026-05-31 23:10:30 +08:00
Alfred
8aa214acc2 feat: 接入 AnalysisContextPack 低敏 Prompt 摘要 P3 (#1491)
* feat: inject AnalysisContextPack prompt summary

* fix: align agent pack summary with prefetched news
2026-05-28 19:04:17 +08:00
Alfred
0bb515cc5e fix: 问股 single-agent 增加 provider-aware trace (#1473)
* fix: add provider-aware trace for ask chat

* fix: drop mismatched provider trace attempts
2026-05-26 19:13:05 +08:00
Alfred
3aa26ba7d8 feat: add visible chat context compression (#1460)
Co-authored-by: mumu <42829555+ZhuLinsen@users.noreply.github.com>
2026-05-25 20:31:20 +08:00
Alfred
79b284014d feat: inject market phase prompt context (#1442) 2026-05-25 20:27:24 +08:00
Alfred
a3c627c384 feat: add runtime market phase context plumbing (#1434)
Co-authored-by: mumu <42829555+ZhuLinsen@users.noreply.github.com>
2026-05-24 15:00:53 +08:00
mumu
205795a325 feat: add LLM provider setup templates and presets (#1175)
* feat(issue-1172): dsa-后续开发规划:配置、通知告警、复盘红绿灯、bot-交互与-agent-增

* fix: address review feedback for MiniMax preset and agent timeout test

- Update MiniMax preset to official OpenAI-compatible base URL (api.minimaxi.com/v1)
  and current model examples (MiniMax-M2.7), with official source links in
  .env.example and docs/llm-providers.md.
- Add provenance + LiteLLM compatibility notes and rollback guidance in
  docs/llm-providers.md.
- Fix flaky test_llm_call_receives_remaining_timeout_budget by patching
  src.agent.runner.time.time so the remaining timeout budget is deterministic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(review-feedback-1175): address latest review comments

* Update LLM provider defaults

* Fix agent model fallback test
2026-05-02 22:19:42 +08:00
mumu
260fe06f08 fix: 最小化修复问股链路在 macOS 本地环境下的失败反馈:优先保留后端真实错误原因并补足… (#1138) (#1139)
* fix(issue-1138): [bug]-macos-26操作系统环境下,搭建完成后,问股页面反馈“问股执行失败
2026-04-28 22:02:55 +08:00
mumu
de5c5376a2 fix: add minimum time budget guard for agent stages and steps (#1003)
* fix: add minimum budget guard to prevent wasted LLM calls near timeout

When earlier pipeline stages consume most of the timeout budget, later
stages and ReAct loop steps start with insufficient time, virtually
guaranteeing a mid-call timeout that still bills a full LLM request.

Changes:
- Runner: skip step when remaining budget < 8s (step > 0 only)
- Orchestrator: skip stage when remaining budget < 15s (index > 0 only)
- First step/stage always runs regardless of budget size, so small
  overall timeouts still work for simple pipelines and tests
2026-04-05 10:21:12 +08:00
mumu
929521aefc fix: complete trading philosophy injection across analyzer paths (#810)
* fix: complete trading philosophy injection across analyzer paths

* fix: preserve legacy prompts for default bull trend

* fix: tighten legacy prompt fallback rules

* fix: scope legacy prompt fallback to builtin bull trend

* fix: align notify flow with async analysis contract

* fix: expose notify controls to home dashboard hook
2026-03-23 23:17:14 +08:00
mumu
9bca31304c fix: harden agent runtime and config handling (#776)
* fix: harden agent runtime and config handling

* fix: restore cors test import and update review status

* fix: close remaining agent timeout gaps

* fix: align agent timeout defaults and fallback budget
2026-03-19 22:25:03 +08:00
mumu
56772ec38e fix: 修复港股代码全链路支持 (Fixes #629, Fixes #691) (#694)
* fix: 修复港股代码全链路支持,避免误走 A 股路径 (Fixes #629, Fixes #691)

- validation.ts: 新增 /^HK\d{5}$/ 港股前缀格式校验,修复 Web 端 HK01810 被拒问题
- base.py: normalize_stock_code 支持 1810.HK / hk1810 归一为 HK01810;
         _is_hk_market 精确匹配 HK+纯数字,防止误匹配;
         DataFetcherManager.get_realtime_quote 新增港股专用快速路径,
         直接调用 akshare_hk,不再按 A 股 source_priority 多次尝试
- tushare_fetcher.py: 四处方法(_convert_stock_code / _fetch_raw_data /
  get_realtime_quote / get_stock_name)增加 HK 早退,避免港股误走深市
- baostock_fetcher.py: 两处方法增加 HK 早退,防止生成 sz.HK01810 等无效请求
- pytdx_fetcher.py: 两处方法增加 HK 早退,规避 36 秒连接超时
- akshare_fetcher.py: get_chip_distribution 增加 HK 早退(stock_cyq_em 仅支持 A 股)
- data_tools.py: DataFetcherManager 改为 singleton,避免每次工具调用重置熔断器;
                 get_realtime_quote 失败时返回 retriable=false,阻止 LLM 重试
- runner.py: 新增工具调用非兼容缓存(non_retriable_tool_results),
             HK 代码不同写法(HK01810 / 1810.HK)共享同一缓存 key
- tests: 新增 test_hk_realtime_routing.py;补充 test_stock_code_bse / test_agent_executor

* fix: reset agent fetcher singleton on config reload

* fix: align web hk validation with backend formats
2026-03-16 00:24:54 +08:00
mumu
d1ec2c8b5f feat: multi-agent architecture — core orchestrator, specialised agents, strategy system (#647)
* feat: multi-agent architecture — core orchestrator, specialised agents, strategy system

Phase 0-7 core agent infrastructure:
- AgentContext/AgentOpinion/StageResult protocols
- run_agent_loop() shared runner extracted from AgentExecutor
- AgentOrchestrator with 4 modes (quick/standard/full/strategy)
- BaseAgent ABC + Technical/Intel/Risk/Decision/Portfolio agents
- StrategyRouter (regime detection), StrategyAggregator (weighted consensus)
- AgentMemory with prediction tracking and confidence calibration
- Backtest summary tools registered as read-only Agent tools
- AGENT_ARCH switch (single/multi), config registry + WebUI entries
- is_agent_available() auto-detection from LITELLM_MODEL
- Config __post_init__ validation for AGENT_ARCH/ORCHESTRATOR_MODE/STRATEGY_ROUTING

* fix: address PR #647 review comments

- base_agent: propagate tool_calls_log in result.meta for orchestrator aggregation
- risk_agent: fix docstring — AGENT_RISK_OVERRIDE is bool, not string
- __init__: remove ResearchAgent from lazy imports (research.py not on this branch)
- router: cast trend_score to float to handle LLM string responses
- config_registry: fix duplicate display_order 65 — bump AGENT_MEMORY_ENABLED to 66 and cascade
- test_system_config_service: add missing assertions to validate test
- agent.py: clarify user_id must include platform prefix in docstring

* feat(multi-agent): strategy mode, data perspective fix, review fixes

- Multi-agent orchestrator: add strategy mode with consensus voting
- Fix data perspective MA N/A: compute trend before agent branch, read
  from trend_result instead of LLM output
- Fix risk override double-apply: make _apply_risk_override idempotent
  so normal runs don't over-downgrade signals
- Fix timeout error suppression: preserve error_message on agent result
  regardless of success flag
- Fix notification float subscript: wrap dashboard values in str()
- Add skills->strategies backward compat on ChatRequest model
- Fix zero-value falsy bug in price_position dict construction
- Add fill_price_position_if_needed post-processing for single-agent
- Add _bias_label helper for computed bias status display
- Increase orchestrator timeout default to 600s
- Web: skills->strategies rename, i18n updates
- Python 3.9 compat: add future annotations to stock_mapping.py

* fix: update pipeline routing test for trend_result param, fix risk docstring

- test_agent_mode_routes_to_agent: assert 8 positional args (trend_result added)
- risk_agent.py: fix docstring to match actual boolean config behavior

* fix typeerror
2026-03-14 13:45:35 +08:00
Alfred
c85423dfca [feat] 在分析报告中标记使用模型并完善展示链路 Issue #528 (#534)
* feat: mark model used in reports and notifications (#528)

* refactor: centralize model_used normalization and raw_result parsing (#528)

---------

Co-authored-by: mumu <42829555+ZhuLinsen@users.noreply.github.com>
2026-03-07 20:29:02 +08:00
mumu
cddb6baeda feat: add agent strategy chat across API, bot, and web UI #minor (#367)
* feat: add agent strategy chat across API, bot, and web UI #minor
- add /api/v1/agent endpoints for strategies and streaming chat
- route pipeline to agent mode when specific skills are configured
- persist multi-turn conversation history in database
- add web chat page, bot /ask command, built-in strategies, and tests

* fix(agent): improve session handling, progress messaging, and chat type safety #patch

Generate UUID session IDs for stream chat requests and use running loop API.

Persist user messages even on failed runs, and store assistant error notes for context continuity.

Add contextual thinking messages after tool calls in agent executor.

Fix strategy display name lookup in bot ask command.

Refine ChatPage TypeScript types and error handling for SSE parsing.

Use SQLAlchemy select+execute for conversation history query.

* docs: add Agent strategy chat to README and CHANGELOG #skip

* fix(tests): update strategy count assertions 6->11; clean up CHANGELOG [Unreleased] section #patch

* chore: update readme and fix unitest

* feat: optimize tools

* fix: Fix hard-coded test values and resolve nested mapping in Dashboard

* update changelog

* refactor(agent): extract shared factory, cache ToolRegistry/SkillManager, fix Gemini model name

* - CRITICAL: fix 4 wrong tool names in AGENT_SYSTEM_PROMPT and
  CHAT_SYSTEM_PROMPT (get_k_history→get_daily_history,
  get_technical_analysis→analyze_trend, get_chip_analysis→
  get_chip_distribution, search_news→search_stock_news)
- fix _THINKING_TOOL_LABELS: update 7 stale keys, add calculate_ma
  and get_analysis_context (13 tools now fully mapped)
- add isinstance(dict) guard in _parse_dashboard to reject non-dict
  JSON (arrays, scalars) that would crash downstream dict access
- use getattr() for config.agent_skills in pipeline.py (AttributeError safety)
- move  to top-level, remove unused imports (get_config,
  Callable, Any/Dict/Optional)
- add phased workflow directives to both system prompts to enforce
  sequential tool calling across analysis stages
- expand .env.example AGENT_SKILLS with all 11 built-in strategies
  and usage examples
- fix factory.py docstring referencing non-existent comprehensive_analysis
2026-02-23 13:24:01 +08:00