Skip to content

TradingAgents: Multi-Agents LLM Financial Trading Framework

refactor: remove stale imports, use configurable results path (#499)

Yijia-Xiaobdb9c29d44a2
diff --git a/tradingagents/agents/analysts/fundamentals_analyst.py b/tradingagents/agents/analysts/fundamentals_analyst.py
index 3f70c734e..6aa49cf3b 100644
--- a/tradingagents/agents/analysts/fundamentals_analyst.py
+++ b/tradingagents/agents/analysts/fundamentals_analyst.py
@@ -1,6 +1,4 @@
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
-import time
-import json
from tradingagents.agents.utils.agent_utils import (
build_instrument_context,
get_balance_sheet,
diff --git a/tradingagents/agents/analysts/market_analyst.py b/tradingagents/agents/analysts/market_analyst.py
index 680f90190..fef8f7519 100644
--- a/tradingagents/agents/analysts/market_analyst.py
+++ b/tradingagents/agents/analysts/market_analyst.py
@@ -1,6 +1,4 @@
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
-import time
-import json
from tradingagents.agents.utils.agent_utils import (
build_instrument_context,
get_indicators,
diff --git a/tradingagents/agents/analysts/news_analyst.py b/tradingagents/agents/analysts/news_analyst.py
index 42fc7a619..e0fe93c5c 100644
--- a/tradingagents/agents/analysts/news_analyst.py
+++ b/tradingagents/agents/analysts/news_analyst.py
@@ -1,6 +1,4 @@
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
-import time
-import json
from tradingagents.agents.utils.agent_utils import (
build_instrument_context,
get_global_news,
diff --git a/tradingagents/agents/analysts/social_media_analyst.py b/tradingagents/agents/analysts/social_media_analyst.py
index 67d78f4c2..34a53c462 100644
--- a/tradingagents/agents/analysts/social_media_analyst.py
+++ b/tradingagents/agents/analysts/social_media_analyst.py
@@ -1,6 +1,4 @@
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
-import time
-import json
from tradingagents.agents.utils.agent_utils import build_instrument_context, get_language_instruction, get_news
from tradingagents.dataflows.config import get_config
diff --git a/tradingagents/agents/managers/research_manager.py b/tradingagents/agents/managers/research_manager.py
index 3ac4b1500..5b4b4fdc5 100644
--- a/tradingagents/agents/managers/research_manager.py
+++ b/tradingagents/agents/managers/research_manager.py
@@ -1,5 +1,3 @@
-import time
-import json
from tradingagents.agents.utils.agent_utils import build_instrument_context
diff --git a/tradingagents/agents/researchers/bear_researcher.py b/tradingagents/agents/researchers/bear_researcher.py
index 6634490a5..a44212dc4 100644
--- a/tradingagents/agents/researchers/bear_researcher.py
+++ b/tradingagents/agents/researchers/bear_researcher.py
@@ -1,6 +1,3 @@
-from langchain_core.messages import AIMessage
-import time
-import json
def create_bear_researcher(llm, memory):
diff --git a/tradingagents/agents/researchers/bull_researcher.py b/tradingagents/agents/researchers/bull_researcher.py
index b03ef7553..d23d4d76e 100644
--- a/tradingagents/agents/researchers/bull_researcher.py
+++ b/tradingagents/agents/researchers/bull_researcher.py
@@ -1,6 +1,3 @@
-from langchain_core.messages import AIMessage
-import time
-import json
def create_bull_researcher(llm, memory):
diff --git a/tradingagents/agents/risk_mgmt/aggressive_debator.py b/tradingagents/agents/risk_mgmt/aggressive_debator.py
index 651114a73..2dab1152a 100644
--- a/tradingagents/agents/risk_mgmt/aggressive_debator.py
+++ b/tradingagents/agents/risk_mgmt/aggressive_debator.py
@@ -1,5 +1,3 @@
-import time
-import json
def create_aggressive_debator(llm):
diff --git a/tradingagents/agents/risk_mgmt/conservative_debator.py b/tradingagents/agents/risk_mgmt/conservative_debator.py
index 7c8c0fd1e..99a8315e0 100644
--- a/tradingagents/agents/risk_mgmt/conservative_debator.py
+++ b/tradingagents/agents/risk_mgmt/conservative_debator.py
@@ -1,6 +1,3 @@
-from langchain_core.messages import AIMessage
-import time
-import json
def create_conservative_debator(llm):
diff --git a/tradingagents/agents/risk_mgmt/neutral_debator.py b/tradingagents/agents/risk_mgmt/neutral_debator.py
index 9ed490da4..e99ff0af1 100644
--- a/tradingagents/agents/risk_mgmt/neutral_debator.py
+++ b/tradingagents/agents/risk_mgmt/neutral_debator.py
@@ -1,5 +1,3 @@
-import time
-import json
def create_neutral_debator(llm):
diff --git a/tradingagents/agents/trader/trader.py b/tradingagents/agents/trader/trader.py
index 6298f239d..07e9f262c 100644
--- a/tradingagents/agents/trader/trader.py
+++ b/tradingagents/agents/trader/trader.py
@@ -1,6 +1,4 @@
import functools
-import time
-import json
from tradingagents.agents.utils.agent_utils import build_instrument_context
diff --git a/tradingagents/agents/utils/agent_states.py b/tradingagents/agents/utils/agent_states.py
index 813b00ee1..6423b9363 100644
--- a/tradingagents/agents/utils/agent_states.py
+++ b/tradingagents/agents/utils/agent_states.py
@@ -1,10 +1,6 @@
-from typing import Annotated, 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
+from typing import Annotated
+from typing_extensions import TypedDict
+from langgraph.graph import MessagesState
# Researcher team state
diff --git a/tradingagents/graph/reflection.py b/tradingagents/graph/reflection.py
index 85438595d..2a680038c 100644
--- a/tradingagents/graph/reflection.py
+++ b/tradingagents/graph/reflection.py
@@ -1,13 +1,12 @@
# TradingAgents/graph/reflection.py
-from typing import Dict, Any
-from langchain_openai import ChatOpenAI
+from typing import Any, Dict
class Reflector:
"""Handles reflection on decisions and updating memory."""
- def __init__(self, quick_thinking_llm: ChatOpenAI):
+ def __init__(self, quick_thinking_llm: Any):
"""Initialize the reflector with an LLM."""
self.quick_thinking_llm = quick_thinking_llm
self.reflection_system_prompt = self._get_reflection_prompt()
diff --git a/tradingagents/graph/setup.py b/tradingagents/graph/setup.py
index e0771c656..ae90489c1 100644
--- a/tradingagents/graph/setup.py
+++ b/tradingagents/graph/setup.py
@@ -1,8 +1,7 @@
# TradingAgents/graph/setup.py
-from typing import Dict, Any
-from langchain_openai import ChatOpenAI
-from langgraph.graph import END, StateGraph, START
+from typing import Any, Dict
+from langgraph.graph import END, START, StateGraph
from langgraph.prebuilt import ToolNode
from tradingagents.agents import *
@@ -16,8 +15,8 @@ class GraphSetup:
def __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,
diff --git a/tradingagents/graph/signal_processing.py b/tradingagents/graph/signal_processing.py
index f96c1efa3..5ac66c1dd 100644
--- a/tradingagents/graph/signal_processing.py
+++ b/tradingagents/graph/signal_processing.py
@@ -1,12 +1,12 @@
# TradingAgents/graph/signal_processing.py
-from langchain_openai import ChatOpenAI
+from typing import Any
class SignalProcessor:
"""Processes trading signals to extract actionable decisions."""
- def __init__(self, quick_thinking_llm: ChatOpenAI):
+ def __init__(self, quick_thinking_llm: Any):
"""Initialize with an LLM for processing."""
self.quick_thinking_llm = quick_thinking_llm
diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py
index c8cd74929..8e18f9c48 100644
--- a/tradingagents/graph/trading_graph.py
+++ b/tradingagents/graph/trading_graph.py
@@ -259,15 +259,12 @@ class TradingAgentsGraph:
}
# Save to file
- directory = Path(f"eval_results/{self.ticker}/TradingAgentsStrategy_logs/")
+ directory = Path(self.config["results_dir"]) / self.ticker / "TradingAgentsStrategy_logs"
directory.mkdir(parents=True, exist_ok=True)
- with open(
- f"eval_results/{self.ticker}/TradingAgentsStrategy_logs/full_states_log_{trade_date}.json",
- "w",
- encoding="utf-8",
- ) as f:
- json.dump(self.log_states_dict, f, indent=4)
+ log_path = directory / f"full_states_log_{trade_date}.json"
+ with open(log_path, "w", encoding="utf-8") as f:
+ json.dump(self.log_states_dict[str(trade_date)], f, indent=4)
def reflect_and_remember(self, returns_losses):
"""Reflect on decisions and update memory based on returns."""