From 1c81e2af8c12d33929cbe7dedf5174d181c49355 Mon Sep 17 00:00:00 2001 From: Priyanka Punukollu Date: Sat, 28 Feb 2026 10:04:14 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20route=20my-TICKER-stock=20queries=20to?= =?UTF-8?q?=20market=5Fdata=20=E2=80=94=20pattern=20check=20before=20portf?= =?UTF-8?q?olio=20check,=20typo=20corrections=20applied=20(APPL=E2=86=92AA?= =?UTF-8?q?PL)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- agent/graph.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/agent/graph.py b/agent/graph.py index 9e7c1b744..943ddb93f 100644 --- a/agent/graph.py +++ b/agent/graph.py @@ -827,6 +827,20 @@ async def classify_node(state: AgentState) -> AgentState: if has_overview: return {**state, "query_type": "market_overview"} + # --- "my TICKER stock" = stock price, not portfolio holding --- + # Check BEFORE portfolio_ticker_kws ("my share of" = portfolio) + _TICKER_CORRECTIONS = { + "APPL": "AAPL", "APPL.": "AAPL", "APPLE": "AAPL", + "GOOG": "GOOGL", "GOOGLE": "GOOGL", "ALPHABET": "GOOGL", + "AMAZON": "AMZN", "MICROSOFT": "MSFT", "NVIDIA": "NVDA", + "TESLA": "TSLA", "META": "META", "FACEBOOK": "META", + } + my_stock_match = re.search(r"my\s+([A-Za-z]{1,5})\s+stock", query, re.IGNORECASE) + if my_stock_match: + candidate = my_stock_match.group(1).upper() + corrected = _TICKER_CORRECTIONS.get(candidate, candidate) + return {**state, "query_type": "market"} + # --- Possessive portfolio queries — check BEFORE stock price keywords --- # "my share of AAPL" = portfolio holding, not stock price portfolio_ticker_kws = [ @@ -847,6 +861,9 @@ async def classify_node(state: AgentState) -> AgentState: ] if any(kw in query for kw in portfolio_ticker_kws): return {**state, "query_type": "performance"} + # "my AAPL position" = portfolio holding (regex: my + optional ticker + position) + if re.search(r"my\s+([A-Za-z]{1,5}\s+)?position", query, re.IGNORECASE): + return {**state, "query_type": "performance"} # --- Stock price / market quote queries — MUST route to market_data not portfolio --- # Check BEFORE performance/portfolio fallback. User asking about market price of a ticker.