fix: drop past-memory directive and placeholder from agent prompts when memory is empty (#572)

This commit is contained in:
Yijia-Xiao
2026-04-25 07:41:36 +00:00
parent 872b063e69
commit 8e7654f0df
5 changed files with 51 additions and 16 deletions
@@ -22,6 +22,17 @@ def create_portfolio_manager(llm, memory):
for i, rec in enumerate(past_memories, 1):
past_memory_str += rec["recommendation"] + "\n\n"
lessons_line = (
f"- Lessons from past decisions: **{past_memory_str.strip()}**\n"
if past_memories
else ""
)
thesis_instruction = (
"3. **Investment Thesis**: Detailed reasoning anchored in the analysts' debate and past reflections."
if past_memories
else "3. **Investment Thesis**: Detailed reasoning anchored in the analysts' debate."
)
prompt = f"""As the Portfolio Manager, synthesize the risk analysts' debate and deliver the final trading decision.
{instrument_context}
@@ -38,12 +49,11 @@ def create_portfolio_manager(llm, memory):
**Context:**
- Research Manager's investment plan: **{research_plan}**
- Trader's transaction proposal: **{trader_plan}**
- Lessons from past decisions: **{past_memory_str}**
{lessons_line}
**Required Output Structure:**
1. **Rating**: State one of Buy / Overweight / Hold / Underweight / Sell.
2. **Executive Summary**: A concise action plan covering entry strategy, position sizing, key risk levels, and time horizon.
3. **Investment Thesis**: Detailed reasoning anchored in the analysts' debate and past reflections.
{thesis_instruction}
---