diff --git a/backend/app/api/routes.py b/backend/app/api/routes.py index 0b2a9ded..4144054e 100644 --- a/backend/app/api/routes.py +++ b/backend/app/api/routes.py @@ -141,6 +141,7 @@ async def run_analysis( alpha_vantage_api_key=request.alpha_vantage_api_key or "", finmind_api_key=request.finmind_api_key or "", language=request.language or "zh-TW", # Pass language for agent reports + analysis_mode=request.analysis_mode or "deep", # Pass analysis mode (fast or deep) )) # Check for errors in result diff --git a/backend/app/models/schemas.py b/backend/app/models/schemas.py index 1cc99a6e..8a75c746 100644 --- a/backend/app/models/schemas.py +++ b/backend/app/models/schemas.py @@ -67,6 +67,10 @@ class AnalysisRequest(BaseModel): default="zh-TW", description="Language for agent reports: 'en' for English, 'zh-TW' for Traditional Chinese" ) + analysis_mode: Optional[Literal["fast", "deep"]] = Field( + default="deep", + description="Analysis mode: 'fast' (no debates, ~15-25 min) or 'deep' (with debates, ~1 hour)" + ) class PriceData(BaseModel): """Stock price data model""" diff --git a/backend/app/services/trading_service.py b/backend/app/services/trading_service.py index 2f135009..e6b7806b 100644 --- a/backend/app/services/trading_service.py +++ b/backend/app/services/trading_service.py @@ -28,14 +28,33 @@ class TradingService: research_depth: int = 1, deep_think_llm: str = "gpt-5-mini", quick_think_llm: str = "gpt-5-mini", + analysis_mode: str = "deep", ) -> Dict[str, Any]: - """Create configuration for TradingAgentsX""" + """Create configuration for TradingAgentsX + + Args: + research_depth: Research depth (1-5) + deep_think_llm: Deep thinking LLM model + quick_think_llm: Quick thinking LLM model + analysis_mode: "fast" (no debates) or "deep" (with debates) + """ config = self.default_config.copy() - config["max_debate_rounds"] = research_depth - config["max_risk_discuss_rounds"] = research_depth config["deep_think_llm"] = deep_think_llm config["quick_think_llm"] = quick_think_llm config["results_dir"] = settings.results_dir + + # Handle analysis mode + if analysis_mode == "fast": + # Fast mode: disable debates entirely + config["max_debate_rounds"] = 0 + config["max_risk_discuss_rounds"] = 0 + logger.info("Analysis mode: FAST (debates disabled)") + else: + # Deep mode: use research_depth for debate rounds + config["max_debate_rounds"] = research_depth + config["max_risk_discuss_rounds"] = research_depth + logger.info(f"Analysis mode: DEEP (research_depth={research_depth})") + return config async def run_analysis( @@ -59,6 +78,7 @@ class TradingService: deep_think_llm: str = "gpt-5-mini", quick_think_llm: str = "gpt-5-mini", language: str = "zh-TW", # Language for agent reports: 'en' or 'zh-TW' + analysis_mode: str = "deep", # Analysis mode: 'fast' (no debates) or 'deep' (with debates) ) -> Dict[str, Any]: """ Run trading analysis for a given ticker and date with user-provided API keys @@ -106,8 +126,8 @@ class TradingService: os.environ["OPENAI_API_KEY"] = openai_api_key # Create configuration - logger.info(f"Initializing TradingAgentsX for {ticker} on {analysis_date}") - config = self.create_config(research_depth, deep_think_llm, quick_think_llm) + logger.info(f"Initializing TradingAgentsX for {ticker} on {analysis_date} (mode={analysis_mode})") + config = self.create_config(research_depth, deep_think_llm, quick_think_llm, analysis_mode) # Normalize base URLs (ensure lowercase paths, common issue with custom endpoints) def normalize_base_url(url: str) -> str: diff --git a/frontend/components/analysis/AnalysisForm.tsx b/frontend/components/analysis/AnalysisForm.tsx index 31386ecb..b9d032a9 100644 --- a/frontend/components/analysis/AnalysisForm.tsx +++ b/frontend/components/analysis/AnalysisForm.tsx @@ -52,6 +52,7 @@ const formSchema = z.object({ .regex(/^\d{4}-\d{2}-\d{2}$/, "日期格式必須為 YYYY-MM-DD"), analysts: z.array(z.string()).min(1, "請至少選擇一位分析師"), research_depth: z.number().int().min(1).max(5), + analysis_mode: z.enum(["fast", "deep"]).default("deep"), quick_think_llm: z.string().min(1, "請選擇快速思維模型"), deep_think_llm: z.string().min(1, "請選擇深層思維模型"), embedding_model: z.string().min(1, "請選擇嵌入式模型"), @@ -111,6 +112,7 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { analysis_date: format(new Date(), "yyyy-MM-dd"), analysts: ["market", "social", "news", "fundamentals"], // 預設全選 research_depth: 3, // 預設中等層級 + analysis_mode: "deep", // 預設深層分析 market_type: "us", // 預設美股 quick_think_llm: "gpt-5-mini", deep_think_llm: "gpt-5-mini", @@ -473,6 +475,35 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { /> + {/* 分析模式行 */} +