save reports & logs under results_dir

This commit is contained in:
ZeroAct
2025-06-12 11:25:07 +09:00
parent a879868396
commit 9647359246
2 changed files with 23 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
from typing import Optional from typing import Optional
import datetime import datetime
import typer import typer
from pathlib import Path
from rich.console import Console from rich.console import Console
from rich.panel import Panel from rich.panel import Panel
from rich.spinner import Spinner from rich.spinner import Spinner
@@ -700,6 +701,10 @@ def run_analysis():
[analyst.value for analyst in selections["analysts"]], config=config, debug=True [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 # Now start the display layout
layout = create_layout() layout = create_layout()
@@ -994,6 +999,23 @@ def run_analysis():
if section in final_state: if section in final_state:
message_buffer.update_report_section(section, final_state[section]) 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 the complete final report
display_complete_report(final_state) display_complete_report(final_state)

View File

@@ -2,6 +2,7 @@ import os
DEFAULT_CONFIG = { DEFAULT_CONFIG = {
"project_dir": os.path.abspath(os.path.join(os.path.dirname(__file__), ".")), "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_dir": "/Users/yluo/Documents/Code/ScAI/FR1-data",
"data_cache_dir": os.path.join( "data_cache_dir": os.path.join(
os.path.abspath(os.path.join(os.path.dirname(__file__), ".")), os.path.abspath(os.path.join(os.path.dirname(__file__), ".")),