From abb9cd072698dcdb71f2ad8781fa43112c899761 Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 5 Nov 2025 00:44:24 -0500 Subject: [PATCH] fix: capture tool messages in conversation history for summarizer **Root Cause:** The summarizer was not receiving tool execution results (buy/sell trades) because they were never captured to conversation_history. **What was captured:** - User: 'Please analyze positions' - Assistant: 'I will buy/sell...' - Assistant: 'Done ' **What was MISSING:** - Tool: buy 14 NVDA at $185.24 - Tool: sell 1 GOOGL at $245.15 **Changes:** - Added tool message capture in trading loop (line 649) - Extract tool_name and tool_content from each tool message - Capture to conversation_history before processing - Changed message['tool_name'] to message['name'] for consistency **Impact:** Now the summarizer sees the actual tool results, not just the AI's intentions. Combined with alpha.8's prompt improvements, summaries will accurately reflect executed trades. Fixes reasoning summaries that contradicted actual trades. --- agent/base_agent/base_agent.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/agent/base_agent/base_agent.py b/agent/base_agent/base_agent.py index e1a62aa..7c44d45 100644 --- a/agent/base_agent/base_agent.py +++ b/agent/base_agent/base_agent.py @@ -419,7 +419,7 @@ class BaseAgent: } if tool_name: - message["tool_name"] = tool_name + message["name"] = tool_name # Use "name" not "tool_name" for consistency with summarizer if tool_input: message["tool_input"] = tool_input @@ -643,6 +643,11 @@ Summary:""" tool_msgs = extract_tool_messages(response) for tool_msg in tool_msgs: tool_name = getattr(tool_msg, 'name', None) or tool_msg.get('name') if isinstance(tool_msg, dict) else None + tool_content = getattr(tool_msg, 'content', '') or tool_msg.get('content', '') if isinstance(tool_msg, dict) else str(tool_msg) + + # Capture tool message to conversation history + self._capture_message("tool", tool_content, tool_name=tool_name) + if tool_name in ['buy', 'sell']: action_count += 1