Skip to content
Python

Merge remote-tracking branch 'upstream/main' into crypto-analysis-mvp

CadeYu5bae82674914
diff --cc tradingagents/agents/researchers/bear_researcher.py
index ce1f1144e,9cde9d39c..a4d88d27d
--- a/tradingagents/agents/researchers/bear_researcher.py
+++ b/tradingagents/agents/researchers/bear_researcher.py
@@@ -11,22 -11,8 +11,15 @@@ def create_bear_researcher(llm)
sentiment_report = state["sentiment_report"]
news_report = state["news_report"]
fundamentals_report = state["fundamentals_report"]
+ asset_type = state.get("asset_type", "stock")
+ target_label = "stock" if asset_type == "stock" else "asset"
+ fundamentals_label = (
+ "Company fundamentals report"
+ if asset_type == "stock"
+ else "Asset fundamentals report (may be unavailable for crypto)"
+ )
- curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"
- past_memories = memory.get_memories(curr_situation, n_matches=2)
-
- past_memory_str = ""
- for i, rec in enumerate(past_memories, 1):
- past_memory_str += rec["recommendation"] + "\n\n"
-
- 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.
+ prompt = f"""You are a Bear Analyst making the case against investing in the {target_label}. 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:
@@@ -41,11 -27,10 +34,10 @@@ 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}
+{fundamentals_label}: {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 {target_label}. You must also address reflections and learn from lessons and mistakes you made in the past.
-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.
++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 {target_label}.
"""
response = llm.invoke(prompt)
diff --cc tradingagents/agents/researchers/bull_researcher.py
index 40b205900,d16bc2371..7ce74054d
--- a/tradingagents/agents/researchers/bull_researcher.py
+++ b/tradingagents/agents/researchers/bull_researcher.py
@@@ -11,22 -11,8 +11,15 @@@ def create_bull_researcher(llm)
sentiment_report = state["sentiment_report"]
news_report = state["news_report"]
fundamentals_report = state["fundamentals_report"]
+ asset_type = state.get("asset_type", "stock")
+ target_label = "stock" if asset_type == "stock" else "asset"
+ fundamentals_label = (
+ "Company fundamentals report"
+ if asset_type == "stock"
+ else "Asset fundamentals report (may be unavailable for crypto)"
+ )
- curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"
- past_memories = memory.get_memories(curr_situation, n_matches=2)
-
- past_memory_str = ""
- for i, rec in enumerate(past_memories, 1):
- past_memory_str += rec["recommendation"] + "\n\n"
-
- prompt = f"""You are a Bull Analyst advocating for investing in the stock. Your task is to build a strong, evidence-based case emphasizing growth potential, competitive advantages, and positive market indicators. Leverage the provided research and data to address concerns and counter bearish arguments effectively.
+ prompt = f"""You are a Bull Analyst advocating for investing in the {target_label}. Your task is to build a strong, evidence-based case emphasizing growth potential, competitive advantages, and positive market indicators. Leverage the provided research and data to address concerns and counter bearish arguments effectively.
Key points to focus on:
- Growth Potential: Highlight the company's market opportunities, revenue projections, and scalability.
@@@ -39,11 -25,10 +32,10 @@@ 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}
+{fundamentals_label}: {fundamentals_report}
Conversation history of the debate: {history}
Last bear argument: {current_response}
- Reflections from similar situations and lessons learned: {past_memory_str}
- Use this information to deliver a compelling bull argument, refute the bear's concerns, and engage in a dynamic debate that demonstrates the strengths of the bull position. You must also address reflections and learn from lessons and mistakes you made in the past.
+ Use this information to deliver a compelling bull argument, refute the bear's concerns, and engage in a dynamic debate that demonstrates the strengths of the bull position.
"""
response = llm.invoke(prompt)
diff --cc tradingagents/agents/trader/trader.py
index 72a16dd6b,ea3f6b232..b8c0df376
--- a/tradingagents/agents/trader/trader.py
+++ b/tradingagents/agents/trader/trader.py
@@@ -1,33 -1,26 +1,27 @@@
+ """Trader: turns the Research Manager's investment plan into a concrete transaction proposal."""
+
+ from __future__ import annotations
+
import functools
+ from langchain_core.messages import AIMessage
+
+ from tradingagents.agents.schemas import TraderProposal, render_trader_proposal
from tradingagents.agents.utils.agent_utils import build_instrument_context
+ from tradingagents.agents.utils.structured import (
+ bind_structured,
+ invoke_structured_or_freetext,
+ )
+
+ def create_trader(llm):
+ structured_llm = bind_structured(llm, TraderProposal, "Trader")
- def create_trader(llm, memory):
def trader_node(state, name):
company_name = state["company_of_interest"]
- instrument_context = build_instrument_context(company_name)
+ asset_type = state.get("asset_type", "stock")
+ instrument_context = build_instrument_context(company_name, asset_type)
investment_plan = state["investment_plan"]
- market_research_report = state["market_report"]
- sentiment_report = state["sentiment_report"]
- news_report = state["news_report"]
- fundamentals_report = state["fundamentals_report"]
-
- curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"
- past_memories = memory.get_memories(curr_situation, n_matches=2)
-
- past_memory_str = ""
- if past_memories:
- for i, rec in enumerate(past_memories, 1):
- past_memory_str += rec["recommendation"] + "\n\n"
- else:
- past_memory_str = "No past memories found."
-
- context = {
- "role": "user",
- "content": f"Based on a comprehensive analysis by a team of analysts, here is an investment plan tailored for {company_name}. {instrument_context} This plan incorporates insights from current technical market trends, macroeconomic indicators, and social media sentiment. Use this plan as a foundation for evaluating your next trading decision.\n\nProposed Investment Plan: {investment_plan}\n\nLeverage these insights to make an informed and strategic decision.",
- }
messages = [
{
diff --cc tradingagents/graph/propagation.py
index a3caaa82c,2a5efb1ba..b7736139e
--- a/tradingagents/graph/propagation.py
+++ b/tradingagents/graph/propagation.py
@@@ -16,14 -16,14 +16,19 @@@ class Propagator
self.max_recur_limit = max_recur_limit
def create_initial_state(
- self, company_name: str, trade_date: str, asset_type: str = "stock"
- self, company_name: str, trade_date: str, past_context: str = ""
++ self,
++ company_name: str,
++ trade_date: str,
++ asset_type: str = "stock",
++ past_context: str = "",
) -> Dict[str, Any]:
"""Create the initial state for the agent graph."""
return {
"messages": [("human", company_name)],
"company_of_interest": company_name,
+ "asset_type": asset_type,
"trade_date": str(trade_date),
+ "past_context": past_context,
"investment_debate_state": InvestDebateState(
{
"bull_history": "",