mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-06-17 05:16:14 +03:00
- analyst_execution.py: rename "Social Analyst" / "Msg Clear Social" to "Sentiment Analyst" / "Msg Clear Sentiment" to match v0.2.5. - conditional_logic.should_continue_social returns the renamed route. - TradingAgentsGraph.propagate accepts asset_type and threads through to Propagator.create_initial_state. - Regression test on the Sentiment Analyst label. Verified end-to-end (NVDA stock + BTC-USD crypto) on gpt-5.4-mini.
74 lines
2.9 KiB
Python
74 lines
2.9 KiB
Python
# TradingAgents/graph/conditional_logic.py
|
|
|
|
from tradingagents.agents.utils.agent_states import AgentState
|
|
|
|
|
|
class ConditionalLogic:
|
|
"""Handles conditional logic for determining graph flow."""
|
|
|
|
def __init__(self, max_debate_rounds=1, max_risk_discuss_rounds=1):
|
|
"""Initialize with configuration parameters."""
|
|
self.max_debate_rounds = max_debate_rounds
|
|
self.max_risk_discuss_rounds = max_risk_discuss_rounds
|
|
|
|
def should_continue_market(self, state: AgentState):
|
|
"""Determine if market analysis should continue."""
|
|
messages = state["messages"]
|
|
last_message = messages[-1]
|
|
if last_message.tool_calls:
|
|
return "tools_market"
|
|
return "Msg Clear Market"
|
|
|
|
def should_continue_social(self, state: AgentState):
|
|
"""Determine if sentiment-analyst tool round should continue.
|
|
|
|
Method name keeps the legacy ``social`` suffix to match the
|
|
``AnalystType.SOCIAL = "social"`` wire value (saved-config
|
|
back-compat); the returned ``clear_node`` label uses the v0.2.5
|
|
rename so it matches the node registered by the execution plan.
|
|
"""
|
|
messages = state["messages"]
|
|
last_message = messages[-1]
|
|
if last_message.tool_calls:
|
|
return "tools_social"
|
|
return "Msg Clear Sentiment"
|
|
|
|
def should_continue_news(self, state: AgentState):
|
|
"""Determine if news analysis should continue."""
|
|
messages = state["messages"]
|
|
last_message = messages[-1]
|
|
if last_message.tool_calls:
|
|
return "tools_news"
|
|
return "Msg Clear News"
|
|
|
|
def should_continue_fundamentals(self, state: AgentState):
|
|
"""Determine if fundamentals analysis should continue."""
|
|
messages = state["messages"]
|
|
last_message = messages[-1]
|
|
if last_message.tool_calls:
|
|
return "tools_fundamentals"
|
|
return "Msg Clear Fundamentals"
|
|
|
|
def should_continue_debate(self, state: AgentState) -> str:
|
|
"""Determine if debate should continue."""
|
|
|
|
if (
|
|
state["investment_debate_state"]["count"] >= 2 * self.max_debate_rounds
|
|
): # 3 rounds of back-and-forth between 2 agents
|
|
return "Research Manager"
|
|
if state["investment_debate_state"]["current_response"].startswith("Bull"):
|
|
return "Bear Researcher"
|
|
return "Bull Researcher"
|
|
|
|
def should_continue_risk_analysis(self, state: AgentState) -> str:
|
|
"""Determine if risk analysis should continue."""
|
|
if (
|
|
state["risk_debate_state"]["count"] >= 3 * self.max_risk_discuss_rounds
|
|
): # 3 rounds of back-and-forth between 3 agents
|
|
return "Portfolio Manager"
|
|
if state["risk_debate_state"]["latest_speaker"].startswith("Aggressive"):
|
|
return "Conservative Analyst"
|
|
if state["risk_debate_state"]["latest_speaker"].startswith("Conservative"):
|
|
return "Neutral Analyst"
|
|
return "Aggressive Analyst"
|