How to Customize Debate Prompts for Bull and Bear Researchers in TradingAgents-CN

Customize debate prompts in TradingAgents-CN by editing the f-string templates in bull_researcher.py and bear_researcher.py, or externalize them to YAML for easier maintenance.

The multi-agent debate system in TradingAgents-CN relies on specialized prompts to guide bull and bear researchers through investment discussions. Customizing these debate prompts allows you to adjust the tone, add specific instructions, or inject additional market data variables. This guide shows you exactly where and how to modify the prompt templates in the TradingAgents-CN codebase.

Where Debate Prompts Are Defined in TradingAgents-CN

The debate prompts are hard-coded as Python f-strings in two specific agent files:

When the workflow reaches the research stage, each researcher builds a prompt string at runtime that embeds market reports, sentiment analysis, news, fundamentals, debate history, the opponent's last argument, and company metadata. This string is then passed to the LLM via llm.invoke(prompt).

How to Customize the Bull Researcher Prompt

Open tradingagents/agents/researchers/bull_researcher.py and locate the f-string assignment to the prompt variable. This typically appears within the main researcher function where state variables are extracted.

To add a citation requirement, modify the f-string as follows:


# File: tradingagents/agents/researchers/bull_researcher.py

prompt = f"""你是一位看涨分析师,负责为股票 {company_name}(股票代码:{ticker})的投资建立强有力的论证。

⚠️ 重要提醒:当前分析的是 {'中国A股' if is_china else '海外股票'},所有价格和估值请使用 {currency}{currency_symbol})作为单位。
⚠️ 在你的分析中,请始终使用公司名称"{company_name}"而不是股票代码"{ticker}"来称呼这家公司。

请用中文回答,重点关注以下几个方面:
- 增长潜力:...
- 竞争优势:...
- 积极指标:...
- 反驳看跌观点:...
- 参与讨论:...

📝 **请在每个数据点后标注来源**(如“来源:财报2023 Q4”),以提升报告的可信度。

可用资源:
...
"""

Modifying the Bear Researcher Prompt

The process is identical for the bear researcher in tradingagents/agents/researchers/bear_researcher.py. The bear prompt uses a similar f-string structure but frames the argument against investment. Edit the f-string to adjust the tone, add risk-focused instructions, or modify the structure of the bearish argumentation.

Injecting Custom Variables into Debate Prompts

You can extend the prompt templates to include additional state variables beyond the default set (market reports, sentiment, etc.).

For example, to add a risk_score variable to the bear researcher:


# File: tradingagents/agents/researchers/bear_researcher.py

# Assume risk_score is computed earlier in the node

risk_score = state.get("risk_score", "N/A")   # ← new line

prompt = f"""你是一位看跌分析师,负责论证不投资股票 {company_name}(股票代码:{ticker})的理由。

⚠️ 重要提醒:当前分析的是 {market_info['market_name']},所有价格和估值请使用 {currency}{currency_symbol})作为单位。
⚠️ 在你的分析中,请始终使用公司名称"{company_name}"而不是股票代码"{ticker}"来称呼这家公司。

风险评分:{risk_score}
...
"""

Because the prompts are generated at runtime, any new variable you add to the f-string must be available in the local scope when the prompt is constructed.

Externalizing Prompts to YAML for Easier Maintenance

For production deployments where non-technical users need to adjust prompts, extract the templates into a YAML file instead of editing Python code.

Create config/debate_prompts.yaml:

bull: |
  你是一位看涨分析师,负责为股票 {company_name}(股票代码:{ticker})的投资建立强有力的论证。
  ⚠️ 重要提醒:当前分析的是 {market_desc},所有价格和估值请使用 {currency}({currency_symbol})作为单位。
  ⚠️ 在你的分析中,请始终使用公司名称"{company_name}"而不是股票代码"{ticker}"来称呼这家公司。
  
  请用中文回答,重点关注以下几个方面:
  - 增长潜力:...
  - 竞争优势:...
  - 积极指标:...
  - 反驳看跌观点:...
  - 参与讨论:...
  
  可用资源:
  ...
bear: |
  你是一位看跌分析师,负责论证不投资股票 {company_name}(股票代码:{ticker})的理由。
  ...

Then modify the researcher files to load from YAML:

import yaml
import pathlib

TEMPLATE_PATH = pathlib.Path(__file__).parents[2] / "config" / "debate_prompts.yaml"
templates = yaml.safe_load(TEMPLATE_PATH.read_text())

prompt_template = templates["bull"]   # or ["bear"]

prompt = prompt_template.format(
    company_name=company_name,
    ticker=ticker,
    market_desc='中国A股' if is_china else '海外股票',
    currency=currency,
    currency_symbol=currency_symbol,
    # … other variables …

)

This approach allows prompt modifications without touching the Python source code.

Summary

  • Debate prompts in TradingAgents-CN are defined as Python f-strings in tradingagents/agents/researchers/bull_researcher.py and tradingagents/agents/researchers/bear_researcher.py
  • Customize prompts by editing the f-string templates directly to change tone, add instructions, or modify structure
  • Inject additional variables by extending the format string and providing values from the state object
  • Externalize prompts to YAML or JSON for production environments to enable non-technical customization
  • Changes take effect immediately on the next workflow execution without requiring application restart or redeployment

Frequently Asked Questions

Where are the debate prompts stored in TradingAgents-CN?

The debate prompts are hard-coded as Python f-strings inside tradingagents/agents/researchers/bull_researcher.py and tradingagents/agents/researchers/bear_researcher.py. Each researcher constructs its prompt at runtime by embedding market data, sentiment, news, fundamentals, and debate history into these templates before passing them to the LLM via llm.invoke(prompt).

Can I add custom variables like technical indicators to the debate prompts?

Yes. You can extend the f-string templates to include any variable available in the researcher node's state. For example, you can extract a risk_score or rsi_value from the state object and insert it into the prompt using {variable_name}. Ensure the variable is always defined or provide a default value like state.get("risk_score", "N/A") to avoid KeyError exceptions.

Do I need to restart the application after modifying debate prompts?

No. Because TradingAgents-CN builds the prompts at runtime using standard Python f-strings, any changes to bull_researcher.py or bear_researcher.py take effect immediately on the next execution of the research workflow. No additional configuration, compilation, or redeployment steps are required.

How can I make debate prompts configurable without editing Python code?

Extract the prompt templates into a YAML or JSON file (e.g., config/debate_prompts.yaml) and modify the researcher nodes to load these templates using yaml.safe_load() or json.load(). Use Python's str.format() method to inject variables into the loaded templates. This approach allows non-technical team members to adjust prompt wording, tone, and instructions by editing the external configuration file rather than the source code.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →