mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-09 20:27:25 -04:00
Compare commits
2 Commits
v0.4.0-alp
...
v0.4.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d126db03c | |||
| 1e7bdb509b |
@@ -52,10 +52,6 @@ class ContextInjector:
|
|||||||
"""
|
"""
|
||||||
# Inject context parameters for trade tools
|
# Inject context parameters for trade tools
|
||||||
if request.name in ["buy", "sell"]:
|
if request.name in ["buy", "sell"]:
|
||||||
# Debug: Log self attributes BEFORE injection
|
|
||||||
print(f"[ContextInjector.__call__] ENTRY: id={id(self)}, self.signature={self.signature}, self.today_date={self.today_date}, self.job_id={self.job_id}, self.session_id={self.session_id}, self.trading_day_id={self.trading_day_id}")
|
|
||||||
print(f"[ContextInjector.__call__] Args BEFORE injection: {request.args}")
|
|
||||||
|
|
||||||
# ALWAYS inject/override context parameters (don't trust AI-provided values)
|
# ALWAYS inject/override context parameters (don't trust AI-provided values)
|
||||||
request.args["signature"] = self.signature
|
request.args["signature"] = self.signature
|
||||||
request.args["today_date"] = self.today_date
|
request.args["today_date"] = self.today_date
|
||||||
@@ -66,8 +62,5 @@ class ContextInjector:
|
|||||||
if self.trading_day_id:
|
if self.trading_day_id:
|
||||||
request.args["trading_day_id"] = self.trading_day_id
|
request.args["trading_day_id"] = self.trading_day_id
|
||||||
|
|
||||||
# Debug logging
|
|
||||||
print(f"[ContextInjector] Tool: {request.name}, Args after injection: {request.args}")
|
|
||||||
|
|
||||||
# Call the actual tool handler
|
# Call the actual tool handler
|
||||||
return await handler(request)
|
return await handler(request)
|
||||||
|
|||||||
@@ -36,15 +36,17 @@ class ReasoningSummarizer:
|
|||||||
summary_prompt = f"""You are reviewing your own trading decisions for the day.
|
summary_prompt = f"""You are reviewing your own trading decisions for the day.
|
||||||
Summarize your trading strategy and key decisions in 2-3 sentences.
|
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:
|
Focus on:
|
||||||
- What you analyzed
|
- What specific trades you executed (buy/sell, symbols, quantities)
|
||||||
- Why you made the trades you did
|
- Why you made those trades
|
||||||
- Your overall strategy for the day
|
- Your overall strategy for the day
|
||||||
|
|
||||||
Trading session log:
|
Trading session log:
|
||||||
{log_text}
|
{log_text}
|
||||||
|
|
||||||
Provide a concise summary:"""
|
Provide a concise summary that includes the actual trades executed:"""
|
||||||
|
|
||||||
response = await self.model.ainvoke([
|
response = await self.model.ainvoke([
|
||||||
{"role": "user", "content": summary_prompt}
|
{"role": "user", "content": summary_prompt}
|
||||||
@@ -67,21 +69,33 @@ Provide a concise summary:"""
|
|||||||
reasoning_log: List of message dicts
|
reasoning_log: List of message dicts
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Formatted text representation
|
Formatted text representation with emphasis on trades
|
||||||
"""
|
"""
|
||||||
formatted_parts = []
|
formatted_parts = []
|
||||||
|
trades_executed = []
|
||||||
|
|
||||||
for msg in reasoning_log:
|
for msg in reasoning_log:
|
||||||
role = msg.get("role", "")
|
role = msg.get("role", "")
|
||||||
content = msg.get("content", "")
|
content = msg.get("content", "")
|
||||||
|
tool_name = msg.get("name", "")
|
||||||
|
|
||||||
if role == "assistant":
|
if role == "assistant":
|
||||||
# AI's thoughts
|
# AI's thoughts
|
||||||
formatted_parts.append(f"AI: {content[:200]}")
|
formatted_parts.append(f"AI: {content[:200]}")
|
||||||
elif role == "tool":
|
elif role == "tool":
|
||||||
# Tool results
|
# Highlight trade tool calls
|
||||||
tool_name = msg.get("name", "tool")
|
if tool_name in ["buy", "sell"]:
|
||||||
formatted_parts.append(f"{tool_name}: {content[:100]}")
|
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)
|
return "\n".join(formatted_parts)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user