50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
import time
|
|
import json
|
|
from tradingagents.default_config import DEFAULT_CONFIG
|
|
from tradingagents.i18n import get_prompts
|
|
|
|
def create_research_manager(llm, memory):
|
|
def research_manager_node(state) -> dict:
|
|
history = state["investment_debate_state"].get("history", "")
|
|
market_research_report = state["market_report"]
|
|
sentiment_report = state["sentiment_report"]
|
|
news_report = state["news_report"]
|
|
fundamentals_report = state["fundamentals_report"]
|
|
investment_preferences = state.get("investment_preferences", "")
|
|
external_reports = state.get("external_reports", [])
|
|
|
|
investment_debate_state = state["investment_debate_state"]
|
|
|
|
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 = get_prompts("managers", "research_manager") \
|
|
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"])) \
|
|
.replace("{past_memory_str}", past_memory_str) \
|
|
.replace("{history}", history) \
|
|
.replace("{external_reports}", "\n".join(external_reports)) \
|
|
+ "\n\n" \
|
|
+ get_prompts("investment_preferences", "system_message") \
|
|
.replace("{investment_preferences}", investment_preferences)
|
|
response = llm.invoke(prompt)
|
|
|
|
new_investment_debate_state = {
|
|
"judge_decision": response.content,
|
|
"history": investment_debate_state.get("history", ""),
|
|
"bear_history": investment_debate_state.get("bear_history", ""),
|
|
"bull_history": investment_debate_state.get("bull_history", ""),
|
|
"current_response": response.content,
|
|
"count": investment_debate_state["count"],
|
|
}
|
|
|
|
return {
|
|
"investment_debate_state": new_investment_debate_state,
|
|
"investment_plan": response.content,
|
|
}
|
|
|
|
return research_manager_node
|