rameshbasina commited on
Commit
87739be
Β·
1 Parent(s): 14f4fe7

refactor(config): rename financial_quote_hints + provider_symbol; neutral logs

Browse files
config/agent_config.json CHANGED
@@ -576,7 +576,7 @@
576
  },
577
 
578
  "tool_routing": {
579
- "description": "Executable tool policy and Yahoo Finance hints. domain_mapping.json = high-level domains/personas; this block = which tools run and how market queries map to symbols.",
580
  "llm_router": {
581
  "min_cpu_exclusive": 4,
582
  "disable_env": "MEETARA_FAST",
@@ -586,24 +586,24 @@
586
  "market_quote_web_suppress": {
587
  "enabled": true,
588
  "unless_regex": "\\b(news|headlines?|articles?|stories|breaking|rumou?rs?|earnings|filing|why did|why is|fed |minutes |look up online|search for)\\b",
589
- "note": "When financial + web_search both fired, skip DDG for pure quote/performance questions (Yahoo already has numbers)."
590
  },
591
- "financial_yahoo_hints": [
592
- { "label": "S&P 500", "yahoo_symbol": "^GSPC", "regex": "\\bs&p\\s*500\\b|\\bsp\\s*500\\b|\\bsp500\\b|\\bspx\\b" },
593
- { "label": "S&P 500", "yahoo_symbol": "^GSPC", "regex": "\\bs\\s+and\\s+p\\s+500\\b" },
594
- { "label": "S&P 500", "yahoo_symbol": "^GSPC", "regex": "\\bs\\s*&\\s*p\\b" },
595
- { "label": "S&P 500", "yahoo_symbol": "^GSPC", "regex": "s&p" },
596
- { "label": "Dow Jones", "yahoo_symbol": "^DJI", "regex": "\\bdow\\s+jones\\b|\\bdjia\\b|\\bthe\\s+dow\\b" },
597
- { "label": "Dow Jones", "yahoo_symbol": "^DJI", "regex": "\\bdow\\b", "exclude_if_substring": ["download"] },
598
- { "label": "NASDAQ", "yahoo_symbol": "^IXIC", "regex": "\\bnasdaq\\b" },
599
- { "label": "Russell 2000", "yahoo_symbol": "^RUT", "regex": "\\brussell\\b" },
600
- { "label": "VIX", "yahoo_symbol": "^VIX", "regex": "\\bvix\\b|fear\\s+index|volatility\\s+index" },
601
- { "label": "BTC/USD", "yahoo_symbol": "BTC-USD", "regex": "\\bbitcoin\\b|\\bbtc\\b" },
602
- { "label": "ETH/USD", "yahoo_symbol": "ETH-USD", "regex": "\\bethereum\\b|\\beth\\b" },
603
- { "label": "Gold", "yahoo_symbol": "GC=F", "regex": "\\bgold\\b" },
604
- { "label": "Oil (WTI)", "yahoo_symbol": "CL=F", "regex": "\\b(wti|crude\\s+oil)\\b" },
605
- { "label": "Oil (WTI)", "yahoo_symbol": "CL=F", "regex": "\\boil\\b", "exclude_if_substring": ["spoil"] },
606
- { "label": "EUR/USD", "yahoo_symbol": "EURUSD=X", "regex": "\\beur\\s*/\\s*usd\\b" }
607
  ]
608
  },
609
 
 
576
  },
577
 
