diff --git a/python/valuecell/adapters/models/factory.py b/python/valuecell/adapters/models/factory.py index 15835a8ed..2c8e6f924 100644 --- a/python/valuecell/adapters/models/factory.py +++ b/python/valuecell/adapters/models/factory.py @@ -507,7 +507,7 @@ class DashScopeProvider(ModelProvider): """DashScope model provider (native)""" def create_model(self, model_id: Optional[str] = None, **kwargs): - """Create DashScope model via agno (native)""" + """Create DashScope model via agno""" try: from agno.models.dashscope import DashScope except ImportError: @@ -518,12 +518,11 @@ def create_model(self, model_id: Optional[str] = None, **kwargs): model_id = model_id or self.config.default_model params = {**self.config.parameters, **kwargs} - # Prefer native endpoint; ignore compatible-mode base_url if present + # Use configured base_url if present, otherwise let DashScope use its default + # agno's DashScope class has a default base_url for the compatible-mode endpoint base_url = self.config.base_url - if base_url and "compatible-mode" in base_url: - base_url = None - logger.info(f"Creating DashScope (native) model: {model_id}") + logger.info(f"Creating DashScope model: {model_id}") return DashScope( id=model_id, diff --git a/python/valuecell/core/super_agent/core.py b/python/valuecell/core/super_agent/core.py index 2f14d56d3..ae4df9ecb 100644 --- a/python/valuecell/core/super_agent/core.py +++ b/python/valuecell/core/super_agent/core.py @@ -54,6 +54,13 @@ def _get_or_init_agent(self) -> Optional[Agent]: """ def _build_agent(with_model) -> Agent: + # Disable session summaries for DashScope models + # DashScope requires 'json' word in messages when using response_format: json_object + # but agno's internal summary feature doesn't include this, causing 400 errors + enable_summaries = not model_utils_mod.model_should_use_json_mode( + with_model + ) + return Agent( model=with_model, markdown=False, @@ -67,7 +74,7 @@ def _build_agent(with_model) -> Agent: add_history_to_context=True, num_history_runs=5, read_chat_history=True, - enable_session_summaries=True, + enable_session_summaries=enable_summaries, ) try: diff --git a/python/valuecell/utils/model.py b/python/valuecell/utils/model.py index be452c30d..4e9e19bd5 100644 --- a/python/valuecell/utils/model.py +++ b/python/valuecell/utils/model.py @@ -13,6 +13,7 @@ from typing import Optional from agno.models.base import Model as AgnoModel +from agno.models.dashscope import DashScope as AgnoDashScopeModel from agno.models.google import Gemini as AgnoGeminiModel from agno.models.openai import OpenAIChat as AgnoOpenAIChatModel from agno.models.openai import OpenAILike as AgnoOpenAILikeModel @@ -51,6 +52,7 @@ def model_should_use_json_mode(model: AgnoModel) -> bool: - DeepSeek models (OpenAI-compatible but no structured outputs support) - OpenRouter models (third-party proxy, safer to use JSON mode) - SiliconFlow models (OpenAI-compatible but limited structured outputs support) + - DashScope models (requires 'json' in messages when using json_object format) - Other OpenAI-compatible APIs (safer default) """ try: @@ -91,6 +93,16 @@ def model_should_use_json_mode(model: AgnoModel) -> bool: logger.debug("Detected SiliconFlow model - using JSON mode") return True + # DashScope models - requires JSON mode + # DashScope's API requires 'json' word in messages when using response_format + if ( + AgnoDashScopeModel + and provider == AgnoDashScopeModel.provider + and name == AgnoDashScopeModel.name + ): + logger.debug("Detected DashScope model - using JSON mode") + return True + # OpenAI-compatible models (OpenAILike) - check base_url if ( AgnoOpenAILikeModel