Clean up debug logging and fix reports count

Remove verbose debug prints added during parallel analysts development.
Fix reports showing 4/7 by updating buf.report_sections for investment_plan,
trader_investment_plan, and final_trade_decision (previously only analyst
reports were tracked).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dtarkent2-sys 2026-02-20 11:41:01 +00:00
parent 05b319c101
commit 47771849ca
1 changed files with 4 additions and 11 deletions

15
app.py
View File

@ -93,7 +93,6 @@ def _agent_stage(agent_name):
async def run_analysis(analysis_id: str, ticker: str, trade_date: str): async def run_analysis(analysis_id: str, ticker: str, trade_date: str):
"""Background task that runs the TradingAgents pipeline and pushes SSE events.""" """Background task that runs the TradingAgents pipeline and pushes SSE events."""
import traceback as _tb import traceback as _tb
print(f"[ANALYSIS] Starting analysis {analysis_id} for {ticker}", flush=True)
state = analyses[analysis_id] state = analyses[analysis_id]
q = state["queue"] q = state["queue"]
config = build_config() config = build_config()
@ -101,14 +100,12 @@ async def run_analysis(analysis_id: str, ticker: str, trade_date: str):
selected_analysts = ["market", "social", "news", "fundamentals"] selected_analysts = ["market", "social", "news", "fundamentals"]
try: try:
print("[ANALYSIS] Creating TradingAgentsGraph...", flush=True)
graph = TradingAgentsGraph( graph = TradingAgentsGraph(
selected_analysts=selected_analysts, selected_analysts=selected_analysts,
debug=False, debug=False,
config=config, config=config,
callbacks=[stats_handler], callbacks=[stats_handler],
) )
print("[ANALYSIS] Graph created successfully", flush=True)
except Exception as e: except Exception as e:
print(f"[ANALYSIS] Init failed: {e}\n{_tb.format_exc()}", flush=True) print(f"[ANALYSIS] Init failed: {e}\n{_tb.format_exc()}", flush=True)
await q.put({"type": "error", "message": f"Init failed: {e}"}) await q.put({"type": "error", "message": f"Init failed: {e}"})
@ -129,7 +126,6 @@ async def run_analysis(analysis_id: str, ticker: str, trade_date: str):
prev_statuses = {} prev_statuses = {}
# Emit all analysts as "in_progress" immediately (they run in parallel) # Emit all analysts as "in_progress" immediately (they run in parallel)
print("[ANALYSIS] Emitting in_progress for all analysts", flush=True)
analyst_name_map = { analyst_name_map = {
"market": "Market Analyst", "market": "Market Analyst",
"social": "Social Analyst", "social": "Social Analyst",
@ -151,13 +147,8 @@ async def run_analysis(analysis_id: str, ticker: str, trade_date: str):
await q.put(evt) await q.put(evt)
prev_statuses[agent_name] = "in_progress" prev_statuses[agent_name] = "in_progress"
print(f"[ANALYSIS] Starting graph stream, events so far: {len(state['events'])}", flush=True)
chunk_count = 0
try: try:
async for chunk in graph.graph.astream(init_state, **args): async for chunk in graph.graph.astream(init_state, **args):
chunk_count += 1
chunk_keys = [k for k in chunk if chunk.get(k) and k != "messages"]
print(f"[ANALYSIS] Chunk #{chunk_count}, keys with data: {chunk_keys[:10]}", flush=True)
final_state = chunk final_state = chunk
# Process messages (same logic as Chainlit app) # Process messages (same logic as Chainlit app)
@ -230,6 +221,7 @@ async def run_analysis(analysis_id: str, ticker: str, trade_date: str):
for a in ("Bull Researcher", "Bear Researcher", "Research Manager"): for a in ("Bull Researcher", "Bear Researcher", "Research Manager"):
buf.update_agent_status(a, "completed") buf.update_agent_status(a, "completed")
buf.update_agent_status("Trader", "in_progress") buf.update_agent_status("Trader", "in_progress")
buf.update_report_section("investment_plan", judge)
evt = { evt = {
"type": "debate", "type": "debate",
"stage": "research", "stage": "research",
@ -246,6 +238,7 @@ async def run_analysis(analysis_id: str, ticker: str, trade_date: str):
trader_emitted = True trader_emitted = True
buf.update_agent_status("Trader", "completed") buf.update_agent_status("Trader", "completed")
buf.update_agent_status("Aggressive Analyst", "in_progress") buf.update_agent_status("Aggressive Analyst", "in_progress")
buf.update_report_section("trader_investment_plan", chunk["trader_investment_plan"])
evt = { evt = {
"type": "trader", "type": "trader",
"stage": "trading", "stage": "trading",
@ -289,8 +282,7 @@ async def run_analysis(analysis_id: str, ticker: str, trade_date: str):
await q.put(evt) await q.put(evt)
except Exception as e: except Exception as e:
import traceback as _tb2 print(f"[ANALYSIS] Stream error: {e}\n{_tb.format_exc()}", flush=True)
print(f"[ANALYSIS] ERROR in stream loop: {e}\n{_tb2.format_exc()}", flush=True)
evt = {"type": "error", "message": str(e)} evt = {"type": "error", "message": str(e)}
state["events"].append(evt) state["events"].append(evt)
await q.put(evt) await q.put(evt)
@ -302,6 +294,7 @@ async def run_analysis(analysis_id: str, ticker: str, trade_date: str):
if final_state: if final_state:
decision_text = final_state.get("final_trade_decision", "No decision reached.") decision_text = final_state.get("final_trade_decision", "No decision reached.")
signal = graph.process_signal(decision_text) signal = graph.process_signal(decision_text)
buf.update_report_section("final_trade_decision", decision_text)
for agent in buf.agent_status: for agent in buf.agent_status:
buf.update_agent_status(agent, "completed") buf.update_agent_status(agent, "completed")
st = get_stats_dict(stats_handler, buf, start_time) st = get_stats_dict(stats_handler, buf, start_time)