"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(agent): guide second-venue resolution on identity_mismatch
William Liao8fa4ef118af6
diff --git a/agent/prompts/identity_resolution.md b/agent/prompts/identity_resolution.mdindex 1405ec857..781ecc437 100644--- a/agent/prompts/identity_resolution.md+++ b/agent/prompts/identity_resolution.md@@ -16,6 +16,16 @@ The agent’s grounding system enforces that market consumers only use identitie- Equivalent spellings like `BTC-USDT` / `BTC/USDT` or `.SS` / `.SH` may normalize to the same identity, but the next market tool must still consume the locked canonical form from the resolver result.- Do not silently change a listed security into a private-company workflow.+### Same issuer, second venue (e.g. TSX + US listing)++A company listed on two exchanges is **two identities**, not one. If the locked identity is `BLDP.TO` (TSX, CAD) and you also need the US listing `BLDP.US` (NASDAQ) for an FX or venue cross-check, resolve the extra venue before touching it:++1. Call `search_symbol("BLDP.US")` in its own assistant turn and wait for the result.+2. Use the exact returned canonical symbol/venue for the follow-up market call.+3. Never bundle two venues of one issuer into a single `get_market_data` call unless both are already locked — `get_market_data(codes=["BLDP.TO", "BLDP.US"])` fails with `identity_mismatch` because only `BLDP.TO` is authorized.++If a `identity_mismatch` message mentions "second venue of ...", the guard is telling you exactly which `search_symbol` query to run next — run it, do not retry the same unauthorized call.+## Example flow1. User asks: “What's the latest price for TANTALUS SYSTEMS HOLDINGS INC?”diff --git a/agent/src/agent/grounding.py b/agent/src/agent/grounding.pyindex a33bf0dd9..4bb41d1a2 100644--- a/agent/src/agent/grounding.py+++ b/agent/src/agent/grounding.py@@ -887,17 +887,66 @@ class GroundingLedger:if self._match_authorized_symbol(symbol, authorized) is None)if mismatched:+ message = (+ "Consumer symbol/venue differs from the locked resolver identity; "+ "silent suffix or exchange rewrites are forbidden."+ )+ hints = [+ hint+ for symbol in mismatched+ for hint in self._venue_mismatch_hints(symbol, authorized)+ ]+ if hints:+ message += " " + " ".join(hints)return ToolAuthorization(allowed=False,error_code="identity_mismatch",- message=(- "Consumer symbol/venue differs from the locked resolver identity; "- "silent suffix or exchange rewrites are forbidden."- ),+ message=message,symbols=mismatched,)return ToolAuthorization(allowed=True, symbols=symbols)+ @staticmethod+ def _venue_mismatch_hints(+ requested_symbol: str,+ authorized_symbols: Iterable[str],+ ) -> list[str]:+ """Turn a same-issuer venue mismatch into an actionable resolver hint.++ ``BLDP.US`` against a locked ``BLDP.TO`` is not a typo of one identity;+ it is a second listing of the same company that was never resolved.+ Naming the exact ``search_symbol`` query keeps the model from retrying+ the identical unauthorized call. A bare ticker that collides with+ several locked venues gets a "use the full suffix" hint instead.+ """+ requested = _normalize_symbol(requested_symbol)+ authorized = {_normalize_symbol(item) for item in authorized_symbols}+ if "." in requested:+ base = requested.rsplit(".", 1)[0]+ same_issuer = sorted(+ item+ for item in authorized+ if "." in item and item.rsplit(".", 1)[0] == base+ )+ if same_issuer:+ return [+ f"[{requested_symbol} is a second venue of {', '.join(same_issuer)}; "+ f"call search_symbol('{requested_symbol}') in a separate turn "+ f"before querying it.]"+ ]+ return []+ matches = sorted(+ item+ for item in authorized+ if "." in item and item.rsplit(".", 1)[0] == requested+ )+ if len(matches) > 1:+ return [+ f"[{requested_symbol} matches multiple locked identities "+ f"({', '.join(matches)}); use the full venue-suffixed symbol.]"+ ]+ return []+@staticmethoddef _match_authorized_symbol(requested_symbol: str,