How to Format the Execution Order Prompt for an AutoHedge Agent
The Execution Order Prompt in AutoHedge is a strictly formatted template defined in autohedge/prompts.py that forces the language model to output trade instructions in a machine-parseable format like BUY NVDA 150 @ MARKET, ensuring the agent converts allocation plans into actionable broker commands without hallucinated commentary.
Formatting the Execution Order Prompt correctly is essential for autonomous trading agents in the AutoHedge repository. This prompt template dictates exactly how the agent must structure its buy and sell instructions to ensure downstream systems can parse and execute trades reliably. Understanding the precise syntax and integration points prevents parsing errors and ensures seamless handoff from the language model to the execution layer.
Understanding the Execution Order Prompt Structure
Prompt Definition in autohedge/prompts.py
According to the AutoHedge source code, the Execution Order Prompt resides in autohedge/prompts.py as the EXECUTION_PROMPT constant. This string template establishes the rules the agent must follow when generating trade orders, including strict prohibitions against explanatory text.
The prompt typically includes formatting constraints such as:
# autohedge/prompts.py
_EXECUTION_SUFFIX = "\nRemember: only output the order lines."
EXECUTION_PROMPT = f"""
You are now in the Execution phase.
Your goal is to translate the allocation plan into concrete trade orders.
Follow these rules strictly:
1. Use the provided ticker symbols and target percentages.
2. Respect the available cash and position limits.
3. Output orders in the exact format:
<ACTION> <TICKER> <SIZE> @ <PRICE>
where <ACTION> is BUY or SELL, <SIZE> is a numeric share count,
and <PRICE> is either MARKET or a limit price.
4. Do not add any explanations or commentary – only the order lines.
""" + _EXECUTION_SUFFIX
Required Output Format
The Execution Order Prompt mandates a specific line-based structure that the parsing logic in the downstream tools expects. Each valid order line must contain exactly four elements separated by spaces: the action (BUY or SELL), the ticker symbol, the number of shares, the literal @ symbol, and the price instruction (MARKET or a numeric limit price).
Any deviation from this format—including introductory phrases like "Here are the orders:" or explanatory notes—will cause the order parser to fail. The prompt explicitly forbids markdown formatting, bullet points, or numbered lists in the output, requiring plain text lines that the execution worker can split and validate.
Integrating the Prompt into the Execution Pipeline
Worker Implementation in autohedge/workers.py
The execute_worker function in autohedge/workers.py retrieves EXECUTION_PROMPT from the prompts module and supplies it as the system prompt when the workflow reaches the execution stage. This ensures the language model receives the formatting constraints immediately before generating the trade instructions.
# autohedge/workers.py
from autohedge.prompts import EXECUTION_PROMPT, _SYSTEM_SUFFIX
def execute_worker(context):
# Build the full system prompt for the execution stage
system_prompt = EXECUTION_PROMPT.strip() + _SYSTEM_SUFFIX
# Send prompt + context (allocation plan) to the LLM
response = llm.chat(system_prompt, user_message=context['allocation_plan'])
# Parse the response into order objects
orders = parse_orders(response)
return orders
The worker passes the allocation_plan generated by previous stages as the user message, while the EXECUTION_PROMPT serves as the system-level instruction set that constrains the model's output format.
Orchestration in autohedge/main.py
The main orchestration layer in autohedge/main.py coordinates the pipeline, ensuring the Execution Order Prompt is only invoked after sentiment analysis and risk assessment phases complete. This sequential approach guarantees that the execution agent receives a validated allocation plan before attempting to format orders.
# autohedge/main.py
from autohedge.workers import sentiment_worker, risk_worker, execute_worker
def run_task(task_prompt):
# 1️⃣ Sentiment analysis
sentiment = sentiment_worker(task_prompt)
# 2️⃣ Risk & allocation calculation
allocation = risk_worker(sentiment)
# 3️⃣ Execution – this is where EXECUTION_PROMPT is used
orders = execute_worker({'allocation_plan': allocation})
# Send orders to the broker (handled elsewhere)
submit_orders(orders)
Practical Code Examples
Defining a Custom Execution Prompt
When adapting AutoHedge for specific broker APIs, you may need to adjust the prompt while maintaining the core formatting constraints:
# autohedge/prompts.py
EXECUTION_PROMPT = """
You are now in the Execution phase.
Your goal is to translate the quantitative allocation plan into concrete trade orders.
Follow these rules strictly:
1. Use the provided ticker symbols and target percentages.
2. Respect the available cash and position limits.
3. Output orders in the exact format:
<ACTION> <TICKER> <SIZE> @ <PRICE>
where <ACTION> is BUY or SELL, <SIZE> is a numeric share count, and <PRICE> is either MARKET or a limit price.
4. Do not add any explanations or commentary – only the order lines.
"""
Parsing the Model Output
The execution worker expects output that can be directly split into structured order objects. Valid output looks like:
BUY NVDA 150 @ MARKET
SELL AAPL 75 @ 180.50
BUY TSLA 30 @ LIMIT 250.00
If the model includes conversational text such as "Certainly! Here are your orders:" or uses markdown code blocks, the parse_orders function will raise a validation error, preventing malformed instructions from reaching the broker API.
Summary
- The Execution Order Prompt is defined in
autohedge/prompts.pyasEXECUTION_PROMPTand enforces strict formatting rules for trade instructions. - The prompt requires machine-parseable output in the format
<ACTION> <TICKER> <SIZE> @ <PRICE>with no additional commentary. - The
execute_workerfunction inautohedge/workers.pyretrieves this prompt and passes it to the language model during the execution phase. - The orchestration layer in
autohedge/main.pyensures the execution stage runs only after sentiment and risk analysis complete. - Deviations from the specified format cause parsing failures, making prompt discipline critical for reliable autonomous trading.
Frequently Asked Questions
What file contains the Execution Order Prompt in AutoHedge?
The Execution Order Prompt is defined in autohedge/prompts.py as the EXECUTION_PROMPT string constant. This file serves as the central repository for all system prompts used across the AutoHedge agent workflow, including sentiment analysis and risk assessment templates.
How does the agent know when to use the Execution Order Prompt?
The execute_worker function in autohedge/workers.py explicitly imports EXECUTION_PROMPT from autohedge/prompts.py and supplies it as the system prompt when the pipeline enters the execution stage. The orchestration logic in autohedge/main.py triggers this worker only after preliminary analysis phases complete, ensuring the prompt is applied at the correct decision point.
What happens if the model outputs extra text beyond the order format?
If the language model includes explanatory text, markdown formatting, or conversational filler beyond the strict line-based order format, the parse_orders function in the execution worker will fail to validate the response. This validation failure prevents malformed instructions from reaching the broker API, protecting against potentially erroneous trades caused by hallucinated content.
Can I customize the Execution Order Prompt for different brokers?
Yes, you can modify EXECUTION_PROMPT in autohedge/prompts.py to accommodate broker-specific order syntax, provided you maintain the core constraint that the model outputs only machine-parseable order lines. When customizing, ensure you also update the parsing logic in the execution worker to handle any new format variations you introduce.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →