Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(grounding): CJK month expressions are dates, and a formula may carry its explanation

Haozhe Wu290b877ebbf1
diff --git a/agent/src/agent/grounding/figures.py b/agent/src/agent/grounding/figures.py
index 9fbb0574a..cc54ceb95 100644
--- a/agent/src/agent/grounding/figures.py
+++ b/agent/src/agent/grounding/figures.py
@@ -45,7 +45,8 @@ _DATE_RE = re.compile(
# A year-less MM-DD / MM/DD; see _short_date_is_structural.
r"|(?P<short>(?<![\d.])(?:0[1-9]|1[0-2])[-/](?:0[1-9]|[12]\d|3[01])(?!\d|\.\d))"
r"|(?<![\d.:])(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?![\d:]|\.\d)"
- r"|\d{1,2}\s*月\s*\d{1,2}\s*[日号]"
+ # A month alone ("6月初"), a day, or a day range ("8月17–18日").
+ r"|(?<![\d.])\d{1,2}\s*月(?:\s*\d{1,2}(?:\s*[-–—~~]\s*\d{1,2})?\s*[日号])?"
r"|(?:19|20)\d{2}\s*年"
# A bare year or compact YYYYMMDD loses to a measurement mark ("$2050").
r"|(?P<soft>(?<![\d.])(?:19|20)\d{2}(?:(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01]))?(?!\d|\.\d))"
diff --git a/agent/src/agent/grounding/policies.py b/agent/src/agent/grounding/policies.py
index 6fc12306e..e98d0389e 100644
--- a/agent/src/agent/grounding/policies.py
+++ b/agent/src/agent/grounding/policies.py
@@ -334,6 +334,10 @@ def _formula_in_note(note: str) -> tuple[float, list[float], ast.Expression] | N
parts = [note]
for separator in ("≈", "≒", "=", "=", "→", "->"):
parts = [piece for part in parts for piece in part.split(separator)]
+ # A formula followed by its explanation ("(a − b) / b,自高点回撤"). A bare
+ # "," is not split: it groups thousands inside a formula.
+ for separator in (",", ";", ":", "; ", ", "):
+ parts = [piece for part in parts for piece in part.split(separator)]
candidates.extend(part for part in parts if part.strip())
for candidate in candidates:
evaluated = _evaluate_formula(candidate)
diff --git a/agent/tests/test_grounding_figures_contract.py b/agent/tests/test_grounding_figures_contract.py
index 2f084d4be..16aa4340a 100644
--- a/agent/tests/test_grounding_figures_contract.py
+++ b/agent/tests/test_grounding_figures_contract.py
@@ -275,6 +275,9 @@ def _shapes(text: str) -> dict[str, str]:
"The 2026-09-09 close", # ISO date, English prose
"On 2024 levels", # bare year, English prose
"3. First conclusion", # ordered-list marker, English
+ "8月17–18日高点", # CJK month with a day range (real run)
+ "6月初低点,8月中旬平台", # CJK month alone (real run)
+ "| 阻力 | 含义 |\n|---|---|\n| 前高 | 8月17–18日高点 |", # in a table cell
"2026-09-11 / 09-14 两次盘中低点", # zero-padded MM-DD after a full date
"09-14 收盘", # zero-padded MM-DD alone
"2026-10-11 / 10-14 两次盘中低点", # unpadded MM-DD opened by a full date
@@ -299,6 +302,7 @@ def test_structural_shapes_need_no_declaration(text: str) -> None:
"The close was 0.666", # decimal, English prose
"Down 37% from the high", # percent, English prose
"revenue of 400.5 billion", # decimal, English prose
+ "| 区间 |\n|---|\n| 17–18 |", # a range with no month mark is checked
"| 区间 |\n|---|\n| 11-12 |", # unpadded MM-DD shape may be a price range
"| 日期 | 区间 |\n|---|---|\n| 2026-09-09 | 11-12 |", # a date in ANOTHER cell
],
diff --git a/agent/tests/test_grounding_role_hardening.py b/agent/tests/test_grounding_role_hardening.py
index 029097e28..3a382717d 100644
--- a/agent/tests/test_grounding_role_hardening.py
+++ b/agent/tests/test_grounding_role_hardening.py
@@ -641,3 +641,16 @@ def test_a_price_discount_and_a_drawdown_still_derive(tmp_path: Path, prose: str
result = _ledger(tmp_path, MARKET_A).validate_final_answer(HDR + prose + _block(ROW, row))
assert result.valid is True, result.issues
+
+
+def test_a_formula_may_be_followed_by_its_explanation(tmp_path: Path) -> None:
+ """A real run wrote "(0.648 − 0.997) / 0.997,自7月1日收盘高点回撤" and lost a round."""
+ explained = _ledger(tmp_path / "ok", MARKET_A).validate_final_answer(
+ HDR + " 较高点回撤 37%。" + _block(ROW, "37% | derived | (1.053 − 0.666) / 1.053,自 5 月高点回撤 | c1")
+ )
+ wrong = _ledger(tmp_path / "bad", MARKET_A).validate_final_answer(
+ HDR + " 较高点回撤 12%。" + _block(ROW, "12% | derived | (1.053 − 0.666) / 1.053,自 5 月高点回撤 | c1")
+ )
+
+ assert explained.valid is True, explained.issues
+ assert "derivation_result_mismatch" in _reasons(wrong)