fix: improve xwang compatibility and vendor fallback

This commit is contained in:
69049ed6x 2026-03-06 12:02:27 +08:00
parent 27e5854503
commit a9d9a42159
4 changed files with 21 additions and 6 deletions

View File

@ -132,10 +132,17 @@ def get_vendor(category: str, method: str = None) -> str:
return config.get("data_vendors", {}).get(category, "default")
def route_to_vendor(method: str, *args, **kwargs):
"""Route method calls to appropriate vendor implementation with fallback support."""
"""Route method calls to appropriate vendor implementation with fallback support.
Fallback policy:
- Try configured vendor order first, then other available vendors.
- On any vendor error, continue trying next vendor.
- Return first successful result.
- If all vendors fail, raise a summarized runtime error.
"""
category = get_category_for_method(method)
vendor_config = get_vendor(category, method)
primary_vendors = [v.strip() for v in vendor_config.split(',')]
primary_vendors = [v.strip() for v in vendor_config.split(',') if v.strip()]
if method not in VENDOR_METHODS:
raise ValueError(f"Method '{method}' not supported")
@ -147,6 +154,7 @@ def route_to_vendor(method: str, *args, **kwargs):
if vendor not in fallback_vendors:
fallback_vendors.append(vendor)
errors = []
for vendor in fallback_vendors:
if vendor not in VENDOR_METHODS[method]:
continue
@ -156,7 +164,9 @@ def route_to_vendor(method: str, *args, **kwargs):
try:
return impl_func(*args, **kwargs)
except AlphaVantageRateLimitError:
continue # Only rate limits trigger fallback
except Exception as e:
errors.append(f"{vendor}: {type(e).__name__}: {e}")
continue
raise RuntimeError(f"No available vendor for '{method}'")
details = " | ".join(errors) if errors else "no vendor candidates"
raise RuntimeError(f"No available vendor for '{method}'. Tried: {details}")

View File

@ -12,6 +12,7 @@ DEFAULT_CONFIG = {
"deep_think_llm": "gpt-5.2",
"quick_think_llm": "gpt-5-mini",
"backend_url": "https://api.openai.com/v1",
"default_headers": {"User-Agent": "curl/8.0"},
"factor_rules_path": os.getenv("TRADINGAGENTS_FACTOR_RULES_PATH", ""),
# Provider-specific thinking configuration
"google_thinking_level": None, # "high", "minimal", etc.

View File

@ -145,6 +145,10 @@ class TradingAgentsGraph:
if reasoning_effort:
kwargs["reasoning_effort"] = reasoning_effort
default_headers = self.config.get("default_headers")
if default_headers:
kwargs["default_headers"] = default_headers
return kwargs
def _create_tool_nodes(self) -> Dict[str, ToolNode]:

View File

@ -61,7 +61,7 @@ class OpenAIClient(BaseLLMClient):
elif self.base_url:
llm_kwargs["base_url"] = self.base_url
for key in ("timeout", "max_retries", "reasoning_effort", "api_key", "callbacks"):
for key in ("timeout", "max_retries", "reasoning_effort", "api_key", "callbacks", "default_headers"):
if key in self.kwargs:
llm_kwargs[key] = self.kwargs[key]