TradingAgents/tradingagents/agents/utils/agent_states.py

97 lines
4.9 KiB
Python

from typing import Annotated, Dict, List, Sequence
from datetime import date, timedelta, datetime
from typing_extensions import TypedDict, Optional
from langchain_openai import ChatOpenAI
from tradingagents.agents import *
from langgraph.prebuilt import ToolNode
from langgraph.graph import END, StateGraph, START, MessagesState
# Researcher team state
class InvestDebateState(TypedDict):
bull_history: Annotated[
str, "Bullish Conversation history"
] # Bullish Conversation history
bear_history: Annotated[
str, "Bearish Conversation history"
] # Bullish Conversation history
history: Annotated[str, "Conversation history"] # Conversation history
current_response: Annotated[str, "Latest response"] # Last response
judge_decision: Annotated[str, "Final judge decision"] # Last response
count: Annotated[int, "Length of the current conversation"] # Conversation length
# Risk management team state
class RiskDebateState(TypedDict):
risky_history: Annotated[
str, "Risky Agent's Conversation history"
] # Conversation history
safe_history: Annotated[
str, "Safe Agent's Conversation history"
] # Conversation history
neutral_history: Annotated[
str, "Neutral Agent's Conversation history"
] # Conversation history
history: Annotated[str, "Conversation history"] # Conversation history
latest_speaker: Annotated[str, "Analyst that spoke last"]
current_risky_response: Annotated[
str, "Latest response by the risky analyst"
] # Last response
current_safe_response: Annotated[
str, "Latest response by the safe analyst"
] # Last response
current_neutral_response: Annotated[
str, "Latest response by the neutral analyst"
] # Last response
judge_decision: Annotated[str, "Judge's decision"]
count: Annotated[int, "Length of the current conversation"] # Conversation length
class AgentState(MessagesState):
company_of_interest: Annotated[str, "Company that we are interested in trading"]
trade_date: Annotated[str, "What date we are trading at"]
target_ticker: Annotated[str, "Ticker selected by the orchestrator for deep analysis"]
sender: Annotated[str, "Agent that sent this message"]
# research step
market_report: Annotated[str, "Report from the Market Analyst"]
sentiment_report: Annotated[str, "Report from the Social Media Analyst"]
news_report: Annotated[
str, "Report from the News Researcher of current world affairs"
]
fundamentals_report: Annotated[str, "Report from the Fundamentals Researcher"]
# researcher team discussion step
investment_debate_state: Annotated[
InvestDebateState, "Current state of the debate on if to invest or not"
]
investment_plan: Annotated[str, "Plan generated by the Analyst"]
trader_investment_plan: Annotated[str, "Plan generated by the Trader"]
# risk management team discussion step
risk_debate_state: Annotated[
RiskDebateState, "Current state of the debate on evaluating risk"
]
final_trade_decision: Annotated[str, "Final decision made by the Risk Analysts"]
portfolio_profile: Annotated[Dict[str, object], "Static portfolio configuration"]
portfolio_summary: Annotated[str, "Orchestrator briefing for the run"]
orchestrator_status: Annotated[str, "Status message produced by the orchestrator"]
alpaca_account_text: Annotated[str, "Raw Alpaca account summary text"]
alpaca_positions_text: Annotated[str, "Raw Alpaca positions text"]
alpaca_orders_text: Annotated[str, "Raw Alpaca recent orders text"]
orchestrator_hypotheses: Annotated[List[Dict[str, object]], "List of active hypotheses evaluated by the orchestrator"]
active_hypothesis: Annotated[Optional[Dict[str, object]], "The hypothesis currently under deep analysis"]
scheduled_analysts: Annotated[List[str], "Analyst roles the orchestrator requested to run for the active hypothesis"]
scheduled_analysts_plan: Annotated[List[str], "Full list of orchestrator-requested analysts for this cycle"]
orchestrator_action: Annotated[str, "Immediate action directive from the orchestrator for the active hypothesis"]
action_queue: Annotated[List[str], "Actions queued by the orchestrator for execution"]
next_directive: Annotated[str, "Directive for the scheduler when the queue is empty"]
next_node: Annotated[str, "Next node selected by the action scheduler"]
portfolio_account_summary: Annotated[Dict[str, object], "Parsed Alpaca account summary used by the orchestrator"]
portfolio_positions_summary: Annotated[List[Dict[str, object]], "Parsed Alpaca positions summary used by the orchestrator"]
planner_plan: Annotated[Dict[str, object], "Raw plan response produced by the sequential planner"]
planner_notes: Annotated[str, "Notes or commentary returned by the sequential planner"]
orchestrator_focus_override: Annotated[List[str], "Optional override forcing orchestrator to focus on specific tickers"]