From 28218b2db9adf8967602420898fe10045061d76f Mon Sep 17 00:00:00 2001 From: Jeffrey Chu Date: Thu, 23 Oct 2025 21:59:47 +0800 Subject: [PATCH] update prompt --- tradingagents/graph/reflection.py | 14 ++++++++++++-- tradingagents/graph/signal_processing.py | 18 ++++++++++++++++-- tradingagents/graph/trading_graph.py | 4 ++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tradingagents/graph/reflection.py b/tradingagents/graph/reflection.py index b4cc6163..228e76f0 100644 --- a/tradingagents/graph/reflection.py +++ b/tradingagents/graph/reflection.py @@ -8,14 +8,22 @@ from langchain_core.language_models.chat_models import BaseChatModel class Reflector: """Handles reflection on decisions and updating memory.""" - def __init__(self, quick_thinking_llm: BaseChatModel): + def __init__(self, quick_thinking_llm: BaseChatModel, config): """Initialize the reflector with an LLM.""" + language = config["output_language"] + language_prompts = { + "en": "", + "zh-tw": "Use Traditional Chinese as the output.", + "zh-cn": "Use Simplified Chinese as the output.", + } + self.language_prompt = language_prompts.get(language, "") + self.quick_thinking_llm = quick_thinking_llm self.reflection_system_prompt = self._get_reflection_prompt() def _get_reflection_prompt(self) -> str: """Get the system prompt for reflection.""" - return """ + return f""" You are an expert financial analyst tasked with reviewing trading decisions/analysis and providing a comprehensive, step-by-step analysis. Your goal is to deliver detailed insights into investment decisions and highlight opportunities for improvement, adhering strictly to the following guidelines: @@ -45,6 +53,8 @@ Your goal is to deliver detailed insights into investment decisions and highligh - Ensure the condensed sentence captures the essence of the lessons and reasoning for easy reference. Adhere strictly to these instructions, and ensure your output is detailed, accurate, and actionable. You will also be given objective descriptions of the market from a price movements, technical indicator, news, and sentiment perspective to provide more context for your analysis. + +Output language: ***{self.language_prompt}*** """ def _extract_current_situation(self, current_state: Dict[str, Any]) -> str: diff --git a/tradingagents/graph/signal_processing.py b/tradingagents/graph/signal_processing.py index bff77b4d..7be34201 100644 --- a/tradingagents/graph/signal_processing.py +++ b/tradingagents/graph/signal_processing.py @@ -7,8 +7,16 @@ from langchain_core.language_models.chat_models import BaseChatModel class SignalProcessor: """Processes trading signals to extract actionable decisions.""" - def __init__(self, quick_thinking_llm: BaseChatModel): + def __init__(self, quick_thinking_llm: BaseChatModel, config): """Initialize with an LLM for processing.""" + language = config["output_language"] + language_prompts = { + "en": "", + "zh-tw": "Use Traditional Chinese as the output.", + "zh-cn": "Use Simplified Chinese as the output.", + } + self.language_prompt = language_prompts.get(language, "") + self.quick_thinking_llm = quick_thinking_llm def process_signal(self, full_signal: str) -> str: @@ -24,7 +32,13 @@ class SignalProcessor: messages = [ ( "system", - "You are an efficient assistant designed to analyze paragraphs or financial reports provided by a group of analysts. Your task is to extract the investment decision: SELL, BUY, or HOLD. Provide only the extracted decision (SELL, BUY, or HOLD) as your output, without adding any additional text or information.", + f""" + You are an efficient assistant designed to analyze paragraphs or financial reports provided by a group of analysts. + Your task is to extract the investment decision: SELL, BUY, or HOLD. + Provide only the extracted decision (SELL, BUY, or HOLD) as your output, without adding any additional text or information. + + Output language: ***{self.language_prompt}*** + """, ), ("human", full_signal), ] diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index c9239aa5..ae5b0ac1 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -109,8 +109,8 @@ class TradingAgentsGraph: ) self.propagator = Propagator() - self.reflector = Reflector(self.quick_thinking_llm) - self.signal_processor = SignalProcessor(self.quick_thinking_llm) + self.reflector = Reflector(self.quick_thinking_llm, self.config) + self.signal_processor = SignalProcessor(self.quick_thinking_llm, self.config) # State tracking self.curr_state = None