How Trade Orders Are Generated in AutoHedge: Execution Agent Parameters Explained

The Execution Agent generates fully-specified trade orders by processing a stock symbol, investment thesis, and risk assessment through a GPT-4.1 model to determine six critical parameters: order type, quantity, entry price, stop-loss, take-profit, and time-in-force.

The AutoHedge repository implements an LLM-driven trading system where the Execution Agent serves as the bridge between abstract trading strategies and concrete broker instructions. This component translates high-level market analysis into executable order specifications through structured prompt engineering and deterministic output formatting.

How the Execution Agent Generates Trade Orders

The Execution Agent operates as a specialized worker within the AutoHedge architecture, converting qualitative risk assessments into quantitative trading parameters. Its operation relies on two core components: prompt templates defined in the prompts module and agent configuration established in the workers module.

Prompt Engineering in autohedge/prompts.py

The agent's behavior is governed by the EXECUTION_PROMPT constant defined in autohedge/prompts.py (lines 121-136). This system prompt instructs the underlying model to generate structured trade orders containing specific risk-management parameters.

When invoked, the system formats user inputs using the EXECUTION_ORDER_PROMPT template (lines 153-165 in the same file). This template injects the stock symbol, investment thesis, and risk assessment into the prompt context, requesting the model to "Generate trade order including" the six required execution parameters.

Agent Configuration in autohedge/workers.py

The agent instance is created in autohedge/workers.py (lines 47-57) using the EXECUTION_PROMPT as its system instruction. According to the source code, the configuration specifies:

  • Model: gpt-4.1 for high-reasoning capability
  • Output type: str (plain text or JSON-style description)

This instantiation makes the agent available as execution_agent for downstream order generation tasks.

The Six Trade Order Parameters Determined by the Execution Agent

When processing the formatted prompt, the Execution Agent determines the following six parameters that constitute a complete trade order:

  • Order type: Specifies execution mechanics such as market, limit, or stop-loss orders.
  • Quantity: The integer number of shares or contracts to trade.
  • Entry price: The desired price level for initiating the position.
  • Stop loss: The price threshold to automatically exit the position and limit downside risk.
  • Take profit: The target price for closing the position to realize gains.
  • Time in force: Duration constraints governing order validity, such as GTC (Good Till Canceled) or specific start/end dates.

Implementing Trade Order Generation in Practice

The following implementation demonstrates how to invoke the Execution Agent using the prompt templates defined in the AutoHedge source code:


# Example: generating a trade order with the Execution Agent

from autohedge.workers import execution_agent
from autohedge.prompts import EXECUTION_ORDER_PROMPT

stock = "AAPL"
thesis = "Long position based on bullish earnings surprise"
risk_assessment = """
Recommended position size: 200 shares
Maximum drawdown risk: 5%
Market risk exposure: Low
Overall risk score: 0.78
"""

# Fill the order-template prompt

order_prompt = EXECUTION_ORDER_PROMPT.format(
    stock=stock,
    thesis=thesis,
    risk_assessment=risk_assessment,
)

# Run the agent – it returns a string containing the six parameters

order_output = execution_agent.run(order_prompt)
print(order_output)

The agent returns a structured string containing the determined parameters:

Order type: limit
Quantity: 200
Entry price: 172.45
Stop loss: 168.00
Take profit: 180.00
Time in force: GTC

Summary

  • The Execution Agent in AutoHedge serves as an LLM-driven interface between trading strategy and broker execution.
  • Order generation relies on EXECUTION_PROMPT and EXECUTION_ORDER_PROMPT templates located in autohedge/prompts.py.
  • The agent is instantiated in autohedge/workers.py using the gpt-4.1 model with string output configuration.
  • Each trade order specifies six parameters: order type, quantity, entry price, stop loss, take profit, and time in force.
  • Downstream systems parse the agent's text output to submit orders via broker APIs.

Frequently Asked Questions

What model does the Execution Agent use to generate trade orders?

According to the source code in autohedge/workers.py (lines 47-57), the Execution Agent uses the gpt-4.1 model. This configuration provides the reasoning capabilities necessary to interpret risk assessments and translate them into precise numerical order parameters.

How does the Execution Agent receive its input parameters?

The agent receives inputs through the EXECUTION_ORDER_PROMPT template in autohedge/prompts.py (lines 153-165). This template accepts three variables—stock, thesis, and risk_assessment—which are formatted into the prompt string before being passed to the agent's run() method.

Can the Execution Agent output formats other than plain text?

The current implementation in autohedge/workers.py explicitly configures the agent with output_type=str, mandating string output. While the resulting string often follows a structured key-value format suitable for parsing, the system architecture expects plain text rather than structured JSON objects or binary formats.

Where is the Execution Agent instantiated in the AutoHedge codebase?

The agent is instantiated as execution_agent in autohedge/workers.py between lines 47-57. This module-level instantiation makes the configured agent available for import throughout the application, ensuring consistent behavior across all trade order generation operations.

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 →