From 747724048fa8e2ba31b718c45c38481722fab079 Mon Sep 17 00:00:00 2001 From: Count20 Date: Sat, 7 Feb 2026 09:32:42 +0100 Subject: [PATCH] fix: correct risk manager data bug, incomplete state init, and LLM type hints - Fix copy-paste bug in risk_manager.py where fundamentals_report was reading from news_report instead of fundamentals_report, causing the risk manager to ignore fundamentals data in its final decision - Initialize all TypedDict fields for InvestDebateState and RiskDebateState in propagation.py to prevent KeyError in _log_state - Update setup.py type hints from ChatOpenAI to ChatModel union type to correctly reflect multi-provider LLM support Co-Authored-By: Claude Opus 4.6 --- tradingagents/agents/managers/risk_manager.py | 2 +- tradingagents/graph/propagation.py | 14 +++++++++++++- tradingagents/graph/setup.py | 12 +++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tradingagents/agents/managers/risk_manager.py b/tradingagents/agents/managers/risk_manager.py index 9ed03e2d..1f2334cc 100644 --- a/tradingagents/agents/managers/risk_manager.py +++ b/tradingagents/agents/managers/risk_manager.py @@ -11,7 +11,7 @@ def create_risk_manager(llm, memory): risk_debate_state = state["risk_debate_state"] market_research_report = state["market_report"] news_report = state["news_report"] - fundamentals_report = state["news_report"] + fundamentals_report = state["fundamentals_report"] sentiment_report = state["sentiment_report"] trader_plan = state["investment_plan"] diff --git a/tradingagents/graph/propagation.py b/tradingagents/graph/propagation.py index 7aba5258..0fd10c0c 100644 --- a/tradingagents/graph/propagation.py +++ b/tradingagents/graph/propagation.py @@ -24,14 +24,26 @@ class Propagator: "company_of_interest": company_name, "trade_date": str(trade_date), "investment_debate_state": InvestDebateState( - {"history": "", "current_response": "", "count": 0} + { + "bull_history": "", + "bear_history": "", + "history": "", + "current_response": "", + "judge_decision": "", + "count": 0, + } ), "risk_debate_state": RiskDebateState( { + "aggressive_history": "", + "conservative_history": "", + "neutral_history": "", "history": "", + "latest_speaker": "", "current_aggressive_response": "", "current_conservative_response": "", "current_neutral_response": "", + "judge_decision": "", "count": 0, } ), diff --git a/tradingagents/graph/setup.py b/tradingagents/graph/setup.py index 772efe7f..720aaa84 100644 --- a/tradingagents/graph/setup.py +++ b/tradingagents/graph/setup.py @@ -1,7 +1,10 @@ # TradingAgents/graph/setup.py -from typing import Dict, Any +from typing import Any, Dict, Union + from langchain_openai import ChatOpenAI +from langchain_anthropic import ChatAnthropic +from langchain_google_genai import ChatGoogleGenerativeAI from langgraph.graph import END, StateGraph, START from langgraph.prebuilt import ToolNode @@ -10,14 +13,17 @@ from tradingagents.agents.utils.agent_states import AgentState from .conditional_logic import ConditionalLogic +# Union of supported LLM chat model types +ChatModel = Union[ChatOpenAI, ChatAnthropic, ChatGoogleGenerativeAI] + class GraphSetup: """Handles the setup and configuration of the agent graph.""" def __init__( self, - quick_thinking_llm: ChatOpenAI, - deep_thinking_llm: ChatOpenAI, + quick_thinking_llm: ChatModel, + deep_thinking_llm: ChatModel, tool_nodes: Dict[str, ToolNode], bull_memory, bear_memory,