feat: config max_tokens for reports
This commit is contained in:
parent
72eb16bbea
commit
a242f1532b
|
|
@ -1,6 +1,7 @@
|
|||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_fundamentals_analyst(llm, toolkit):
|
||||
|
|
@ -15,6 +16,7 @@ def create_fundamentals_analyst(llm, toolkit):
|
|||
|
||||
system_message = (
|
||||
get_prompts("analysts", "fundamentals_analyst", "system_message")
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"]))
|
||||
)
|
||||
|
||||
prompt = ChatPromptTemplate.from_messages(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_market_analyst(llm, toolkit):
|
||||
|
|
@ -16,6 +17,7 @@ def create_market_analyst(llm, toolkit):
|
|||
|
||||
system_message = (
|
||||
get_prompts("analysts", "market_analyst", "system_message")
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"]))
|
||||
)
|
||||
|
||||
prompt = ChatPromptTemplate.from_messages(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_news_analyst(llm, toolkit):
|
||||
|
|
@ -18,6 +19,7 @@ def create_news_analyst(llm, toolkit):
|
|||
|
||||
system_message = (
|
||||
get_prompts("analysts", "news_analyst", "system_message")
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"]))
|
||||
)
|
||||
|
||||
prompt = ChatPromptTemplate.from_messages(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_social_media_analyst(llm, toolkit):
|
||||
|
|
@ -16,6 +17,7 @@ def create_social_media_analyst(llm, toolkit):
|
|||
|
||||
system_message = (
|
||||
get_prompts("analysts", "social_media_analyst", "system_message")
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"]))
|
||||
)
|
||||
|
||||
prompt = ChatPromptTemplate.from_messages(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_research_manager(llm, memory):
|
||||
|
|
@ -20,6 +21,7 @@ def create_research_manager(llm, memory):
|
|||
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)
|
||||
response = llm.invoke(prompt)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_risk_manager(llm, memory):
|
||||
|
|
@ -23,6 +24,7 @@ def create_risk_manager(llm, memory):
|
|||
past_memory_str += rec["recommendation"] + "\n\n"
|
||||
|
||||
prompt = get_prompts("managers", "risk_manager") \
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"])) \
|
||||
.replace("{trader_plan}", trader_plan) \
|
||||
.replace("{past_memory_str}", past_memory_str) \
|
||||
.replace("{history}", history)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from langchain_core.messages import AIMessage
|
||||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_bear_researcher(llm, memory):
|
||||
|
|
@ -23,6 +24,7 @@ def create_bear_researcher(llm, memory):
|
|||
past_memory_str += rec["recommendation"] + "\n\n"
|
||||
|
||||
prompt = get_prompts("researchers", "bear_researcher") \
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"])) \
|
||||
.replace("{market_research_report}", market_research_report) \
|
||||
.replace("{sentiment_report}", sentiment_report) \
|
||||
.replace("{news_report}", news_report) \
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from langchain_core.messages import AIMessage
|
||||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_bull_researcher(llm, memory):
|
||||
|
|
@ -23,6 +24,7 @@ def create_bull_researcher(llm, memory):
|
|||
past_memory_str += rec["recommendation"] + "\n\n"
|
||||
|
||||
prompt = get_prompts("researchers", "bull_researcher") \
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"])) \
|
||||
.replace("{market_research_report}", market_research_report) \
|
||||
.replace("{sentiment_report}", sentiment_report) \
|
||||
.replace("{news_report}", news_report) \
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_risky_debator(llm):
|
||||
|
|
@ -19,6 +20,7 @@ def create_risky_debator(llm):
|
|||
trader_decision = state["trader_investment_plan"]
|
||||
|
||||
prompt = get_prompts("risk_mgmt", "aggressive_debator") \
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"])) \
|
||||
.replace("{trader_decision}", trader_decision) \
|
||||
.replace("{market_research_report}", market_research_report) \
|
||||
.replace("{sentiment_report}", sentiment_report) \
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from langchain_core.messages import AIMessage
|
||||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_safe_debator(llm):
|
||||
|
|
@ -20,6 +21,7 @@ def create_safe_debator(llm):
|
|||
trader_decision = state["trader_investment_plan"]
|
||||
|
||||
prompt = get_prompts("risk_mgmt", "conservative_debator") \
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"])) \
|
||||
.replace("{trader_decision}", trader_decision) \
|
||||
.replace("{market_research_report}", market_research_report) \
|
||||
.replace("{sentiment_report}", sentiment_report) \
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import time
|
||||
import json
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.i18n import get_prompts
|
||||
|
||||
def create_neutral_debator(llm):
|
||||
|
|
@ -19,6 +20,7 @@ def create_neutral_debator(llm):
|
|||
trader_decision = state["trader_investment_plan"]
|
||||
|
||||
prompt = get_prompts("risk_mgmt", "neutral_debator") \
|
||||
.replace("{max_tokens}", str(DEFAULT_CONFIG["max_tokens"])) \
|
||||
.replace("{trader_decision}", trader_decision) \
|
||||
.replace("{market_research_report}", market_research_report) \
|
||||
.replace("{sentiment_report}", sentiment_report) \
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ DEFAULT_CONFIG = {
|
|||
"quick_think_llm": "qwen-turbo",
|
||||
"backend_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
|
||||
"api_key_env_name": "DASHSCOPE_API_KEY",
|
||||
"max_tokens": 1000, # Maximum tokens for LLM responses
|
||||
"max_tokens": 500, # Maximum tokens for LLM responses
|
||||
# Debate and discussion settings
|
||||
"max_debate_rounds": 1,
|
||||
"max_risk_discuss_rounds": 1,
|
||||
|
|
|
|||
|
|
@ -59,14 +59,14 @@ class TradingAgentsGraph:
|
|||
|
||||
# Initialize LLMs
|
||||
if self.config["llm_provider"].lower() == "openai" or self.config["llm_provider"] == "ollama" or self.config["llm_provider"] == "openrouter":
|
||||
self.deep_thinking_llm = ChatOpenAI(model=self.config["deep_think_llm"], base_url=self.config["backend_url"])
|
||||
self.quick_thinking_llm = ChatOpenAI(model=self.config["quick_think_llm"], base_url=self.config["backend_url"])
|
||||
self.deep_thinking_llm = ChatOpenAI(model=self.config["deep_think_llm"], base_url=self.config["backend_url"], max_completion_tokens=self.config["max_tokens"])
|
||||
self.quick_thinking_llm = ChatOpenAI(model=self.config["quick_think_llm"], base_url=self.config["backend_url"], max_completion_tokens=self.config["max_tokens"])
|
||||
elif self.config["llm_provider"].lower() == "qwen":
|
||||
self.deep_thinking_llm = ChatOpenAI(model=self.config["deep_think_llm"], base_url=self.config["backend_url"], api_key=os.getenv("DASHSCOPE_API_KEY"))
|
||||
self.quick_thinking_llm = ChatOpenAI(model=self.config["quick_think_llm"], base_url=self.config["backend_url"], api_key=os.getenv("DASHSCOPE_API_KEY"))
|
||||
self.deep_thinking_llm = ChatOpenAI(model=self.config["deep_think_llm"], base_url=self.config["backend_url"], api_key=os.getenv("DASHSCOPE_API_KEY"), max_completion_tokens=self.config["max_tokens"])
|
||||
self.quick_thinking_llm = ChatOpenAI(model=self.config["quick_think_llm"], base_url=self.config["backend_url"], api_key=os.getenv("DASHSCOPE_API_KEY"), max_completion_tokens=self.config["max_tokens"])
|
||||
elif self.config["llm_provider"].lower() == "anthropic":
|
||||
self.deep_thinking_llm = ChatAnthropic(model=self.config["deep_think_llm"], base_url=self.config["backend_url"])
|
||||
self.quick_thinking_llm = ChatAnthropic(model=self.config["quick_think_llm"], base_url=self.config["backend_url"])
|
||||
self.deep_thinking_llm = ChatAnthropic(model=self.config["deep_think_llm"], base_url=self.config["backend_url"], max_tokens_to_sample=self.config["max_tokens"])
|
||||
self.quick_thinking_llm = ChatAnthropic(model=self.config["quick_think_llm"], base_url=self.config["backend_url"], max_tokens_to_sample=self.config["max_tokens"])
|
||||
elif self.config["llm_provider"].lower() == "google":
|
||||
self.deep_thinking_llm = ChatGoogleGenerativeAI(model=self.config["deep_think_llm"])
|
||||
self.quick_thinking_llm = ChatGoogleGenerativeAI(model=self.config["quick_think_llm"])
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ PROMPTS = {
|
|||
#region Fundamentals Analyst
|
||||
"fundamentals_analyst": {
|
||||
"system_message": (
|
||||
"你是一名研究员,负责分析目标公司过去一周的基本面信息。请撰写一份详尽的报告,内容涵盖:财务文件、公司概况、基本财务数据、财务历史、内部人情绪与交易等,帮助交易员全面理解公司基本面。请避免简单描述为“趋势不明”或“走势复杂”,务必提供深入细致的分析与洞察。" +
|
||||
"你是一名研究员,负责分析目标公司过去一周的基本面信息。请撰写一份详尽的但不超过 {max_tokens}tokens 的报告,内容涵盖:财务文件、公司概况、基本财务数据、财务历史、内部人情绪与交易等,帮助交易员全面理解公司基本面。请避免简单描述为“趋势不明”或“走势复杂”,务必提供深入细致的分析与洞察。" +
|
||||
" 最后请附上一张 Markdown 表格,总结并清晰地整理报告中的关键要点,便于阅读和参考。"
|
||||
)
|
||||
},
|
||||
|
|
@ -43,8 +43,9 @@ MACD 相关指标:
|
|||
成交量指标:
|
||||
- vwma: 成交量加权移动平均线(VWMA):基于成交量加权的价格平均。用途:将价格走势与成交量结合,确认趋势强度。提示:成交量激增时可能造成偏差,建议搭配其他成交量指标使用。
|
||||
|
||||
选择提供多样化和互补信息的指标。避免冗余(例如,不要同时选择rsi和stochrsi)。还简要解释为什么它们适合给定的市场环境。请调用 get_binance_data 以获取资产的 K 线、深度、24 小时价格变化、多空比等数据,为了获取中短期的数据,传入 interval 参数时,请保证其范围为5m至1d之间,此外,必须分析15m和1h的趋势。
|
||||
写一份非常详细和细致入微的报告,说明你观察到的趋势。不要简单地说趋势是混合的,提供详细和细粒度的分析和见解,以帮助交易者做出决策。""" +
|
||||
选择提供多样化和互补信息的指标。避免冗余(例如,不要同时选择rsi和stochrsi)。还简要解释为什么它们适合给定的市场环境。
|
||||
请调用 get_binance_data 以获取资产的 K 线、深度、24 小时价格变化、多空比等数据,为了获取中短期的数据,传入 interval 参数时,请保证其范围为5m至1d之间,此外,必须分析15m和1h的趋势。
|
||||
写一份详细但不超过 {max_tokens}tokens 的报告,说明你观察到的趋势。不要简单地说趋势是混合的,提供详细和细粒度的分析和见解,以帮助交易者做出决策。""" +
|
||||
" 最后请附上一张 Markdown 表格,总结并清晰地整理报告中的关键要点,便于阅读和参考。"
|
||||
)
|
||||
},
|
||||
|
|
@ -53,7 +54,7 @@ MACD 相关指标:
|
|||
#region News Analyst
|
||||
"news_analyst": {
|
||||
"system_message": (
|
||||
"你是一名新闻研究员,负责分析过去一周内影响交易与宏观经济的重要新闻与趋势。请撰写一份全面的分析报告,整合来自 Blockbeats 与 CoinDesk 的新闻数据。避免使用模糊措辞如“走势复杂”,应深入剖析市场动态与潜在影响,提供有助于交易判断的洞察。" +
|
||||
"你是一名新闻研究员,负责分析过去一周内影响交易与宏观经济的重要新闻与趋势。请撰写一份全面的但不超过 {max_tokens}tokens 的分析报告,整合来自 Blockbeats 与 CoinDesk 的新闻数据。避免使用模糊措辞如“走势复杂”,应深入剖析市场动态与潜在影响,提供有助于交易判断的洞察。" +
|
||||
" 最后请附上一张 Markdown 表格,总结并清晰地整理报告中的关键要点,便于阅读和参考。"
|
||||
)
|
||||
},
|
||||
|
|
@ -62,7 +63,7 @@ MACD 相关指标:
|
|||
#region Social Media Analyst
|
||||
"social_media_analyst": {
|
||||
"system_message": (
|
||||
"你是一名社交媒体与公司新闻研究员,任务是分析某家公司过去一周在社交平台、新闻媒体上的舆情与公众情绪。请撰写一份详细报告,内容包括:社交媒体舆情、情绪变化趋势、公司相关新闻、公众评价等内容,分析对投资者的潜在影响。请避免笼统表达,深入挖掘细节与数据,提供交易决策支持。" +
|
||||
"你是一名社交媒体与公司新闻研究员,任务是分析某家公司过去一周在社交平台、新闻媒体上的舆情与公众情绪。请撰写一份详细但不超过 {max_tokens}tokens 的报告,内容包括:社交媒体舆情、情绪变化趋势、公司相关新闻、公众评价等内容,分析对投资者的潜在影响。请避免笼统表达,深入挖掘细节与数据,提供交易决策支持。" +
|
||||
" 最后请附上一张 Markdown 表格,总结并清晰地整理报告中的关键要点,便于阅读和参考。"
|
||||
)
|
||||
}
|
||||
|
|
@ -72,7 +73,8 @@ MACD 相关指标:
|
|||
#region Research Manager
|
||||
"research_manager": """你是一名投资组合经理与辩论评审人,负责评估多头与空头分析师的论点,并做出明确立场:支持买入、卖出或(仅在有充分理由时)选择持有。请简明总结双方的关键论点,聚焦最有说服力的证据或逻辑。
|
||||
|
||||
输出内容包括:投资建议:Buy / Sell / Hold(三选一,必须明确,避免默认中立)
|
||||
输出内容包括(务必不超过{max_tokens}tokens):
|
||||
投资建议:Buy / Sell / Hold(三选一,必须明确,避免默认中立)
|
||||
推荐理由:说明为何你支持该立场,引用论据
|
||||
策略行动:基于建议提出具体的执行计划
|
||||
|
||||
|
|
@ -97,6 +99,7 @@ MACD 相关指标:
|
|||
输出要求:
|
||||
- 明确的投资建议:Buy / Sell / Hold
|
||||
- 基于辩论与反思的详细理由
|
||||
- 务必不超过{max_tokens}tokens
|
||||
|
||||
分析师辩论历史:
|
||||
{history}"""
|
||||
|
|
@ -121,7 +124,7 @@ Conversation history of the debate: {history}
|
|||
Last bull argument: {current_response}
|
||||
Reflections from similar situations and lessons learned: {past_memory_str}
|
||||
|
||||
请结合以上内容分析为什么不建议投资该资产,并回应Bull Analyst的观点,展现该资产存在的风险与弱点。你还必须反思,从过去的教训和错误中吸取教训。""",
|
||||
请结合以上内容分析为什么不建议投资该资产,并回应Bull Analyst的观点,展现该资产存在的风险与弱点。你还必须反思,从过去的教训和错误中吸取教训。请注意,输出务必不超过{max_tokens}tokens。""",
|
||||
#endregion
|
||||
|
||||
#region Bull Researcher
|
||||
|
|
@ -142,7 +145,7 @@ Conversation history of the debate: {history}
|
|||
Last bear argument: {current_response}
|
||||
Reflections from similar situations and lessons learned: {past_memory_str}
|
||||
|
||||
请整合所有信息分析为什么建议投资该资产,并反驳Bear Analyst的观点。你还必须反思,从过去的教训和错误中吸取教训。"""
|
||||
请整合所有信息分析为什么建议投资该资产,并反驳Bear Analyst的观点。你还必须反思,从过去的教训和错误中吸取教训。请注意,输出务必不超过{max_tokens}tokens。""",
|
||||
#endregion
|
||||
},
|
||||
"risk_mgmt": {
|
||||
|
|
@ -157,7 +160,7 @@ Latest World Affairs Report: {news_report}
|
|||
Company Fundamentals Report: {fundamentals_report}
|
||||
Here is the current conversation history: {history} Here are the last arguments from the conservative analyst: {current_safe_response} Here are the last arguments from the neutral analyst: {current_neutral_response}. If there are no responses from the other viewpoints, do not halluncinate and just present your point.
|
||||
|
||||
如果没有其他观点的发言,请不要凭空臆测,只表达你自己的立场。请以对话风格回应具体观点,无需特殊格式。""",
|
||||
如果没有其他观点的发言,请不要凭空臆测,只表达你自己的立场。请以对话风格回应具体观点,无需特殊格式,输出务必不超过{max_tokens}tokens。""",
|
||||
#endregion
|
||||
|
||||
#region Conservative Debator
|
||||
|
|
@ -171,7 +174,7 @@ Latest World Affairs Report: {news_report}
|
|||
Company Fundamentals Report: {fundamentals_report}
|
||||
Here is the current conversation history: {history} Here is the last response from the risky analyst: {current_risky_response} Here is the last response from the neutral analyst: {current_neutral_response}. If there are no responses from the other viewpoints, do not halluncinate and just present your point.
|
||||
|
||||
如果没有其他观点的发言,请不要凭空臆测,只表达你自己的立场。请以对话风格回应具体观点,无需特殊格式。""",
|
||||
如果没有其他观点的发言,请不要凭空臆测,只表达你自己的立场。请以对话风格回应具体观点,无需特殊格式,输出务必不超过{max_tokens}tokens。""",
|
||||
#endregion
|
||||
|
||||
#region Neutral Debator
|
||||
|
|
@ -185,7 +188,7 @@ Latest World Affairs Report: {news_report}
|
|||
Company Fundamentals Report: {fundamentals_report}
|
||||
Here is the current conversation history: {history} Here is the last response from the risky analyst: {current_risky_response} Here is the last response from the safe analyst: {current_safe_response}. If there are no responses from the other viewpoints, do not halluncinate and just present your point.
|
||||
|
||||
如果没有其他观点的发言,请不要凭空臆测,只表达你自己的立场。请以对话风格回应具体观点,无需特殊格式。"""
|
||||
如果没有其他观点的发言,请不要凭空臆测,只表达你自己的立场。请以对话风格回应具体观点,无需特殊格式,输出务必不超过{max_tokens}tokens。"""
|
||||
#endregion
|
||||
},
|
||||
"trader": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue