From 6d126db03c7eaed28e70c8ff4aa612c960322679 Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 5 Nov 2025 00:41:59 -0500 Subject: [PATCH] fix: improve reasoning summary to explicitly mention trades The reasoning summary was not accurately reflecting actual trades. For example, 2 sell trades were summarized as 'maintain core holdings'. Changes: - Updated prompt to require explicit mention of trades executed - Added emphasis on buy/sell tool calls in formatted log - Trades now highlighted at top of log with TRADES EXECUTED section - Prompt instructs: state specific trades (symbols, quantities, action) Example before: 'chose to maintain core holdings' Example after: 'sold 1 GOOGL and 1 AMZN to reduce exposure' This ensures reasoning field accurately describes what the AI actually did. --- agent/reasoning_summarizer.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/agent/reasoning_summarizer.py b/agent/reasoning_summarizer.py index 7f4e4d4..2cd668a 100644 --- a/agent/reasoning_summarizer.py +++ b/agent/reasoning_summarizer.py @@ -36,15 +36,17 @@ class ReasoningSummarizer: summary_prompt = f"""You are reviewing your own trading decisions for the day. Summarize your trading strategy and key decisions in 2-3 sentences. +IMPORTANT: Explicitly state what trades you executed (e.g., "sold 2 GOOGL shares" or "bought 10 NVDA shares"). If you made no trades, state that clearly. + Focus on: -- What you analyzed -- Why you made the trades you did +- What specific trades you executed (buy/sell, symbols, quantities) +- Why you made those trades - Your overall strategy for the day Trading session log: {log_text} -Provide a concise summary:""" +Provide a concise summary that includes the actual trades executed:""" response = await self.model.ainvoke([ {"role": "user", "content": summary_prompt} @@ -67,21 +69,33 @@ Provide a concise summary:""" reasoning_log: List of message dicts Returns: - Formatted text representation + Formatted text representation with emphasis on trades """ formatted_parts = [] + trades_executed = [] for msg in reasoning_log: role = msg.get("role", "") content = msg.get("content", "") + tool_name = msg.get("name", "") if role == "assistant": # AI's thoughts formatted_parts.append(f"AI: {content[:200]}") elif role == "tool": - # Tool results - tool_name = msg.get("name", "tool") - formatted_parts.append(f"{tool_name}: {content[:100]}") + # Highlight trade tool calls + if tool_name in ["buy", "sell"]: + trades_executed.append(f"{tool_name.upper()}: {content[:150]}") + formatted_parts.append(f"TRADE - {tool_name.upper()}: {content[:150]}") + else: + # Other tool results (search, price, etc.) + formatted_parts.append(f"{tool_name}: {content[:100]}") + + # Add summary of trades at the top + if trades_executed: + trade_summary = f"TRADES EXECUTED ({len(trades_executed)}):\n" + "\n".join(trades_executed) + formatted_parts.insert(0, trade_summary) + formatted_parts.insert(1, "\n--- FULL LOG ---") return "\n".join(formatted_parts)