TradingAgents: Multi-Agents LLM Financial Trading Framework
Merge remote-tracking branch 'upstream/main' into analyst-phase1-observability
CadeYu249caba06fde
diff --cc cli/main.pyindex 7ac3af636,043c2311f..d6683e88b--- a/cli/main.py+++ b/cli/main.py@@@ -1067,35 -1083,27 +1098,31 @@@ def run_analysis(checkpoint: bool = Fal# Stream the analysistrace = []for chunk in graph.graph.stream(init_agent_state, **args):- # Process messages if present (skip duplicates via message ID)- if len(chunk["messages"]) > 0:- last_message = chunk["messages"][-1]- msg_id = getattr(last_message, "id", None)-- if msg_id != message_buffer._last_message_id:- message_buffer._last_message_id = msg_id-- # Add message to buffer- msg_type, content = classify_message_type(last_message)- if content and content.strip():- message_buffer.add_message(msg_type, content)-- # Handle tool calls- if hasattr(last_message, "tool_calls") and last_message.tool_calls:- for tool_call in last_message.tool_calls:- if isinstance(tool_call, dict):- message_buffer.add_tool_call(- tool_call["name"], tool_call["args"]- )- else:- message_buffer.add_tool_call(tool_call.name, tool_call.args)+ # Process all messages in chunk, deduplicating by message ID+ for message in chunk.get("messages", []):+ msg_id = getattr(message, "id", None)+ if msg_id is not None:+ if msg_id in message_buffer._processed_message_ids:+ continue+ message_buffer._processed_message_ids.add(msg_id)++ msg_type, content = classify_message_type(message)+ if content and content.strip():+ message_buffer.add_message(msg_type, content)++ if hasattr(message, "tool_calls") and message.tool_calls:+ for tool_call in message.tool_calls:+ if isinstance(tool_call, dict):+ message_buffer.add_tool_call(tool_call["name"], tool_call["args"])+ else:+ message_buffer.add_tool_call(tool_call.name, tool_call.args)# Update analyst statuses based on report state (runs on every chunk)- update_analyst_statuses(message_buffer, chunk)+ update_analyst_statuses(+ message_buffer,+ chunk,+ wall_time_tracker=analyst_wall_time_tracker,+ )# Research Team - Handle Investment Debate Stateif chunk.get("investment_debate_state"):diff --cc tradingagents/default_config.pyindex 9fb318c1b,fe5a6f755..b61b49ba1--- a/tradingagents/default_config.py+++ b/tradingagents/default_config.py@@@ -23,7 -73,21 +73,22 @@@ DEFAULT_CONFIG = _apply_env_overrides("max_debate_rounds": 1,"max_risk_discuss_rounds": 1,"max_recur_limit": 100,+ "analyst_concurrency_limit": 1,+ # News / data fetching parameters+ # Increase for longer lookback strategies or to broaden macro coverage;+ # decrease to reduce token usage in agent prompts.+ "news_article_limit": 20, # max articles per ticker (ticker-news)+ "global_news_article_limit": 10, # max articles for global/macro news+ "global_news_lookback_days": 7, # macro news lookback window+ # Search queries used by get_global_news for macro headlines. Extend or+ # replace to broaden geographic / sector coverage.+ "global_news_queries": [+ "Federal Reserve interest rates inflation",+ "S&P 500 earnings GDP economic outlook",+ "geopolitical risk trade war sanctions",+ "ECB Bank of England BOJ central bank policy",+ "oil commodities supply chain energy",+ ],# Data vendor configuration# Category-level configuration (default for all tools in category)"data_vendors": {diff --cc tradingagents/graph/setup.pyindex 4e16a743d,3d328c89f..1e6b4da72--- a/tradingagents/graph/setup.py+++ b/tradingagents/graph/setup.py@@@ -17,28 -15,16 +16,18 @@@ class GraphSetupdef __init__(self,- quick_thinking_llm: ChatOpenAI,- deep_thinking_llm: ChatOpenAI,+ quick_thinking_llm: Any,+ deep_thinking_llm: Any,tool_nodes: Dict[str, ToolNode],- bull_memory,- bear_memory,- trader_memory,- invest_judge_memory,- portfolio_manager_memory,conditional_logic: ConditionalLogic,+ analyst_concurrency_limit: int = 1,):"""Initialize with required components."""self.quick_thinking_llm = quick_thinking_llmself.deep_thinking_llm = deep_thinking_llmself.tool_nodes = tool_nodes- self.bull_memory = bull_memory- self.bear_memory = bear_memory- self.trader_memory = trader_memory- self.invest_judge_memory = invest_judge_memory- self.portfolio_manager_memory = portfolio_manager_memoryself.conditional_logic = conditional_logic+ self.analyst_concurrency_limit = analyst_concurrency_limitdef setup_graph(self, selected_analysts=["market", "social", "news", "fundamentals"]@@@ -52,29 -38,51 +41,23 @@@- "news": News analyst- "fundamentals": Fundamentals analyst"""- if len(selected_analysts) == 0:- raise ValueError("Trading Agents Graph Setup Error: no analysts selected!")-- # Create analyst nodes- analyst_nodes = {}- delete_nodes = {}- tool_nodes = {}-- if "market" in selected_analysts:- analyst_nodes["market"] = create_market_analyst(- self.quick_thinking_llm- )- delete_nodes["market"] = create_msg_delete()- tool_nodes["market"] = self.tool_nodes["market"]-- if "social" in selected_analysts:- # "social" selector key preserved for back-compat with existing- # user configs; the underlying agent has been renamed to- # sentiment_analyst (the old name advertised social-media data- # the agent never had access to — see issue #557).- analyst_nodes["social"] = create_sentiment_analyst(- self.quick_thinking_llm- )- delete_nodes["social"] = create_msg_delete()- tool_nodes["social"] = self.tool_nodes["social"]-- if "news" in selected_analysts:- analyst_nodes["news"] = create_news_analyst(- self.quick_thinking_llm- )- delete_nodes["news"] = create_msg_delete()- tool_nodes["news"] = self.tool_nodes["news"]+ plan = build_analyst_execution_plan(+ selected_analysts,+ concurrency_limit=self.analyst_concurrency_limit,+ )- if "fundamentals" in selected_analysts:- analyst_nodes["fundamentals"] = create_fundamentals_analyst(- self.quick_thinking_llm- )- delete_nodes["fundamentals"] = create_msg_delete()- tool_nodes["fundamentals"] = self.tool_nodes["fundamentals"]+ analyst_factories = {+ "market": lambda: create_market_analyst(self.quick_thinking_llm),- "social": lambda: create_social_media_analyst(self.quick_thinking_llm),++ "social": lambda: create_sentiment_analyst(self.quick_thinking_llm),+ "news": lambda: create_news_analyst(self.quick_thinking_llm),+ "fundamentals": lambda: create_fundamentals_analyst(self.quick_thinking_llm),+ }# Create researcher and manager nodes- bull_researcher_node = create_bull_researcher(- self.quick_thinking_llm, self.bull_memory- )- bear_researcher_node = create_bear_researcher(- self.quick_thinking_llm, self.bear_memory- )- research_manager_node = create_research_manager(- self.deep_thinking_llm, self.invest_judge_memory- )- trader_node = create_trader(self.quick_thinking_llm, self.trader_memory)+ bull_researcher_node = create_bull_researcher(self.quick_thinking_llm)+ bear_researcher_node = create_bear_researcher(self.quick_thinking_llm)+ research_manager_node = create_research_manager(self.deep_thinking_llm)+ trader_node = create_trader(self.quick_thinking_llm)# Create risk analysis nodesaggressive_analyst = create_aggressive_debator(self.quick_thinking_llm)diff --cc tradingagents/graph/trading_graph.pyindex c5423f61b,949dbf654..8a694b0ba--- a/tradingagents/graph/trading_graph.py+++ b/tradingagents/graph/trading_graph.py@@@ -113,16 -113,12 +113,13 @@@ class TradingAgentsGraphself.quick_thinking_llm,self.deep_thinking_llm,self.tool_nodes,- self.bull_memory,- self.bear_memory,- self.trader_memory,- self.invest_judge_memory,- self.portfolio_manager_memory,self.conditional_logic,+ analyst_concurrency_limit=self.config.get("analyst_concurrency_limit", 1),)- self.propagator = Propagator()+ self.propagator = Propagator(+ max_recur_limit=self.config.get("max_recur_limit", 100),+ )self.reflector = Reflector(self.quick_thinking_llm)self.signal_processor = SignalProcessor(self.quick_thinking_llm)