67 lines
3.6 KiB
Python
67 lines
3.6 KiB
Python
import functools
|
|
|
|
|
|
def create_bear_researcher(llm, memory):
|
|
def bear_node(state) -> dict:
|
|
if not state or not isinstance(state, dict):
|
|
raise ValueError("Invalid state provided to bear_researcher")
|
|
|
|
investment_debate_state = state.get("investment_debate_state", {})
|
|
history = investment_debate_state.get("history", "")
|
|
bear_history = investment_debate_state.get("bear_history", "")
|
|
|
|
current_response = investment_debate_state.get("current_response", "")
|
|
market_research_report = state.get("market_report", "")
|
|
sentiment_report = state.get("sentiment_report", "")
|
|
news_report = state.get("news_report", "")
|
|
fundamentals_report = state.get("fundamentals_report", "")
|
|
|
|
curr_situation = f"Market: {market_research_report}\nSentiment: {sentiment_report}\nNews: {news_report}\nFundamentals: {fundamentals_report}"
|
|
past_memories = memory.get_memories(curr_situation, n_matches=3, min_similarity=0.8)
|
|
|
|
past_memory_str = ""
|
|
if past_memories:
|
|
for i, rec in enumerate(past_memories, 1):
|
|
similarity = rec.get("similarity_score", 0)
|
|
past_memory_str += f"Bear Memory {i} (similarity: {similarity:.3f}): {rec['recommendation']}\n\n"
|
|
else:
|
|
past_memory_str = "No statistically significant bear memories found (similarity < 80%)."
|
|
|
|
prompt = f"""You are a Bear Analyst making the case against investing in the stock. Your goal is to present a well-reasoned argument emphasizing risks, challenges, and negative indicators. Leverage the provided research and data to highlight potential downsides and counter bullish arguments effectively.
|
|
|
|
Key points to focus on:
|
|
|
|
- Risks and Challenges: Highlight factors like market saturation, financial instability, or macroeconomic threats that could hinder the stock's performance.
|
|
- Competitive Weaknesses: Emphasize vulnerabilities such as weaker market positioning, declining innovation, or threats from competitors.
|
|
- Negative Indicators: Use evidence from financial data, market trends, or recent adverse news to support your position.
|
|
- Bull Counterpoints: Critically analyze the bull argument with specific data and sound reasoning, exposing weaknesses or over-optimistic assumptions.
|
|
- Engagement: Present your argument in a conversational style, directly engaging with the bull analyst's points and debating effectively rather than simply listing facts.
|
|
|
|
Resources available:
|
|
|
|
Market research report: {market_research_report}
|
|
Social media sentiment report: {sentiment_report}
|
|
Latest world affairs news: {news_report}
|
|
Company fundamentals report: {fundamentals_report}
|
|
Conversation history of the debate: {history}
|
|
Last bull argument: {current_response}
|
|
Reflections from similar situations and lessons learned: {past_memory_str}
|
|
Use this information to deliver a compelling bear argument, refute the bull's claims, and engage in a dynamic debate that demonstrates the risks and weaknesses of investing in the stock. You must also address reflections and learn from lessons and mistakes you made in the past.
|
|
"""
|
|
|
|
response = llm.invoke(prompt)
|
|
|
|
argument = f"Bear Analyst: {response.content}"
|
|
|
|
new_investment_debate_state = {
|
|
"history": history + "\n" + argument,
|
|
"bear_history": bear_history + "\n" + argument,
|
|
"bull_history": investment_debate_state.get("bull_history", ""),
|
|
"current_response": argument,
|
|
"count": investment_debate_state["count"] + 1,
|
|
}
|
|
|
|
return {"investment_debate_state": new_investment_debate_state}
|
|
|
|
return bear_node
|