Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(grounding): unify the resolver's "source cannot serve this query" marker

Haozhe Wu94cb7327914f
diff --git a/agent/src/agent/grounding.py b/agent/src/agent/grounding.py
index 4e71e3b49..b7a96dcc6 100644
--- a/agent/src/agent/grounding.py
+++ b/agent/src/agent/grounding.py
@@ -372,7 +372,7 @@ _CURRENCY_ALIASES = {
"HKD": ("hkd", "hk$", "港元", "港币"),
"KRW": ("krw", "韩元", "韩圜"),
"INR": ("inr", "印度卢比", "卢比"),
- "CAD": ("cad", "加元", "加拿大元"),
+ "CAD": ("cad", "c$", "加元", "加拿大元"),
}
_SYMBOL_HEADERS = {"symbol", "ticker", "code", "标的", "代码", "证券代码"}
diff --git a/agent/src/tools/symbol_search_tool.py b/agent/src/tools/symbol_search_tool.py
index 4b6cbfe1e..5b78b163f 100644
--- a/agent/src/tools/symbol_search_tool.py
+++ b/agent/src/tools/symbol_search_tool.py
@@ -82,6 +82,15 @@ _PER_SOURCE_CAP = 25
# the ``sec_edgar`` source entry entirely.
_NO_US = "__no_us__"
+# A source that cannot serve a given query shape reports this prefix instead of
+# an error string. The distinction is load-bearing, not cosmetic: the grounding
+# ledger concludes "this entity does not exist" only when every source that
+# could answer did answer, so a source recorded as failed turns a legitimate
+# "not listed" into a blocking ``invalidated`` identity. Both skip reasons below
+# share this one prefix — two spellings for one concept is exactly how that
+# cross-module contract breaks silently.
+_SKIPPED = "skipped: "
+
class SymbolSearchTool(BaseTool):
"""Resolve a company name or ticker fragment to candidate symbols."""
@@ -229,7 +238,7 @@ def _search_eastmoney(query: str) -> tuple[List[Dict[str, Any]], str]:
"eastmoney skipped for Canadian symbol %r (no Canada coverage)",
query,
)
- return [], "unsupported: eastmoney has no Canada coverage"
+ return [], f"{_SKIPPED}eastmoney has no Canada coverage"
try:
payload = eastmoney_client.get_json(
_EASTMONEY_SUGGEST_URL,
@@ -342,7 +351,7 @@ def _search_yahoo(query: str) -> tuple[List[Dict[str, Any]], str]:
# a request to manufacture a source failure. That failure is not
# cosmetic: a caller deciding whether an entity exists counts clean
# sources, and an unsupported query shape must not read as an outage.
- return [], "skipped: non-ASCII query is not supported by this source"
+ return [], f"{_SKIPPED}non-ASCII query is not supported by this source"
try:
quotes = yahoo_client.search(query)
except Exception as exc: # noqa: BLE001 - one source failing is non-fatal
diff --git a/agent/tests/test_agent_grounding.py b/agent/tests/test_agent_grounding.py
index e54e63169..c1c44fc1a 100644
--- a/agent/tests/test_agent_grounding.py
+++ b/agent/tests/test_agent_grounding.py
@@ -1707,3 +1707,65 @@ def test_a_clause_comma_still_separates_clauses(tmp_path: Path) -> None:
assert result.valid is False
assert "numeric_claim_conflict" in {issue["code"] for issue in result.issues}
+
+
[email protected]("query", ["贵州茅台", "ZZZZ.V"])
+def test_every_resolver_skip_marker_is_understood_as_a_non_failure(
+ tmp_path: Path,
+ monkeypatch: pytest.MonkeyPatch,
+ query: str,
+) -> None:
+ """Lock the cross-module contract for "this source cannot serve this query".
+
+ The resolver skips Yahoo for a non-ASCII query and Eastmoney for a Canadian
+ one. This ledger recognizes a non-failure only by the status prefix, so a
+ second spelling on the tool side silently turns "not listed" into a blocking
+ ``invalidated`` identity — which is exactly what an "unsupported: ..." status
+ did before the two were unified.
+ """
+ from src.tools import symbol_search_tool as resolver
+
+ monkeypatch.setattr(resolver.eastmoney_client, "get_json", lambda *a, **k: {})
+ monkeypatch.setattr(resolver.yahoo_client, "search", lambda *a, **k: [])
+
+ result = resolver.SymbolSearchTool().execute(query=query)
+ statuses = json.loads(result)["data"]["sources"]
+ assert any(value.startswith("skipped:") for value in statuses.values()), statuses
+
+ ledger = GroundingLedger(run_dir=tmp_path, user_message="这家公司现在股价多少")
+ ledger.ingest_tool_result(
+ tool_name="search_symbol",
+ arguments={"query": query},
+ result=result,
+ call_id="resolve",
+ success=True,
+ )
+
+ assert ledger.identity_status == "not_found"
+ assert ledger.validate_final_answer("没有查到这家公司,无法给出结论。").valid is True
+
+
+ ("symbol", "written"),
+ [("562500.SH", "¥1.171"), ("PDI.TO", "C$1.171")],
+)
+def test_a_currency_symbol_counts_as_naming_the_currency(
+ tmp_path: Path,
+ symbol: str,
+ written: str,
+) -> None:
+ """A model writes a quote as ¥ or C$, not as the ISO code."""
+ ledger = GroundingLedger(run_dir=tmp_path, user_message=f"{symbol} 现价多少")
+ ledger.ingest_tool_result(
+ tool_name="get_market_data",
+ arguments={"codes": [symbol]},
+ result=_market_payload(symbol),
+ call_id="prices",
+ success=True,
+ )
+
+ result = ledger.validate_final_answer(
+ f"{symbol} 最新收盘价 {written},数据来源:雅虎财经。"
+ )
+
+ assert result.valid is True, result.issues
diff --git a/agent/tests/test_symbol_search_tool.py b/agent/tests/test_symbol_search_tool.py
index 174fe6ab0..d51d50759 100644
--- a/agent/tests/test_symbol_search_tool.py
+++ b/agent/tests/test_symbol_search_tool.py
@@ -189,7 +189,7 @@ class TestSymbolSearchSuccess:
payload = json.loads(out)
assert payload["ok"] is True
assert payload["data"]["sources"]["eastmoney"] == (
- "unsupported: eastmoney has no Canada coverage"
+ "skipped: eastmoney has no Canada coverage"
)
def test_canadian_query_drops_us_otc_aliases(self):
@@ -286,7 +286,7 @@ class TestSymbolSearchSuccess:
payload = json.loads(out)
assert payload["ok"] is True
assert payload["data"]["sources"]["eastmoney"] == (
- "unsupported: eastmoney has no Canada coverage"
+ "skipped: eastmoney has no Canada coverage"
)
def test_canadian_v_ticker_with_name_text_skips_eastmoney(self):
@@ -301,7 +301,7 @@ class TestSymbolSearchSuccess:
mock_em.assert_not_called()
payload = json.loads(out)
assert payload["data"]["sources"]["eastmoney"] == (
- "unsupported: eastmoney has no Canada coverage"
+ "skipped: eastmoney has no Canada coverage"
)
def test_bare_name_without_suffix_still_hits_eastmoney(self):