Skip to content
Python

Merge pull request #464 from CadeYu/sync-validator-models

Yijia Xiaoc61242a28cd3
diff --cc tradingagents/llm_clients/anthropic_client.py
index 27b01234e,939c7488b..ae2c367a9
--- a/tradingagents/llm_clients/anthropic_client.py
+++ b/tradingagents/llm_clients/anthropic_client.py
@@@ -31,12 -14,10 +31,13 @@@ class AnthropicClient(BaseLLMClient)
def get_llm(self) -> Any:
"""Return configured ChatAnthropic instance."""
+ self.warn_if_unknown_model()
llm_kwargs = {"model": self.model}
- for key in ("timeout", "max_retries", "api_key", "max_tokens", "callbacks", "http_client", "http_async_client"):
+ if self.base_url:
+ llm_kwargs["base_url"] = self.base_url
+
+ for key in _PASSTHROUGH_KWARGS:
if key in self.kwargs:
llm_kwargs[key] = self.kwargs[key]
diff --cc tradingagents/llm_clients/base_client.py
index 9c3dd17ce,818808560..f29d713dd
--- a/tradingagents/llm_clients/base_client.py
+++ b/tradingagents/llm_clients/base_client.py
@@@ -1,26 -1,8 +1,27 @@@
from abc import ABC, abstractmethod
from typing import Any, Optional
+ import warnings
+def normalize_content(response):
+ """Normalize LLM response content to a plain string.
+
+ Multiple providers (OpenAI Responses API, Google Gemini 3) return content
+ as a list of typed blocks, e.g. [{'type': 'reasoning', ...}, {'type': 'text', 'text': '...'}].
+ Downstream agents expect response.content to be a string. This extracts
+ and joins the text blocks, discarding reasoning/metadata blocks.
+ """
+ content = response.content
+ if isinstance(content, list):
+ texts = [
+ item.get("text", "") if isinstance(item, dict) and item.get("type") == "text"
+ else item if isinstance(item, str) else ""
+ for item in content
+ ]
+ response.content = "\n".join(t for t in texts if t)
+ return response
+
+
class BaseLLMClient(ABC):
"""Abstract base class for LLM clients."""
diff --cc tradingagents/llm_clients/google_client.py
index 755ff4ede,557e26401..baa31addd
--- a/tradingagents/llm_clients/google_client.py
+++ b/tradingagents/llm_clients/google_client.py
@@@ -25,12 -36,10 +25,13 @@@ class GoogleClient(BaseLLMClient)
def get_llm(self) -> Any:
"""Return configured ChatGoogleGenerativeAI instance."""
+ self.warn_if_unknown_model()
llm_kwargs = {"model": self.model}
- for key in ("timeout", "max_retries", "google_api_key", "callbacks", "http_client", "http_async_client"):
+ if self.base_url:
+ llm_kwargs["base_url"] = self.base_url
+
+ for key in ("timeout", "max_retries", "callbacks", "http_client", "http_async_client"):
if key in self.kwargs:
llm_kwargs[key] = self.kwargs[key]
diff --cc tradingagents/llm_clients/openai_client.py
index fd9b4e335,0629d894d..4f2e1b32b
--- a/tradingagents/llm_clients/openai_client.py
+++ b/tradingagents/llm_clients/openai_client.py
@@@ -53,18 -41,22 +53,19 @@@ class OpenAIClient(BaseLLMClient)
def get_llm(self) -> Any:
"""Return configured ChatOpenAI instance."""
+ self.warn_if_unknown_model()
llm_kwargs = {"model": self.model}
- if self.provider == "xai":
- llm_kwargs["base_url"] = "https://api.x.ai/v1"
- api_key = os.environ.get("XAI_API_KEY")
- if api_key:
- llm_kwargs["api_key"] = api_key
- elif self.provider == "openrouter":
- llm_kwargs["base_url"] = "https://openrouter.ai/api/v1"
- api_key = os.environ.get("OPENROUTER_API_KEY")
- if api_key:
- llm_kwargs["api_key"] = api_key
- elif self.provider == "ollama":
- llm_kwargs["base_url"] = "http://localhost:11434/v1"
- llm_kwargs["api_key"] = "ollama" # Ollama doesn't require auth
+ # Provider-specific base URL and auth
+ if self.provider in _PROVIDER_CONFIG:
+ base_url, api_key_env = _PROVIDER_CONFIG[self.provider]
+ llm_kwargs["base_url"] = base_url
+ if api_key_env:
+ api_key = os.environ.get(api_key_env)
+ if api_key:
+ llm_kwargs["api_key"] = api_key
+ else:
+ llm_kwargs["api_key"] = "ollama"
elif self.base_url:
llm_kwargs["base_url"] = self.base_url