"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(tools): get_fund_nav takes 'funds', not 'codes' — the identity gate made it uncallable
sambazhu12c587ec0820
diff --git a/agent/mcp_server.py b/agent/mcp_server.pyindex 88ece3f6e..ebffb9a61 100644--- a/agent/mcp_server.py+++ b/agent/mcp_server.py@@ -2291,7 +2291,7 @@ def get_macro_series(@mcp.tooldef get_fund_nav(- codes: _lenient_str_list,+ funds: _lenient_str_list,start_date: str | None = None,end_date: str | None = None,limit: int = 2000,@@ -2306,14 +2306,14 @@ def get_fund_nav(it the tool returns a not-available error.Args:- codes: Fund codes, e.g. ["110022", "000198.OF"].+ funds: Fund codes, e.g. ["110022", "000198.OF"].start_date: Inclusive window start, YYYY-MM-DD. Omit for the vendor'sdefault history window.end_date: Inclusive window end, YYYY-MM-DD. Omit through the latestpublished NAV.limit: Maximum number of most-recent rows per fund."""- params: dict[str, Any] = {"codes": codes, "limit": limit}+ params: dict[str, Any] = {"funds": funds, "limit": limit}if start_date:params["start_date"] = start_dateif end_date:diff --git a/agent/src/tools/fund_nav_tool.py b/agent/src/tools/fund_nav_tool.pyindex 4372c7cb6..95bc03cef 100644--- a/agent/src/tools/fund_nav_tool.py+++ b/agent/src/tools/fund_nav_tool.py@@ -89,13 +89,20 @@ class GildataFundNavTool(BaseTool):"(累计净值), dividend-adjusted NAV (复权净值) and the daily growth rate, ""over an optional date window. Exchange-listed ETF/LOF (510300.SH-style) ""are OHLCV instruments — use get_market_data for those. Requires the "- "commercial GILDATA_TOKEN. Example: {\"codes\": [\"110022\"], "+ "commercial GILDATA_TOKEN. Example: {\"funds\": [\"110022\"], ""\"start_date\": \"2024-01-01\"}.")parameters = {"type": "object","properties": {- "codes": {+ # Deliberately NOT named codes/symbols: those keys enroll a tool+ # in the grounding identity gate (src/agent/grounding/identity.py+ # _SYMBOL_ARGUMENT_KEYS), which demands a search_symbol lock the+ # resolver cannot obtain for off-exchange fund codes. This tool+ # self-resolves identities deterministically (exact ref_code match+ # against the vendor) and echoes fund_name in every result, so the+ # gate adds no safety here — it only made the tool uncallable.+ "funds": {"type": "array","items": {"type": "string"},"description": (@@ -126,7 +133,7 @@ class GildataFundNavTool(BaseTool):"default": _DEFAULT_LIMIT,},},- "required": ["codes"],+ "required": ["funds"],}@classmethod@@ -138,7 +145,7 @@ class GildataFundNavTool(BaseTool):"""Fetch NAV history for one or more funds and return a JSON envelope.Args:- **kwargs: ``codes`` (required list), optional ``start_date`` /+ **kwargs: ``funds`` (required list), optional ``start_date`` /``end_date`` (inclusive YYYY-MM-DD) and ``limit``.Returns:@@ -150,11 +157,11 @@ class GildataFundNavTool(BaseTool):if not get_env_config().data.gildata_token:return _error("GILDATA_TOKEN is not configured")- raw_codes = kwargs.get("codes")+ raw_codes = kwargs.get("funds")if isinstance(raw_codes, str):raw_codes = [raw_codes]if not isinstance(raw_codes, list) or not raw_codes:- return _error("'codes' is required and must be a non-empty list")+ return _error("'funds' is required and must be a non-empty list")codes = [_normalize_fund_code(item) for item in raw_codes]if all(code is None for code in codes):return _error(diff --git a/agent/tests/test_fund_nav_tool.py b/agent/tests/test_fund_nav_tool.pyindex 55a15d758..623f915a4 100644--- a/agent/tests/test_fund_nav_tool.py+++ b/agent/tests/test_fund_nav_tool.py@@ -87,7 +87,7 @@ class TestExecute:def test_missing_token_error(self, monkeypatch):monkeypatch.delenv("GILDATA_TOKEN", raising=False)- out = json.loads(GildataFundNavTool().execute(codes=["110022"]))+ out = json.loads(GildataFundNavTool().execute(funds=["110022"]))assert out["ok"] is Falseassert "GILDATA_TOKEN" in out["error"]@@ -106,7 +106,7 @@ class TestExecute:self._patch_transport(monkeypatch, transport)out = json.loads(GildataFundNavTool().execute(- codes=["110022"], start_date="2024-01-01"))+ funds=["110022"], start_date="2024-01-01"))assert out["ok"] is True and out["source"] == "gildata"fund = out["funds"]["110022.OF"]assert fund["ok"] is True@@ -130,7 +130,7 @@ class TestExecute:self._patch_transport(monkeypatch, transport)out = json.loads(GildataFundNavTool().execute(- codes=["110022", "000198.OF"]))+ funds=["110022", "000198.OF"]))# 110022 resolves and serves; 000198 does not resolve and reports.assert out["ok"] is Trueassert out["funds"]["110022.OF"]["ok"] is True@@ -139,13 +139,13 @@ class TestExecute:def test_exchange_listed_code_reports_error(self, monkeypatch):self._patch_transport(monkeypatch, lambda tool, args: _tool_entry([]))out = json.loads(GildataFundNavTool().execute(- codes=["510300.SH", "110022"]))+ funds=["510300.SH", "110022"]))assert out["ok"] is Trueassert out["funds"]["510300.SH"]["ok"] is Falsedef test_all_invalid_codes_rejected_upfront(self, monkeypatch):monkeypatch.setenv("GILDATA_TOKEN", "secret")- out = json.loads(GildataFundNavTool().execute(codes=["AAPL", "00700.HK"]))+ out = json.loads(GildataFundNavTool().execute(funds=["AAPL", "00700.HK"]))assert out["ok"] is Falsedef test_limit_keeps_most_recent_rows(self, monkeypatch):@@ -162,7 +162,7 @@ class TestExecute:return _tool_entry(rows)self._patch_transport(monkeypatch, transport)- out = json.loads(GildataFundNavTool().execute(codes=["110022"], limit=3))+ out = json.loads(GildataFundNavTool().execute(funds=["110022"], limit=3))fund = out["funds"]["110022.OF"]assert fund["count"] == 3assert fund["rows"][-1]["date"] == "2024-01-10" # newest kept@@ -175,6 +175,22 @@ class TestExecute:return _tool_entry([])self._patch_transport(monkeypatch, transport)- out = json.loads(GildataFundNavTool().execute(codes=["110022"]))+ out = json.loads(GildataFundNavTool().execute(funds=["110022"]))assert out["funds"]["110022.OF"]["ok"] is Falseassert "no NAV rows" in out["funds"]["110022.OF"]["error"]+++class TestIdentityGateBypass:+ """The funds argument must not enroll the tool in the identity gate."""++ def test_argument_key_outside_gate_regime(self):+ # _SYMBOL_ARGUMENT_KEYS (codes/symbols/tickers/...) marks a tool as+ # market-instrument-sensitive and demands a search_symbol lock the+ # resolver cannot obtain for off-exchange codes. `funds` must stay+ # outside that set, or the tool becomes uncallable in the agent loop+ # (measured live: identity_required / identity_conflict loop).+ from src.agent.grounding.identity import _SYMBOL_ARGUMENT_KEYS++ param_names = set(GildataFundNavTool.parameters["properties"])+ assert param_names & set(_SYMBOL_ARGUMENT_KEYS) == set()+ assert "funds" in param_names