feat(reporting): share the report-tree writer between the CLI and the API
The per-section markdown report tree was written only by the CLI, so programmatic (TradingAgentsGraph) runs produced no saved reports. - Extract the writer into tradingagents/reporting.write_report_tree. - The CLI's save_report_to_disk delegates to it (no behavior change). - Add TradingAgentsGraph.save_reports(final_state, ticker) so headless/API callers get the same report tree, defaulting under results_dir.
This commit is contained in:
4 files changed
+170
-87
No files matched your search
@@ -32,6 +32,7 @@ from tradingagents.dataflows.config import set_config
|
||||
from tradingagents.dataflows.utils import safe_ticker_component
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.llm_clients import create_llm_client
|
||||
from tradingagents.reporting import write_report_tree
|
||||
|
||||
from .checkpointer import checkpoint_step, clear_checkpoint, get_checkpointer, thread_id
|
||||
from .conditional_logic import ConditionalLogic
|
||||
@@ -358,6 +359,21 @@ class TradingAgentsGraph:
|
||||
self._checkpointer_ctx = None
|
||||
self.graph = self.workflow.compile()
|
||||
|
||||
def save_reports(self, final_state, ticker, save_path=None) -> Path:
|
||||
"""Write the markdown report tree for a completed run, like the CLI does.
|
||||
|
||||
Programmatic callers get the same on-disk reports the CLI produces. Pass
|
||||
an explicit ``save_path`` or let it default under ``results_dir``.
|
||||
"""
|
||||
if save_path is None:
|
||||
stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
save_path = (
|
||||
Path(self.config["results_dir"])
|
||||
/ "reports"
|
||||
/ f"{safe_ticker_component(ticker)}_{stamp}"
|
||||
)
|
||||
return write_report_tree(final_state, ticker, save_path)
|
||||
|
||||
def _run_graph(self, company_name, trade_date, asset_type: str = "stock"):
|
||||
"""Execute the graph and write the resulting state to disk and memory log."""
|
||||
# Initialize state — inject memory log context for PM and the
|
||||
|
||||
Reference in new issue
Block a user