Implementation:HKUDS AI Trader Get Agent System Prompt
| Knowledge Sources | |
|---|---|
| Domains | Prompt_Engineering, LLM_Agents |
| Last Updated | 2026-02-09 14:00 GMT |
Overview
Concrete tool for building context-rich system prompts with live market data injection for LLM trading agents.
Description
The get_agent_system_prompt function constructs the full system prompt for each trading day. It fetches yesterday's buy/sell prices via get_yesterday_open_and_close_price(), today's open prices via get_open_prices(), and current holdings via get_today_init_position(). These are formatted and injected into a template string that includes trading rules and the STOP_SIGNAL termination token.
The STOP_SIGNAL constant is defined as "<FINISH_SIGNAL>" and is injected into the prompt template so the agent knows how to signal completion.
Usage
Call this function at the start of each trading session (daily loop iteration) to generate the system prompt passed to create_agent(). Different prompt modules exist for each market: agent_prompt.py (US), agent_prompt_astock.py (A-share), agent_prompt_crypto.py (crypto).
Code Reference
Source Location
- Repository: AI-Trader
- File: prompts/agent_prompt.py
- Lines: L62-88
Signature
STOP_SIGNAL = "<FINISH_SIGNAL>" # L23
def get_agent_system_prompt(
today_date: str,
signature: str,
market: str = "us",
stock_symbols: Optional[List[str]] = None
) -> str:
"""
Construct the system prompt for a trading agent on a given date.
Args:
today_date: Current trading date in YYYY-MM-DD format
signature: Agent model name/identifier
market: Market type ("us" or "cn")
stock_symbols: Override symbol list (defaults to NASDAQ-100 or SSE-50)
Returns:
Formatted system prompt string with market data and trading rules
"""
Import
from prompts.agent_prompt import get_agent_system_prompt, STOP_SIGNAL
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| today_date | str | Yes | Trading date YYYY-MM-DD |
| signature | str | Yes | Agent model name for identification |
| market | str | No | Market type: "us" (default) or "cn" |
| stock_symbols | Optional[List[str]] | No | Override symbol list (defaults to NASDAQ-100 or SSE-50) |
Outputs
| Name | Type | Description |
|---|---|---|
| system_prompt | str | Complete system prompt with date, positions, prices, rules, and STOP_SIGNAL |
Usage Examples
Generate US Stock Prompt
from prompts.agent_prompt import get_agent_system_prompt
prompt = get_agent_system_prompt(
today_date="2025-01-15",
signature="gpt-4o",
market="us"
)
# Returns prompt containing:
# - Date: 2025-01-15
# - Current positions from position.jsonl
# - Yesterday's close prices for all NASDAQ-100 stocks
# - Today's open prices
# - Trading rules and STOP_SIGNAL