TradingAgents/tradingagents/agents/researchers/bear_researcher.py

106 lines
3.3 KiB
Python

from tradingagents.agents.utils.agent_utils import format_memory_context
from tradingagents.agents.utils.llm_utils import create_and_invoke_chain, parse_llm_response
def create_bear_researcher(llm, memory):
def bear_node(state) -> dict:
investment_debate_state = state["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["market_report"]
sentiment_report = state["sentiment_report"]
news_report = state["news_report"]
fundamentals_report = state["fundamentals_report"]
past_memory_str = format_memory_context(memory, state)
prompt = f"""You are the Bear Analyst making the case for SHORT-TERM SELL/AVOID (1-2 weeks).
## YOUR OBJECTIVE
Build evidence-based bear case emphasizing SHORT-TERM risks and refute Bull claims.
## STRUCTURE
### Core Thesis (2-3 sentences)
Why this is SELL/AVOID for short-term traders NOW.
### Key Bearish Points (3-4 max)
For each:
- **Risk:** [Bearish argument]
- **Evidence:** [Specific data - numbers, dates]
- **Short-Term Impact:** [Impact in next 1-2 weeks]
- **Probability:** [High/Med/Low]
- **Strength Score:** [1-10] (10 = very strong, 5 = moderate, 1 = weak)
- **Confidence:** [High/Med/Low] based on data quality
### Bull Rebuttals
For EACH Bull claim:
- **Bull Says:** "[Quote]"
- **Counter:** [Why they're wrong]
- **Flaw:** [Weakness in their logic]
- **Rebuttal Strength:** [Strong/Moderate/Weak] - does your counter fully address their claim?
### Strengths I Acknowledge
- [1-2 legitimate Bull points]
- [Why risks still dominate]
## EVIDENCE PRIORITY
1. Disappointing results, guidance cuts
2. Technical breakdown, fading momentum
3. Near-term risk (next 1-2 weeks)
4. Insider selling, downgrades
## RULES
- ✅ Specific numbers and dates
- ✅ Engage with Bull points
- ✅ Short-term focus (1-2 weeks)
- ❌ Don't exaggerate
- ❌ Don't ignore Bull strengths
---
**DATA:**
Technical: {market_research_report}
Sentiment: {sentiment_report}
News: {news_report}
Fundamentals: {fundamentals_report}
**DEBATE:**
History: {history}
Last Bull: {current_response}
""" + (
f"""
## PAST LESSONS APPLICATION (Review BEFORE making arguments)
{past_memory_str}
**For each relevant past lesson:**
1. **Similar Situation:** [What was similar?]
2. **What Went Wrong/Right:** [Specific outcome]
3. **How I'm Adjusting:** [Specific change to current argument based on lesson]
4. **Impact on Conviction:** [Increases/Decreases/No change to conviction level]
Apply lessons: How are you adjusting?"""
if past_memory_str
else ""
)
response = create_and_invoke_chain(llm, [], prompt, [])
response_text = parse_llm_response(response.content)
argument = f"Bear Analyst: {response_text}"
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