Implement Plan A1: Fast Mode Analysis
Features: - Add analysis_mode parameter (fast/deep) to AnalysisRequest - Fast mode (15-25 min): Disables investment and risk debates (max_debate_rounds=0) - Deep mode (60 min): Default mode with debates enabled - Update backend TradingService to handle analysis_mode - Add analysis_mode form field to frontend with dropdown selector - Update TypeScript interfaces to include analysis_mode Changes: - backend/app/models/schemas.py: Add analysis_mode field to AnalysisRequest - backend/app/services/trading_service.py: Handle analysis_mode in create_config() - backend/app/api/routes.py: Pass analysis_mode parameter to run_analysis() - frontend/components/analysis/AnalysisForm.tsx: Add analysis_mode dropdown (fast/deep) - frontend/lib/types.ts: Add analysis_mode to AnalysisRequest interface When users select "fast mode", the system will: 1. Skip investment debate (max_debate_rounds = 0) 2. Skip risk debate (max_risk_discuss_rounds = 0) 3. Reduce analysis time from ~60 minutes to ~15-25 minutes 4. Still run all analyst reports with proper 500-1000 word counts 5. Provide initial decision without debate refinement Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a019896a9e
commit
9c0a9819e6
|
|
@ -141,6 +141,7 @@ async def run_analysis(
|
||||||
alpha_vantage_api_key=request.alpha_vantage_api_key or "",
|
alpha_vantage_api_key=request.alpha_vantage_api_key or "",
|
||||||
finmind_api_key=request.finmind_api_key or "",
|
finmind_api_key=request.finmind_api_key or "",
|
||||||
language=request.language or "zh-TW", # Pass language for agent reports
|
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
|
# Check for errors in result
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,10 @@ class AnalysisRequest(BaseModel):
|
||||||
default="zh-TW",
|
default="zh-TW",
|
||||||
description="Language for agent reports: 'en' for English, 'zh-TW' for Traditional Chinese"
|
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):
|
class PriceData(BaseModel):
|
||||||
"""Stock price data model"""
|
"""Stock price data model"""
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,33 @@ class TradingService:
|
||||||
research_depth: int = 1,
|
research_depth: int = 1,
|
||||||
deep_think_llm: str = "gpt-5-mini",
|
deep_think_llm: str = "gpt-5-mini",
|
||||||
quick_think_llm: str = "gpt-5-mini",
|
quick_think_llm: str = "gpt-5-mini",
|
||||||
|
analysis_mode: str = "deep",
|
||||||
) -> Dict[str, Any]:
|
) -> 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 = 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["deep_think_llm"] = deep_think_llm
|
||||||
config["quick_think_llm"] = quick_think_llm
|
config["quick_think_llm"] = quick_think_llm
|
||||||
config["results_dir"] = settings.results_dir
|
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
|
return config
|
||||||
|
|
||||||
async def run_analysis(
|
async def run_analysis(
|
||||||
|
|
@ -59,6 +78,7 @@ class TradingService:
|
||||||
deep_think_llm: str = "gpt-5-mini",
|
deep_think_llm: str = "gpt-5-mini",
|
||||||
quick_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'
|
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]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Run trading analysis for a given ticker and date with user-provided API keys
|
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
|
os.environ["OPENAI_API_KEY"] = openai_api_key
|
||||||
|
|
||||||
# Create configuration
|
# Create configuration
|
||||||
logger.info(f"Initializing TradingAgentsX for {ticker} on {analysis_date}")
|
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)
|
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)
|
# Normalize base URLs (ensure lowercase paths, common issue with custom endpoints)
|
||||||
def normalize_base_url(url: str) -> str:
|
def normalize_base_url(url: str) -> str:
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ const formSchema = z.object({
|
||||||
.regex(/^\d{4}-\d{2}-\d{2}$/, "日期格式必須為 YYYY-MM-DD"),
|
.regex(/^\d{4}-\d{2}-\d{2}$/, "日期格式必須為 YYYY-MM-DD"),
|
||||||
analysts: z.array(z.string()).min(1, "請至少選擇一位分析師"),
|
analysts: z.array(z.string()).min(1, "請至少選擇一位分析師"),
|
||||||
research_depth: z.number().int().min(1).max(5),
|
research_depth: z.number().int().min(1).max(5),
|
||||||
|
analysis_mode: z.enum(["fast", "deep"]).default("deep"),
|
||||||
quick_think_llm: z.string().min(1, "請選擇快速思維模型"),
|
quick_think_llm: z.string().min(1, "請選擇快速思維模型"),
|
||||||
deep_think_llm: z.string().min(1, "請選擇深層思維模型"),
|
deep_think_llm: z.string().min(1, "請選擇深層思維模型"),
|
||||||
embedding_model: 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"),
|
analysis_date: format(new Date(), "yyyy-MM-dd"),
|
||||||
analysts: ["market", "social", "news", "fundamentals"], // 預設全選
|
analysts: ["market", "social", "news", "fundamentals"], // 預設全選
|
||||||
research_depth: 3, // 預設中等層級
|
research_depth: 3, // 預設中等層級
|
||||||
|
analysis_mode: "deep", // 預設深層分析
|
||||||
market_type: "us", // 預設美股
|
market_type: "us", // 預設美股
|
||||||
quick_think_llm: "gpt-5-mini",
|
quick_think_llm: "gpt-5-mini",
|
||||||
deep_think_llm: "gpt-5-mini",
|
deep_think_llm: "gpt-5-mini",
|
||||||
|
|
@ -473,6 +475,35 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 分析模式行 */}
|
||||||
|
<div className="md:col-span-2 grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="analysis_mode"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>分析模式</FormLabel>
|
||||||
|
<Select
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
defaultValue={field.value}
|
||||||
|
>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="選擇分析模式" />
|
||||||
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="fast">快速分析 (~15-25 分鐘)</SelectItem>
|
||||||
|
<SelectItem value="deep">深層分析 (~1 小時)</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormDescription>快速模式跳過辯論,深層模式包含投資和風險辯論</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* 第二行:研究深度、快速思維模型、深層思維模型、嵌入式模型(4列) */}
|
{/* 第二行:研究深度、快速思維模型、深層思維模型、嵌入式模型(4列) */}
|
||||||
<div className="md:col-span-2 grid grid-cols-1 md:grid-cols-4 gap-6">
|
<div className="md:col-span-2 grid grid-cols-1 md:grid-cols-4 gap-6">
|
||||||
<FormField
|
<FormField
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export interface AnalysisRequest {
|
||||||
analysis_date: string;
|
analysis_date: string;
|
||||||
analysts?: string[];
|
analysts?: string[];
|
||||||
research_depth?: number;
|
research_depth?: number;
|
||||||
|
analysis_mode?: "fast" | "deep"; // Analysis mode: 'fast' (no debates) or 'deep' (with debates)
|
||||||
market_type?: "us" | "twse" | "tpex"; // 市場類型:美股、上市、上櫃/興櫃
|
market_type?: "us" | "twse" | "tpex"; // 市場類型:美股、上市、上櫃/興櫃
|
||||||
quick_think_llm?: string;
|
quick_think_llm?: string;
|
||||||
deep_think_llm?: string;
|
deep_think_llm?: string;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue