Skip to content

TradingAgents: Multi-Agents LLM Financial Trading Framework

save reports & logs under results_dir

ZeroAct9647359246eb
diff --git a/cli/main.py b/cli/main.py
index e7bed4ee4..462ad49f1 100644
--- a/cli/main.py
+++ b/cli/main.py
@@ -1,6 +1,7 @@
from typing import Optional
import datetime
import typer
+from pathlib import Path
from rich.console import Console
from rich.panel import Panel
from rich.spinner import Spinner
@@ -700,6 +701,10 @@ def run_analysis():
[analyst.value for analyst in selections["analysts"]], config=config, debug=True
)
+ # Create result directory
+ results_dir = Path(config["results_dir"]) / selections["ticker"] / datetime.datetime.now().strftime("%Y-%m-%d")
+ results_dir.mkdir(parents=True, exist_ok=True)
+
# Now start the display layout
layout = create_layout()
@@ -994,6 +999,23 @@ def run_analysis():
if section in final_state:
message_buffer.update_report_section(section, final_state[section])
+ # Save results to file
+ report_dir = results_dir / "reports"
+ report_dir.mkdir(parents=True, exist_ok=True)
+
+ for section, content in message_buffer.report_sections.items():
+ if content:
+ with open(report_dir / f"{section}.md", "w") as f:
+ f.write(content)
+
+ for (timestamp, msg_type, content) in message_buffer.messages:
+ with open(results_dir / "messages.log", "a") as f:
+ f.write(f"{timestamp} [{msg_type}]: {content}\n")
+
+ for (timestamp, tool_name, args) in message_buffer.tool_calls:
+ with open(results_dir / "tool_calls.log", "a") as f:
+ f.write(f"{timestamp} [Tool: {tool_name}]: {args}\n")
+
# Display the complete final report
display_complete_report(final_state)
diff --git a/tradingagents/default_config.py b/tradingagents/default_config.py
index 5bb2548c5..b5abf38ed 100644
--- a/tradingagents/default_config.py
+++ b/tradingagents/default_config.py
@@ -2,6 +2,7 @@ import os
DEFAULT_CONFIG = {
"project_dir": os.path.abspath(os.path.join(os.path.dirname(__file__), ".")),
+ "results_dir": os.getenv("TRADINGAGENTS_RESULTS_DIR", "./results"),
"data_dir": "/Users/yluo/Documents/Code/ScAI/FR1-data",
"data_cache_dir": os.path.join(
os.path.abspath(os.path.join(os.path.dirname(__file__), ".")),