Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(grounding): tell the model when a formula runs the other way, and to answer only

Haozhe Wu4a40a7f6475f
diff --git a/agent/src/agent/grounding/policies.py b/agent/src/agent/grounding/policies.py
index b419f670b..4768b60c6 100644
--- a/agent/src/agent/grounding/policies.py
+++ b/agent/src/agent/grounding/policies.py
@@ -594,7 +594,14 @@ class _PolicyMixin:
"is not declared in the figures block and is not an observed "
"value; declare it as observed / derived / proposed / cited / "
"count, or remove it",
- **({"declared_as": other_unit.value_text} if other_unit else {}),
+ **(
+ {
+ "declared_as": other_unit.value_text,
+ "declared_sign_differs": (other_unit.value < 0) != (figure.value < 0),
+ }
+ if other_unit
+ else {}
+ ),
)
)
continue
@@ -1677,6 +1684,10 @@ class _PolicyMixin:
# Reported in the figure's own units, as ``_result_matches`` compares it.
scaled = result * 100.0 if figure.percent else result
shown = f"{scaled:.6g}%" if figure.percent else f"{scaled:.6g}"
+ # "−1.51pp" beside "12.87% − 11.36%": the size is right and the formula
+ # runs the other way. Still refused (the sign is part of the claim),
+ # but said, or the model rewrites the number instead of the formula.
+ reversed_sign = self._result_matches(figure, -result)
return [
self._figure_issue(
"numeric_claim_conflict",
@@ -1686,6 +1697,7 @@ class _PolicyMixin:
"derivation_result_mismatch",
f"is declared derived, but its own formula evaluates to {shown}",
derived_result=shown,
+ **({"sign_reversed": True} if reversed_sign else {}),
)
]
@@ -2030,7 +2042,9 @@ def _declared_in_other_unit(block: FiguresBlock, figure: Figure) -> Declaration
if declaration.percent == figure.percent:
continue
in_figure_units = declaration.value * (100.0 if figure.percent else 0.01)
- if abs(in_figure_units - figure.value) <= half_unit * (1 + 1e-9):
+ # By size: a difference declared one way round and written the other
+ # ("0.0151" for "−1.51pp") is still the value the model meant to name.
+ if abs(abs(in_figure_units) - abs(figure.value)) <= half_unit * (1 + 1e-9):
return declaration
return None
diff --git a/agent/src/agent/grounding/release.py b/agent/src/agent/grounding/release.py
index 1c988b687..9d6ec64ce 100644
--- a/agent/src/agent/grounding/release.py
+++ b/agent/src/agent/grounding/release.py
@@ -125,8 +125,15 @@ def _correction_line(issue: dict[str, Any]) -> str:
declared_as = issue.get("declared_as")
if declared_as:
evidence += (
- f"; the figures block declares {declared_as}, which is not how the answer "
- f"writes it — declare it exactly as written ({issue.get('value')})"
+ f"; the figures block declares {declared_as}"
+ + (", with the opposite sign," if issue.get("declared_sign_differs") else "")
+ + f" which is not how the answer writes it — declare it exactly as written "
+ f"({issue.get('value')})"
+ )
+ if issue.get("sign_reversed"):
+ evidence += (
+ "; that is the same size with the opposite sign — the formula runs the other "
+ "way round from the answer, so write its operands in the order the answer states"
)
candidates = issue.get("field_ref_candidates") or []
if candidates:
@@ -177,6 +184,8 @@ class _ReleaseMixin:
"""
lines = [
"[GROUNDING GATE] The previous draft was rejected and was not released to the user.",
+ "Reply with the corrected answer only, in the user's language, written as the "
+ "answer itself: do not mention this rejection, the check or the figures block.",
"Every figure below, exactly as you wrote it, with what you declared and what the evidence says:",
]
figures, others = [], []
diff --git a/agent/tests/test_grounding_backtest_outputs.py b/agent/tests/test_grounding_backtest_outputs.py
index 50cf83b7c..ff7a68564 100644
--- a/agent/tests/test_grounding_backtest_outputs.py
+++ b/agent/tests/test_grounding_backtest_outputs.py
@@ -613,3 +613,49 @@ def test_only_a_literal_square_or_cube_is_evaluated() -> None:
assert _formula_in_note("9^9^9") is None
assert _formula_in_note("2^10 + 1") is None
assert _formula_in_note("0.3^2 + 0.4^2")[0] == pytest.approx(0.25)
+
+
+# ---------------------------------------------------------------------------
+# What the correction tells the model (live DeepSeek run, 2026-09-29)
+# ---------------------------------------------------------------------------
+
+
+def test_a_formula_that_runs_the_other_way_is_named_as_such(two_runs: GroundingLedger) -> None:
+ """"−0.079" beside "1.2115 − 1.1329": the size is right, the direction is not.
+
+ Still refused — the sign is part of the claim — but the second draft of a
+ live run rewrote eight such figures instead of their formulas, because the
+ correction only said "its own note evaluates to 0.079".
+ """
+ result = two_runs.validate_final_answer(
+ _declared("风险平价 Sortino 低 −0.079。", "−0.079 | derived | 1.2115 − 1.1329 | rp, ew")
+ )
+ wrong = two_runs.validate_final_answer(
+ _declared("风险平价 Sortino 低 −0.12。", "−0.12 | derived | 1.2115 − 1.1329 | rp, ew")
+ )
+
+ (issue,) = result.issues
+ assert issue["reason"] == "derivation_result_mismatch" and issue["sign_reversed"] is True
+ assert "opposite sign" in two_runs.correction_prompt(result)
+ assert "sign_reversed" not in wrong.issues[0]
+
+
+def test_a_declaration_of_the_other_sign_and_unit_is_named(two_runs: GroundingLedger) -> None:
+ result = two_runs.validate_final_answer(
+ _declared("风险平价总收益低 −0.30pp。", "0.0030 | derived | 0.132805 − 0.129817 | rp, ew")
+ )
+
+ (issue,) = result.issues
+ assert issue["declared_as"] == "0.0030" and issue["declared_sign_differs"] is True
+ assert "with the opposite sign" in two_runs.correction_prompt(result)
+
+
+def test_the_correction_asks_for_the_answer_alone(two_runs: GroundingLedger) -> None:
+ """A live second draft opened with "The rejection was because…" — in English,
+ to a user who wrote Chinese — and that sentence was released."""
+ result = two_runs.validate_final_answer("风险平价 Sortino 1.190。")
+
+ prompt = two_runs.correction_prompt(result)
+
+ assert "do not mention this rejection" in prompt
+ assert "in the user's language" in prompt