Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions python/valuecell/adapters/models/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion python/valuecell/core/super_agent/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions python/valuecell/utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down