fix: strip trailing newlines from past_memory_str and gate thesis instruction
Addresses gemini-code-assist review feedback: - All five files (portfolio_manager, research_manager, bear/bull researchers, trader) now call .strip() on past_memory_str before injecting it into prompts, removing the trailing '\n\n' artifacts from the construction loop. - portfolio_manager now also makes the 'past reflections' phrasing in the Investment Thesis instruction conditional on past_memories being non-empty, so an empty memory section can't trigger hallucinated past reflections.
This commit is contained in:
parent
42dafee655
commit
25cc0e144c
|
|
@ -23,10 +23,15 @@ def create_portfolio_manager(llm, memory):
|
|||
past_memory_str += rec["recommendation"] + "\n\n"
|
||||
|
||||
lessons_line = (
|
||||
f"- Lessons from past decisions: **{past_memory_str}**\n"
|
||||
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.
|
||||
|
||||
|
|
@ -48,7 +53,7 @@ def create_portfolio_manager(llm, memory):
|
|||
**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}
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ def create_research_manager(llm, memory):
|
|||
past_memory_str += rec["recommendation"] + "\n\n"
|
||||
|
||||
past_memory_block = (
|
||||
f'Take into account your past mistakes on similar situations. Use these insights to refine your decision-making and ensure you are learning and improving. Present your analysis conversationally, as if speaking naturally, without special formatting. \n\nHere are your past reflections on mistakes:\n"{past_memory_str}"\n\n'
|
||||
f'Take into account your past mistakes on similar situations. Use these insights to refine your decision-making and ensure you are learning and improving. Present your analysis conversationally, as if speaking naturally, without special formatting. \n\nHere are your past reflections on mistakes:\n"{past_memory_str.strip()}"\n\n'
|
||||
if past_memories
|
||||
else ""
|
||||
)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ def create_bear_researcher(llm, memory):
|
|||
past_memory_str += rec["recommendation"] + "\n\n"
|
||||
|
||||
memory_section = (
|
||||
f"Reflections from similar situations and lessons learned: {past_memory_str}\n"
|
||||
f"Reflections from similar situations and lessons learned: {past_memory_str.strip()}\n"
|
||||
if past_memories
|
||||
else ""
|
||||
)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ def create_bull_researcher(llm, memory):
|
|||
past_memory_str += rec["recommendation"] + "\n\n"
|
||||
|
||||
memory_section = (
|
||||
f"Reflections from similar situations and lessons learned: {past_memory_str}\n"
|
||||
f"Reflections from similar situations and lessons learned: {past_memory_str.strip()}\n"
|
||||
if past_memories
|
||||
else ""
|
||||
)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ def create_trader(llm, memory):
|
|||
past_memory_str += rec["recommendation"] + "\n\n"
|
||||
|
||||
memory_instruction = (
|
||||
f" Apply lessons from past decisions to strengthen your analysis. Here are reflections from similar situations you traded in and the lessons learned: {past_memory_str}"
|
||||
f" Apply lessons from past decisions to strengthen your analysis. Here are reflections from similar situations you traded in and the lessons learned: {past_memory_str.strip()}"
|
||||
if past_memories
|
||||
else ""
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue