Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(tools): coerce EDB value strings to float in srv-tool rows

sambazhu9425a5296ee7
diff --git a/agent/src/tools/gildata_srv.py b/agent/src/tools/gildata_srv.py
index f88169f2a..0759c3872 100644
--- a/agent/src/tools/gildata_srv.py
+++ b/agent/src/tools/gildata_srv.py
@@ -109,4 +109,24 @@ def call_srv_tool(
entry_rows = entry.get("rows")
if isinstance(entry_rows, list):
rows.extend(r for r in entry_rows if isinstance(r, dict))
+ _coerce_numeric_strings(rows)
return {"api_names": api_names, "rows": rows}
+
+
+def _coerce_numeric_strings(rows: list[dict[str, Any]]) -> None:
+ """Convert numeric-looking ``value`` strings to floats, in place.
+
+ The EDB rows carry their measurement as a string (``"value": "5.4"``).
+ The grounding evidence extractor indexes only numeric leaves, so a string
+ value never enters the verification pool while the same row's numeric
+ ``indicatorcode`` does — every macro figure was then unverifiable
+ (measured live: numeric_claim_conflict against the code, degraded release
+ with all figures redacted). Coercing the measurement field fixes the pool.
+ """
+ for row in rows:
+ value = row.get("value")
+ if isinstance(value, str):
+ try:
+ row["value"] = float(value)
+ except ValueError:
+ pass
diff --git a/agent/tests/test_gildata_research_tools.py b/agent/tests/test_gildata_research_tools.py
index dc6ad797b..bb78d217b 100644
--- a/agent/tests/test_gildata_research_tools.py
+++ b/agent/tests/test_gildata_research_tools.py
@@ -118,3 +118,37 @@ class TestExecute:
self._patch(monkeypatch, {"api_names": [], "rows": []})
out = json.loads(GetCnAnnouncementsTool().execute(query="不存在的东西"))
assert out["ok"] is True and out["rows"] == []
+
+
+class TestNumericCoercion:
+ """EDB value strings must land in the numeric evidence pool."""
+
+ def test_value_strings_coerced(self):
+ from src.tools.gildata_srv import _coerce_numeric_strings
+
+ rows = [{"indicatorname": "GDP同比", "value": "5.4", "unit": "%"},
+ {"indicatorname": "CPI同比", "value": "0.2"},
+ {"indicatorname": "缺口", "value": "."}]
+ _coerce_numeric_strings(rows)
+ assert rows[0]["value"] == 5.4
+ assert rows[1]["value"] == 0.2
+ assert rows[2]["value"] == "." # non-numeric stays untouched
+
+ def test_coerced_values_land_in_generic_evidence(self, tmp_path):
+ from src.agent.grounding.ledger import GroundingLedger
+
+ ledger = GroundingLedger(run_dir=tmp_path, user_message="2024年GDP增速")
+ payload = {
+ "api_names": ["EDB取数"],
+ "rows": [{"indicatorcode": 110252269, "indicatorname": "GDP当季同比",
+ "value": 5.4, "unit": "%", "date": "2024-12-31"}],
+ }
+ ledger._ingest_generic_numeric(
+ "get_cn_macro_series", {"query": "GDP"}, payload, call_id="edb",
+ )
+ leaves = {r.field: r.value for r in ledger._evidence}
+ # The measurement is a numeric leaf now (string "5.4" never indexed).
+ assert leaves.get("rows[0].value") == 5.4
+ # NOTE: whether percent claims VERIFY against these leaves is an
+ # upstream grounding question (the metric pool admits analysis
+ # metrics only) — tracked as an upstream issue, not asserted here.