Skip to content

Commit 69da1bb

Browse files
authored
chore(TA): 升级 tradingagents v0.2.5 → v0.3.0 + 美股 get_news 透传修复 (#69)
零代码破坏升级 0.3.0(三市场 A/HK/US 真机验证跑通)+ timeout 默认 30min + 修美股 get_news 误入东财关键词搜索。 Closes #68
1 parent e01b03b commit 69da1bb

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

requirements.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ xhtml2pdf>=0.2.17
2525
# 不在 PyPI,用 git+ URL 安装。会拉 langchain/langgraph/yfinance 等较重依赖
2626
# (~115 个包,首次安装 2-5 分钟)。
2727
# 用户启用「TradingAgents 深度分析」Agent 时才会真正调用它;不启用零开销。
28-
# 锁定到 v0.2.5(而非 @main):上游 main 不断加需外部 key/服务的新工具
29-
# (get_verified_market_snapshot→yfinance、get_macro_indicators→FRED、polymarket 等),
30-
# 我们的注入层未覆盖就会硬失败。v0.2.5 是 PanWatch 适配/测试的稳定版,不含这些工具。
31-
# 升级前需先在适配层(toolkit_adapter)对新工具做覆盖/降级。
32-
tradingagents @ git+https://github.com/TauricResearch/TradingAgents.git@v0.2.5
28+
# 锁定到 v0.3.0(release tag,非 @main)。0.3.0 把 FRED/Polymarket 等可选数据源
29+
# 列入 OPTIONAL_CATEGORIES,无 key/网络失败时返回 DATA_UNAVAILABLE 哨兵而非硬失败
30+
# (根治了当初锁 v0.2.5 要躲的硬失败)。适配层 monkeypatch 目标(route_to_vendor/
31+
# load_ohlcv/get_graph_args/create_initial_state)的符号与签名跨 0.2.5→0.3.0 全部稳定,
32+
# result_mapper 读的 AgentState 字段全部保留 —— 零代码改动升级(评估见 issue #68)。
33+
tradingagents @ git+https://github.com/TauricResearch/TradingAgents.git@v0.3.0

src/agents/tradingagents/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(
6161
output_language: str = "Chinese",
6262
deep_model: str | None = None, # 推理/辩论/PM 用的强模型 (留空走默认)
6363
quick_model: str | None = None, # 分析师工具调用用的快模型 (留空 = deep_model)
64-
timeout_minutes: int = 15, # 整个流程硬超时;default 15 min 防卡死
64+
timeout_minutes: int = 30, # 整个流程硬超时;0.3.0 工具链更重,默认提到 30 min
6565
emit_paper_trading_signal: bool = False, # 是否把 BUY 决策写入 StrategySignalRun 驱动模拟盘
6666
):
6767
# 校验分析师配置

src/agents/tradingagents/toolkit_adapter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ def is_panwatch_routable(symbol: str) -> bool:
106106
return is_a_share(symbol) or is_hk_share(symbol)
107107

108108

109+
def _looks_like_cn_keyword(symbol: str) -> bool:
110+
"""含中文字符 = 行业/主题中文检索词(如「汽车行业」)→ 走东财关键词新闻;
111+
纯字母 ticker(美股 BABA/NVDA 等)不算 → 应透传上游 Yahoo 个股新闻。"""
112+
return any("一" <= ch <= "鿿" for ch in str(symbol or ""))
113+
114+
109115
def hk_symbol_to_yfinance(symbol: str) -> str:
110116
"""港股 PanWatch 5 位代码 → yfinance 格式。
111117
@@ -274,7 +280,7 @@ def _patched_route_to_vendor(method_name: str, *args, **kwargs):
274280

275281
# 行业/主题新闻:get_news 的 query 不是 ticker(中文行业词等) → 实时搜中文新闻(东方财富),
276282
# 替代拉不到中文数据的上游 vendor。
277-
if symbol and "news" in method_name.lower() and not is_panwatch_routable(symbol):
283+
if symbol and "news" in method_name.lower() and not is_panwatch_routable(symbol) and _looks_like_cn_keyword(symbol):
278284
try:
279285
result = _serve_keyword_news(symbol)
280286
_emit_toolkit_log(
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""美股 get_news 路由:应透传上游(Yahoo)而非被东财关键词搜索截走;中文行业词才走东财。
2+
3+
回归 bug:0.3.0 新闻分析师对美股 ticker(BABA)调 get_news,原逻辑只判 `not is_panwatch_routable`,
4+
把美股 ticker 也送进东财关键词搜索 → 搜不到 → 返回「未搜到」空结果,美股拿不到个股新闻。
5+
修复:关键词新闻分支再加「含中文」闸,纯字母 ticker 落到上游透传。
6+
"""
7+
8+
from __future__ import annotations
9+
10+
from src.agents.tradingagents import toolkit_adapter as tk
11+
12+
13+
def test_looks_like_cn_keyword_distinguishes_ticker_from_cn_query():
14+
"""纯字母美股 ticker 不算中文行业词;含中文(行业/主题)才算。"""
15+
assert tk._looks_like_cn_keyword("汽车行业") is True
16+
assert tk._looks_like_cn_keyword("新能源汽车") is True
17+
assert tk._looks_like_cn_keyword("BABA") is False
18+
assert tk._looks_like_cn_keyword("NVDA") is False
19+
assert tk._looks_like_cn_keyword("") is False
20+
21+
22+
def test_us_ticker_get_news_passes_through_to_upstream(monkeypatch):
23+
"""美股 get_news(BABA)→ 走上游 vendor(Yahoo),不进东财关键词搜索。"""
24+
calls = {"keyword": 0, "upstream": 0}
25+
26+
def fake_keyword(_sym):
27+
calls["keyword"] += 1
28+
return "东财关键词新闻"
29+
30+
def fake_upstream(_method, *_a, **_k):
31+
calls["upstream"] += 1
32+
return "UPSTREAM YAHOO NEWS for BABA"
33+
34+
monkeypatch.setattr(tk, "_serve_keyword_news", fake_keyword)
35+
monkeypatch.setattr(tk, "_real_route_to_vendor", fake_upstream)
36+
37+
out = tk._patched_route_to_vendor("get_news", "BABA", "2026-06-15", "2026-06-22")
38+
39+
assert calls["upstream"] == 1
40+
assert calls["keyword"] == 0
41+
assert "UPSTREAM" in str(out)
42+
43+
44+
def test_cn_keyword_get_news_goes_to_eastmoney(monkeypatch):
45+
"""中文行业词(汽车行业)→ 走东财关键词搜索,不透传上游。"""
46+
calls = {"keyword": 0, "upstream": 0}
47+
48+
def fake_keyword(_sym):
49+
calls["keyword"] += 1
50+
return "东财搜到的行业新闻"
51+
52+
def fake_upstream(_method, *_a, **_k):
53+
calls["upstream"] += 1
54+
return "UPSTREAM"
55+
56+
monkeypatch.setattr(tk, "_serve_keyword_news", fake_keyword)
57+
monkeypatch.setattr(tk, "_real_route_to_vendor", fake_upstream)
58+
59+
out = tk._patched_route_to_vendor("get_news", "汽车行业", "2026-06-15", "2026-06-22")
60+
61+
assert calls["keyword"] == 1
62+
assert calls["upstream"] == 0
63+
assert "行业新闻" in str(out)

0 commit comments

Comments
 (0)