fix: use run_tool_loop instead of invoke in analyst agents
This commit updates the `fundamentals_analyst`, `market_analyst`, `social_media_analyst`, and `news_analyst` files to use `run_tool_loop` instead of `.invoke()`. Using `.invoke()` resulted in the LLM execution stopping immediately upon a tool call request without executing the tool, returning an empty report or raw JSON. The `run_tool_loop` function ensures tools are executed recursively and the final text content is returned. Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
This commit is contained in:
parent
5bdd42f818
commit
9cf3a023fa
|
|
@ -11,6 +11,7 @@ from tradingagents.agents.utils.fundamental_data_tools import (
|
|||
get_sector_relative,
|
||||
)
|
||||
from tradingagents.agents.utils.news_data_tools import get_insider_transactions
|
||||
from tradingagents.agents.utils.tool_runner import run_tool_loop
|
||||
from tradingagents.dataflows.config import get_config
|
||||
|
||||
|
||||
|
|
@ -66,12 +67,9 @@ def create_fundamentals_analyst(llm):
|
|||
|
||||
chain = prompt | llm.bind_tools(tools)
|
||||
|
||||
result = chain.invoke(state["messages"])
|
||||
result = run_tool_loop(chain, state["messages"], tools)
|
||||
|
||||
report = ""
|
||||
|
||||
if len(result.tool_calls) == 0:
|
||||
report = result.content
|
||||
report = result.content or ""
|
||||
|
||||
return {
|
||||
"messages": [result],
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import time
|
|||
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.agents.utils.tool_runner import run_tool_loop
|
||||
from tradingagents.dataflows.config import get_config
|
||||
|
||||
|
||||
|
|
@ -73,16 +74,14 @@ Volume-Based Indicators:
|
|||
|
||||
chain = prompt | llm.bind_tools(tools)
|
||||
|
||||
result = chain.invoke(state["messages"])
|
||||
result = run_tool_loop(chain, state["messages"], tools)
|
||||
|
||||
report = ""
|
||||
report = result.content or ""
|
||||
macro_regime_report = ""
|
||||
|
||||
if len(result.tool_calls) == 0:
|
||||
report = result.content
|
||||
# Extract macro regime section if present
|
||||
if "Macro Regime Classification" in report or "RISK-ON" in report.upper() or "RISK-OFF" in report.upper() or "TRANSITION" in report.upper():
|
||||
macro_regime_report = report
|
||||
# Extract macro regime section if present
|
||||
if report and ("Macro Regime Classification" in report or "RISK-ON" in report.upper() or "RISK-OFF" in report.upper() or "TRANSITION" in report.upper()):
|
||||
macro_regime_report = report
|
||||
|
||||
return {
|
||||
"messages": [result],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
import json
|
||||
from tradingagents.agents.utils.news_data_tools import get_news, get_global_news
|
||||
from tradingagents.agents.utils.tool_runner import run_tool_loop
|
||||
from tradingagents.dataflows.config import get_config
|
||||
|
||||
|
||||
|
|
@ -42,12 +43,9 @@ def create_news_analyst(llm):
|
|||
prompt = prompt.partial(instrument_context=instrument_context)
|
||||
|
||||
chain = prompt | llm.bind_tools(tools)
|
||||
result = chain.invoke(state["messages"])
|
||||
result = run_tool_loop(chain, state["messages"], tools)
|
||||
|
||||
report = ""
|
||||
|
||||
if len(result.tool_calls) == 0:
|
||||
report = result.content
|
||||
report = result.content or ""
|
||||
|
||||
return {
|
||||
"messages": [result],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|||
import time
|
||||
import json
|
||||
from tradingagents.agents.utils.news_data_tools import get_news
|
||||
from tradingagents.agents.utils.tool_runner import run_tool_loop
|
||||
from tradingagents.dataflows.config import get_config
|
||||
|
||||
|
||||
|
|
@ -43,12 +44,9 @@ def create_social_media_analyst(llm):
|
|||
|
||||
chain = prompt | llm.bind_tools(tools)
|
||||
|
||||
result = chain.invoke(state["messages"])
|
||||
result = run_tool_loop(chain, state["messages"], tools)
|
||||
|
||||
report = ""
|
||||
|
||||
if len(result.tool_calls) == 0:
|
||||
report = result.content
|
||||
report = result.content or ""
|
||||
|
||||
return {
|
||||
"messages": [result],
|
||||
|
|
|
|||
Loading…
Reference in New Issue