578
  "tool_routing": {
579
+ "description": "Executable tool policy and market-quote hints. domain_mapping.json = high-level domains/personas; this block = which tools run and how questions map to provider symbols (backend may swap APIs).",
580
  "llm_router": {
581
  "min_cpu_exclusive": 4,
582
  "disable_env": "MEETARA_FAST",
 
586
  "market_quote_web_suppress": {
587
  "enabled": true,
588
  "unless_regex": "\\b(news|headlines?|articles?|stories|breaking|rumou?rs?|earnings|filing|why did|why is|fed |minutes |look up online|search for)\\b",
589
+ "note": "When financial + web_search both fired, skip DDG for pure quote/performance questions (market tool already returns levels)."
590
  },
591
+ "financial_quote_hints": [
592
+ { "label": "S&P 500", "provider_symbol": "^GSPC", "regex": "\\bs&p\\s*500\\b|\\bsp\\s*500\\b|\\bsp500\\b|\\bspx\\b" },
593
+ { "label": "S&P 500", "provider_symbol": "^GSPC", "regex": "\\bs\\s+and\\s+p\\s+500\\b" },
594
+ { "label": "S&P 500", "provider_symbol": "^GSPC", "regex": "\\bs\\s*&\\s*p\\b" },
595
+ { "label": "S&P 500", "provider_symbol": "^GSPC", "regex": "s&p" },
596
+ { "label": "Dow Jones", "provider_symbol": "^DJI", "regex": "\\bdow\\s+jones\\b|\\bdjia\\b|\\bthe\\s+dow\\b" },
597
+ { "label": "Dow Jones", "provider_symbol": "^DJI", "regex": "\\bdow\\b", "exclude_if_substring": ["download"] },
598
+ { "label": "NASDAQ", "provider_symbol": "^IXIC", "regex": "\\bnasdaq\\b" },
599
+ { "label": "Russell 2000", "provider_symbol": "^RUT", "regex": "\\brussell\\b" },
600
+ { "label": "VIX", "provider_symbol": "^VIX", "regex": "\\bvix\\b|fear\\s+index|volatility\\s+index" },
601
+ { "label": "BTC/USD", "provider_symbol": "BTC-USD", "regex": "\\bbitcoin\\b|\\bbtc\\b" },
602
+ { "label": "ETH/USD", "provider_symbol": "ETH-USD", "regex": "\\bethereum\\b|\\beth\\b" },
603
+ { "label": "Gold", "provider_symbol": "GC=F", "regex": "\\bgold\\b" },
604
+ { "label": "Oil (WTI)", "provider_symbol": "CL=F", "regex": "\\b(wti|crude\\s+oil)\\b" },
605
+ { "label": "Oil (WTI)", "provider_symbol": "CL=F", "regex": "\\boil\\b", "exclude_if_substring": ["spoil"] },
606
+ { "label": "EUR/USD", "provider_symbol": "EURUSD=X", "regex": "\\beur\\s*/\\s*usd\\b" }
607
  ]
608
  },
609
 
core/meetara_agent.py CHANGED
@@ -44,13 +44,13 @@ except ImportError:
44
 
45
  try:
46
  from core.tool_routing import (
47
- resolve_financial_yahoo_symbols,
48
  should_run_llm_router,
49
  should_suppress_web_for_financial_quote,
50
  )
51
  except ImportError:
52
  from .tool_routing import (
53
- resolve_financial_yahoo_symbols,
54
  should_run_llm_router,
55
  should_suppress_web_for_financial_quote,
56
  )
@@ -1078,20 +1078,20 @@ def datetime_tool(query: str) -> str:
1078
 
1079
 
1080
  # ── Financial Market Data ─────────────────────────────────────────────────
1081
- # Yahoo symbol hints: config/agent_config.json β†’ tool_routing.financial_yahoo_hints
1082
 
1083
 
1084
  def financial_data(query: str = "") -> str:
1085
  """
1086
- Fetch real-time market prices from Yahoo Finance for major indices,
1087
- commodities, currencies, and crypto.
 
1088
 
1089
  Args:
1090
- query: Optional symbol or market name to look up specifically.
1091
- Leave blank for the standard market overview.
1092
 
1093
  Returns:
1094
- Formatted market snapshot string with prices and % changes.
1095
  """
1096
  import re
1097
  import urllib.request
@@ -1137,7 +1137,7 @@ def financial_data(query: str = "") -> str:
1137
  if _q in _EXACT_ALIAS:
1138
  symbols_to_fetch = [_EXACT_ALIAS[_q]]
1139
  else:
1140
- nl = resolve_financial_yahoo_symbols(raw, _ac)
1141
  if nl:
1142
  symbols_to_fetch = nl
1143
  elif _q and len(raw) <= 16 and re.match(r"^[A-Z0-9=\-\.\^]+$", _q):
@@ -1194,9 +1194,9 @@ def financial_data(query: str = "") -> str:
1194
  success += 1
1195
 
1196
  if success == 0:
1197
- return "Financial Data: Could not fetch market data (Yahoo Finance may be unavailable)."
1198
 
1199
- lines.append(f"\n*Prices from Yahoo Finance. Delayed ~15 min.*")
1200
  result = "\n".join(lines)
1201
  logger.info(f"[AGENT] πŸ“ˆ Financial data: fetched {success}/{len(symbols_to_fetch)} symbols")
1202
  return result
@@ -1297,7 +1297,7 @@ class MeeTARAAgent:
1297
  # Financial Data Tool
1298
  if 'financial_data' in globals():
1299
  self.tools.append(financial_data)
1300
- logger.info("[AGENT] βœ… Financial Data tool loaded (Yahoo Finance)")
1301
 
1302
  logger.info(f"[AGENT] βœ… meeTARA Agent loaded {len(self.tools)} tools (no smolagents needed)")
1303
 
@@ -1789,7 +1789,7 @@ class MeeTARAAgent:
1789
  needs["web_search"] = False
1790
  needs["search_query"] = None
1791
  logger.info(
1792
- "[AGENT] πŸ“ˆ Skipping web search β€” quote-style market question (Yahoo only)"
1793
  )
1794
 
1795
  logger.debug(f"[AGENT] πŸ” Final detection result: {needs}")
 
44
 
45
  try:
46
  from core.tool_routing import (
47
+ resolve_financial_quote_symbols,
48
  should_run_llm_router,
49
  should_suppress_web_for_financial_quote,
50
  )
51
  except ImportError:
52
  from .tool_routing import (
53
+ resolve_financial_quote_symbols,
54
  should_run_llm_router,
55
  should_suppress_web_for_financial_quote,
56
  )
 
1078
 
1079
 
1080
  # ── Financial Market Data ─────────────────────────────────────────────────
1081
+ # Quote symbol hints: config/agent_config.json β†’ tool_routing.financial_quote_hints
1082
 
1083
 
1084
  def financial_data(query: str = "") -> str:
1085
  """
1086
+ Fetch delayed market quotes (indices, FX, commodities, crypto).
1087
+ Implementation uses the public Yahoo chart JSON endpoint today; symbols in
1088
+ config are provider-neutral (`provider_symbol`) so the fetcher can be swapped.
1089
 
1090
  Args:
1091
+ query: Optional symbol or natural-language market question.
 
1092
 
1093
  Returns:
1094
+ Formatted snapshot with prices and % changes.
1095
  """
1096
  import re
1097
  import urllib.request
 
1137
  if _q in _EXACT_ALIAS:
1138
  symbols_to_fetch = [_EXACT_ALIAS[_q]]
1139
  else:
1140
+ nl = resolve_financial_quote_symbols(raw, _ac)
1141
  if nl:
1142
  symbols_to_fetch = nl
1143
  elif _q and len(raw) <= 16 and re.match(r"^[A-Z0-9=\-\.\^]+$", _q):
 
1194
  success += 1
1195
 
1196
  if success == 0:
1197
+ return "Financial Data: Could not fetch market quotes (quote provider may be unavailable)."
1198
 
1199
+ lines.append(f"\n*Delayed quote (~15 min). Source: current deployment uses Yahoo chart data.*")
1200
  result = "\n".join(lines)
1201
  logger.info(f"[AGENT] πŸ“ˆ Financial data: fetched {success}/{len(symbols_to_fetch)} symbols")
1202
  return result
 
1297
  # Financial Data Tool
1298
  if 'financial_data' in globals():
1299
  self.tools.append(financial_data)
1300
+ logger.info("[AGENT] βœ… Financial Data tool loaded (market quotes)")
1301
 
1302
  logger.info(f"[AGENT] βœ… meeTARA Agent loaded {len(self.tools)} tools (no smolagents needed)")
1303
 
 
1789
  needs["web_search"] = False
1790
  needs["search_query"] = None
1791
  logger.info(
1792
+ "[AGENT] πŸ“ˆ Skipping web search β€” quote-style question (market tool has levels)"
1793
  )
1794
 
1795
  logger.debug(f"[AGENT] πŸ” Final detection result: {needs}")
core/tool_routing.py CHANGED
@@ -26,11 +26,12 @@ def _routing_section(agent_config: Optional[Dict[str, Any]] = None) -> Dict[str,
26
  return {}
27
 
28
 
29
- def resolve_financial_yahoo_symbols(
30
  query: str, agent_config: Optional[Dict[str, Any]] = None
31
  ) -> List[Tuple[str, str]]:
32
- """Return [(label, yahoo_symbol), ...] from financial_yahoo_hints in agent_config."""
33
- hints = _routing_section(agent_config).get("financial_yahoo_hints") or []
 
34
  if not hints:
35
  return []
36
 
@@ -48,13 +49,19 @@ def resolve_financial_yahoo_symbols(
48
  if not re.search(rx, ql, re.IGNORECASE):
49
  continue
50
  except re.error as ex:
51
- logger.warning(f"[tool_routing] bad financial_yahoo_hints regex: {ex}")
52
  continue
53
  for bad in rule.get("exclude_if_substring") or []:
54
  if str(bad).lower() in ql:
55
  break
56
  else:
57
- sym = (rule.get("yahoo_symbol") or rule.get("yahoo") or "").strip()
 
 
 
 
 
 
58
  label = (rule.get("label") or sym or "?").strip()
59
  if sym and sym not in seen:
60
  seen.add(sym)
@@ -92,3 +99,7 @@ def should_run_llm_router(ncpu: int, agent_config: Optional[Dict[str, Any]] = No
92
  return True
93
  min_exc = int(lr.get("min_cpu_exclusive", 4))
94
  return ncpu > min_exc
 
 
 
 
 
26
  return {}
27
 
28
 
29
+ def resolve_financial_quote_symbols(
30
  query: str, agent_config: Optional[Dict[str, Any]] = None
31
  ) -> List[Tuple[str, str]]:
32
+ """Return [(label, provider_symbol), ...] from tool_routing.financial_quote_hints."""
33
+ sec = _routing_section(agent_config)
34
+ hints = sec.get("financial_quote_hints") or sec.get("financial_yahoo_hints") or []
35
  if not hints:
36
  return []
37
 
 
49
  if not re.search(rx, ql, re.IGNORECASE):
50
  continue
51
  except re.error as ex:
52
+ logger.warning(f"[tool_routing] bad financial_quote_hints regex: {ex}")
53
  continue
54
  for bad in rule.get("exclude_if_substring") or []:
55
  if str(bad).lower() in ql:
56
  break
57
  else:
58
+ sym = (
59
+ rule.get("provider_symbol")
60
+ or rule.get("yahoo_symbol")
61
+ or rule.get("symbol")
62
+ or rule.get("yahoo")
63
+ or ""
64
+ ).strip()
65
  label = (rule.get("label") or sym or "?").strip()
66
  if sym and sym not in seen:
67
  seen.add(sym)
 
99
  return True
100
  min_exc = int(lr.get("min_cpu_exclusive", 4))
101
  return ncpu > min_exc
102
+
103
+
104
+ # Backward-compatible name (older docs / forks)
105
+ resolve_financial_yahoo_symbols = resolve_financial_quote_symbols