Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(grounding): require a quantity or an order label before masking an "@" level

Haozhe Wu03e1ff6555eb
diff --git a/agent/src/agent/grounding.py b/agent/src/agent/grounding.py
index 3a2b728e7..dab8f83f3 100644
--- a/agent/src/agent/grounding.py
+++ b/agent/src/agent/grounding.py
@@ -326,16 +326,16 @@ _ORDER_LEVEL_RE = re.compile(
r"\d[\d,]*(?:\.\d+)?\s*(?:股|shares?)?\s*@\s*"
+ _CURRENCY_TOKEN + r"\s*[-+]?\d[\d,]*(?:\.\d+)?"
r"|"
- # (b) a bare "@ <price>" with no quantity in front
- r"@\s*" + _CURRENCY_TOKEN + r"\s*[-+]?\d[\d,]*(?:\.\d+)?"
- r"|"
- # (c) an order label introducing the level
- # 买入价/卖出价 are deliberately absent: in running prose they name the
- # price a report OBSERVED entering at, not an instruction, and masking
- # them stopped a genuinely ungrounded quote from being rejected.
+ # (b) an order label, optionally carrying its own "<qty> @", then the level.
+ # There is deliberately no bare "@ <price>" branch: dates are masked before
+ # this runs, so "收盘 2026-08-10 @ 8.20" would arrive here as "@ 8.20" and a
+ # genuinely observed close would stop being checked. 买入价 / 卖出价 are
+ # absent for the same reason -- in running prose they name a price the
+ # report says it observed, not an instruction it proposes.
r"(?:挂单|限价单|限价|委托价?|订单"
r"|limit\s+(?:order|price)|\bGTC\b|\bGTD\b|\bIOC\b|\bFOK\b)"
- r"\s*(?:为|是|at|@|=)?\s*[::]?\s*"
+ r"\s*(?:为|是|at|=)?\s*[::]?\s*"
+ r"(?:\d[\d,]*(?:\.\d+)?\s*(?:股|shares?)?\s*@\s*)?"
+ _CURRENCY_TOKEN + r"\s*[-+]?\d[\d,]*(?:\.\d+)?"
r")" + _RANGE_TAIL,
re.IGNORECASE,
diff --git a/agent/tests/test_agent_grounding.py b/agent/tests/test_agent_grounding.py
index 31263ab39..2f216f653 100644
--- a/agent/tests/test_agent_grounding.py
+++ b/agent/tests/test_agent_grounding.py
@@ -2229,6 +2229,11 @@ def test_an_order_line_is_an_instruction_not_an_observation(tmp_path: Path) -> N
# quote through the gate.
assert extract("买入价 0.881") == [0.881]
+ # There is no bare "@ <price>" branch either. Dates are masked before this
+ # runs, so an observed close written "2026-08-10 @ 8.20" would reach the
+ # order mask as "@ 8.20" and stop being checked at all.
+ assert extract("收盘 2026-08-10 @ 8.20") == [8.2]
+
# An observed quote standing beside an order line is still checked, and a
# bare handle carries no price to mask.
assert extract("现价 8.20 CNY,挂单 100 @ 8.50") == [8.2]