mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-02 01:27:24 -04:00
Compare commits
3 Commits
v0.4.0-alp
...
v0.4.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
| 462de3adeb | |||
| 31e346ecbb | |||
| abb9cd0726 |
@@ -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
|
||||
|
||||
@@ -633,21 +633,28 @@ Summary:"""
|
||||
# Capture assistant response
|
||||
self._capture_message("assistant", agent_response)
|
||||
|
||||
# Check stop signal
|
||||
if STOP_SIGNAL in agent_response:
|
||||
print("✅ Received stop signal, trading session ended")
|
||||
print(agent_response)
|
||||
break
|
||||
|
||||
# Extract tool messages and count trade actions
|
||||
# Extract tool messages BEFORE checking stop signal
|
||||
# (agent may call tools AND return FINISH_SIGNAL in same response)
|
||||
tool_msgs = extract_tool_messages(response)
|
||||
print(f"[DEBUG] Extracted {len(tool_msgs)} tool messages from 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
|
||||
|
||||
tool_response = '\n'.join([msg.content for msg in tool_msgs])
|
||||
|
||||
# Check stop signal AFTER processing tools
|
||||
if STOP_SIGNAL in agent_response:
|
||||
print("✅ Received stop signal, trading session ended")
|
||||
print(agent_response)
|
||||
break
|
||||
|
||||
# Prepare new messages
|
||||
new_messages = [
|
||||
{"role": "assistant", "content": agent_response},
|
||||
@@ -665,6 +672,15 @@ Summary:"""
|
||||
session_duration = time.time() - session_start
|
||||
|
||||
# 7. Generate reasoning summary
|
||||
# Debug: Log conversation history size
|
||||
print(f"\n[DEBUG] Generating summary from {len(self.conversation_history)} messages")
|
||||
assistant_msgs = [m for m in self.conversation_history if m.get('role') == 'assistant']
|
||||
tool_msgs = [m for m in self.conversation_history if m.get('role') == 'tool']
|
||||
print(f"[DEBUG] Assistant messages: {len(assistant_msgs)}, Tool messages: {len(tool_msgs)}")
|
||||
if assistant_msgs:
|
||||
first_assistant = assistant_msgs[0]
|
||||
print(f"[DEBUG] First assistant message preview: {first_assistant.get('content', '')[:200]}...")
|
||||
|
||||
summarizer = ReasoningSummarizer(model=self.model)
|
||||
summary = await summarizer.generate_summary(self.conversation_history)
|
||||
|
||||
|
||||
@@ -71,6 +71,12 @@ Provide a concise summary that includes the actual trades executed:"""
|
||||
Returns:
|
||||
Formatted text representation with emphasis on trades
|
||||
"""
|
||||
# Debug: Log what we're formatting
|
||||
print(f"[DEBUG ReasoningSummarizer] Formatting {len(reasoning_log)} messages")
|
||||
assistant_count = sum(1 for m in reasoning_log if m.get('role') == 'assistant')
|
||||
tool_count = sum(1 for m in reasoning_log if m.get('role') == 'tool')
|
||||
print(f"[DEBUG ReasoningSummarizer] Breakdown: {assistant_count} assistant, {tool_count} tool")
|
||||
|
||||
formatted_parts = []
|
||||
trades_executed = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user