From 3bed14e5c149931959718362f2b1f8b26f1c2255 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 21 Mar 2026 08:30:43 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20fix:=20remove=20unused=20imports?= =?UTF-8?q?=20from=20agent=5Futils.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed re-exported tool imports from `tradingagents/agents/utils/agent_utils.py` to declutter the file and prevent unnecessary dependency loading. Updated all downstream modules (tests, analysts, scanners, and the trading graph) to import the required tools directly from their respective source files in `tradingagents/agents/utils/`. Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com> --- tests/unit/test_config_wiring.py | 10 +++---- .../agents/analysts/fundamentals_analyst.py | 4 +-- .../agents/analysts/market_analyst.py | 4 ++- tradingagents/agents/analysts/news_analyst.py | 2 +- .../agents/analysts/social_media_analyst.py | 2 +- .../agents/scanners/geopolitical_scanner.py | 2 +- .../agents/scanners/industry_deep_dive.py | 2 +- .../agents/scanners/market_movers_scanner.py | 2 +- .../agents/scanners/sector_scanner.py | 2 +- tradingagents/agents/utils/agent_utils.py | 30 ------------------- tradingagents/graph/trading_graph.py | 16 +++++----- 11 files changed, 25 insertions(+), 51 deletions(-) diff --git a/tests/unit/test_config_wiring.py b/tests/unit/test_config_wiring.py index 15e9bc4d..2258b317 100644 --- a/tests/unit/test_config_wiring.py +++ b/tests/unit/test_config_wiring.py @@ -24,26 +24,26 @@ class TestAgentStateFields: class TestNewToolsExported: def test_get_ttm_analysis_exported(self): - from tradingagents.agents.utils.agent_utils import get_ttm_analysis + from tradingagents.agents.utils.fundamental_data_tools import get_ttm_analysis # @tool returns a LangChain StructuredTool — callable() is False on it. # hasattr(..., "invoke") is the correct check for LangChain tools. assert hasattr(get_ttm_analysis, "invoke") def test_get_peer_comparison_exported(self): - from tradingagents.agents.utils.agent_utils import get_peer_comparison + from tradingagents.agents.utils.fundamental_data_tools import get_peer_comparison assert hasattr(get_peer_comparison, "invoke") def test_get_sector_relative_exported(self): - from tradingagents.agents.utils.agent_utils import get_sector_relative + from tradingagents.agents.utils.fundamental_data_tools import get_sector_relative assert hasattr(get_sector_relative, "invoke") def test_get_macro_regime_exported(self): - from tradingagents.agents.utils.agent_utils import get_macro_regime + from tradingagents.agents.utils.fundamental_data_tools import get_macro_regime assert hasattr(get_macro_regime, "invoke") def test_tools_are_langchain_tools(self): """All new tools should be LangChain @tool decorated (have .name attribute).""" - from tradingagents.agents.utils.agent_utils import ( + from tradingagents.agents.utils.fundamental_data_tools import ( get_ttm_analysis, get_peer_comparison, get_sector_relative, get_macro_regime ) for tool in [get_ttm_analysis, get_peer_comparison, get_sector_relative, get_macro_regime]: diff --git a/tradingagents/agents/analysts/fundamentals_analyst.py b/tradingagents/agents/analysts/fundamentals_analyst.py index 108b6d3e..8749b4cd 100644 --- a/tradingagents/agents/analysts/fundamentals_analyst.py +++ b/tradingagents/agents/analysts/fundamentals_analyst.py @@ -1,16 +1,16 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder import time import json -from tradingagents.agents.utils.agent_utils import ( +from tradingagents.agents.utils.fundamental_data_tools import ( get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement, - get_insider_transactions, get_ttm_analysis, get_peer_comparison, get_sector_relative, ) +from tradingagents.agents.utils.news_data_tools import get_insider_transactions from tradingagents.dataflows.config import get_config diff --git a/tradingagents/agents/analysts/market_analyst.py b/tradingagents/agents/analysts/market_analyst.py index 6d4afe3e..65abd9ea 100644 --- a/tradingagents/agents/analysts/market_analyst.py +++ b/tradingagents/agents/analysts/market_analyst.py @@ -1,7 +1,9 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder import time import json -from tradingagents.agents.utils.agent_utils import get_stock_data, get_indicators, get_macro_regime +from tradingagents.agents.utils.core_stock_tools import get_stock_data +from tradingagents.agents.utils.technical_indicators_tools import get_indicators +from tradingagents.agents.utils.fundamental_data_tools import get_macro_regime from tradingagents.dataflows.config import get_config diff --git a/tradingagents/agents/analysts/news_analyst.py b/tradingagents/agents/analysts/news_analyst.py index 03b4fae4..27c7c3d1 100644 --- a/tradingagents/agents/analysts/news_analyst.py +++ b/tradingagents/agents/analysts/news_analyst.py @@ -1,7 +1,7 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder import time import json -from tradingagents.agents.utils.agent_utils import get_news, get_global_news +from tradingagents.agents.utils.news_data_tools import get_news, get_global_news from tradingagents.dataflows.config import get_config diff --git a/tradingagents/agents/analysts/social_media_analyst.py b/tradingagents/agents/analysts/social_media_analyst.py index b25712d7..82089443 100644 --- a/tradingagents/agents/analysts/social_media_analyst.py +++ b/tradingagents/agents/analysts/social_media_analyst.py @@ -1,7 +1,7 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder import time import json -from tradingagents.agents.utils.agent_utils import get_news +from tradingagents.agents.utils.news_data_tools import get_news from tradingagents.dataflows.config import get_config diff --git a/tradingagents/agents/scanners/geopolitical_scanner.py b/tradingagents/agents/scanners/geopolitical_scanner.py index afa5d3ce..98075b19 100644 --- a/tradingagents/agents/scanners/geopolitical_scanner.py +++ b/tradingagents/agents/scanners/geopolitical_scanner.py @@ -1,5 +1,5 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder -from tradingagents.agents.utils.agent_utils import get_topic_news +from tradingagents.agents.utils.scanner_tools import get_topic_news from tradingagents.agents.utils.tool_runner import run_tool_loop diff --git a/tradingagents/agents/scanners/industry_deep_dive.py b/tradingagents/agents/scanners/industry_deep_dive.py index 3b15cf4f..06bc0ac7 100644 --- a/tradingagents/agents/scanners/industry_deep_dive.py +++ b/tradingagents/agents/scanners/industry_deep_dive.py @@ -1,7 +1,7 @@ from __future__ import annotations from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder -from tradingagents.agents.utils.agent_utils import get_industry_performance, get_topic_news +from tradingagents.agents.utils.scanner_tools import get_industry_performance, get_topic_news from tradingagents.agents.utils.tool_runner import run_tool_loop # All valid sector keys accepted by yfinance Sector() and get_industry_performance. diff --git a/tradingagents/agents/scanners/market_movers_scanner.py b/tradingagents/agents/scanners/market_movers_scanner.py index 219a5adf..1fb85244 100644 --- a/tradingagents/agents/scanners/market_movers_scanner.py +++ b/tradingagents/agents/scanners/market_movers_scanner.py @@ -1,5 +1,5 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder -from tradingagents.agents.utils.agent_utils import get_market_movers, get_market_indices +from tradingagents.agents.utils.scanner_tools import get_market_movers, get_market_indices from tradingagents.agents.utils.tool_runner import run_tool_loop diff --git a/tradingagents/agents/scanners/sector_scanner.py b/tradingagents/agents/scanners/sector_scanner.py index f66782af..4e1e41b7 100644 --- a/tradingagents/agents/scanners/sector_scanner.py +++ b/tradingagents/agents/scanners/sector_scanner.py @@ -1,5 +1,5 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder -from tradingagents.agents.utils.agent_utils import get_sector_performance +from tradingagents.agents.utils.scanner_tools import get_sector_performance from tradingagents.agents.utils.tool_runner import run_tool_loop diff --git a/tradingagents/agents/utils/agent_utils.py b/tradingagents/agents/utils/agent_utils.py index 32ad548d..892c2365 100644 --- a/tradingagents/agents/utils/agent_utils.py +++ b/tradingagents/agents/utils/agent_utils.py @@ -1,35 +1,5 @@ from langchain_core.messages import HumanMessage, RemoveMessage -# Import tools from separate utility files -from tradingagents.agents.utils.core_stock_tools import ( - get_stock_data -) -from tradingagents.agents.utils.technical_indicators_tools import ( - get_indicators -) -from tradingagents.agents.utils.fundamental_data_tools import ( - get_fundamentals, - get_balance_sheet, - get_cashflow, - get_income_statement, - get_ttm_analysis, - get_peer_comparison, - get_sector_relative, - get_macro_regime, -) -from tradingagents.agents.utils.news_data_tools import ( - get_news, - get_insider_transactions, - get_global_news -) -from tradingagents.agents.utils.scanner_tools import ( - get_market_movers, - get_market_indices, - get_sector_performance, - get_industry_performance, - get_topic_news -) - def create_msg_delete(): def delete_messages(state): diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index 7119e6ad..474315c3 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -20,22 +20,24 @@ from tradingagents.agents.utils.agent_states import ( ) from tradingagents.dataflows.config import set_config -# Import the new abstract tool methods from agent_utils -from tradingagents.agents.utils.agent_utils import ( - get_stock_data, - get_indicators, +# Import the new abstract tool methods +from tradingagents.agents.utils.core_stock_tools import get_stock_data +from tradingagents.agents.utils.technical_indicators_tools import get_indicators +from tradingagents.agents.utils.fundamental_data_tools import ( get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement, - get_news, - get_insider_transactions, - get_global_news, get_ttm_analysis, get_peer_comparison, get_sector_relative, get_macro_regime, ) +from tradingagents.agents.utils.news_data_tools import ( + get_news, + get_insider_transactions, + get_global_news, +) from .conditional_logic import ConditionalLogic from .setup import GraphSetup