Understanding the Structured Output from AutoHedge Agents: A Complete Schema Guide

AutoHedge agents return machine-readable JSON schemas defined in autohedge/prompts.py, with the Director emitting plain text thesis, Quant Analyst returning technical scores, Risk Manager providing position sizing data, and Execution Agent generating broker-ready order objects.

The AutoHedge trading system orchestrates a multi-agent pipeline where specialized LLM agents communicate through strictly defined data contracts. Each agent in the The-Swarm-Corporation/AutoHedge repository—except the Director—outputs structured JSON that downstream components consume for automated trading decisions.

The Four-Agent Pipeline Architecture

AutoHedge drives a sequential workflow through four specialized agents. Three of these enforce strict structured output schemas, while the Director provides free-form contextual analysis.

Director Agent: Textual Thesis Generation

The Director operates through the DIRECTOR_PROMPT template (lines 5-21 in autohedge/prompts.py). Unlike other agents, it returns plain text (e.g., "Long XYZ because...") rather than structured JSON. This textual thesis feeds into subsequent agents as contextual grounding.

Quant Analyst Agent: Technical Evaluation Schema

The Quant Analyst produces granular market analysis via QUANT_ANALYSIS_PROMPT located at lines 75-90 in autohedge/prompts.py. The agent returns a JSON object with normalized scoring:

{
  "ticker": "str",
  "technical_score": 0-1,
  "volume_score": 0-1,
  "trend_strength": 0-1,
  "volatility": "float",
  "probability_score": 0-1,
  "key_levels": {
    "support": "float",
    "resistance": "float",
    "pivot": "float"
  }
}

Risk Manager Agent: Position Sizing Schema

Defined in RISK_ASSESSMENT_PROMPT (lines 41-49 in autohedge/prompts.py), this agent evaluates portfolio exposure and returns:

{
  "recommended_position_size": "float",
  "max_drawdown_risk": "float",
  "market_risk_exposure": "float",
  "overall_risk_score": 0-1
}

Execution Agent: Broker-Ready Order Schema

The final agent generates executable orders through EXECUTION_ORDER_PROMPT (lines 152-165 in autohedge/prompts.py). This structured output aligns with standard brokerage API requirements:

{
  "order_type": "market|limit|stop",
  "quantity": "int",
  "entry_price": "float",
  "stop_loss": "float",
  "take_profit": "float",
  "time_in_force": "str"
}

Technical Implementation in the Source Code

Agent instantiation occurs in autohedge/workers.py, where each worker is configured with output_type="str". The system appends _SYSTEM_SUFFIX (current date/time) to system prompts, ensuring temporal context while maintaining JSON output constraints. According to the source, the pipeline flow executes sequentially:

  1. Director creates the textual thesis
  2. Quant Analyst receives the thesis and returns technical JSON
  3. Risk Manager consumes both thesis and Quant output to produce risk JSON
  4. Execution Agent synthesizes all prior outputs into the final order JSON

Processing Structured Output in Practice

The AutoHedge class in autohedge/main.py orchestrates the complete trading cycle. Configure output_type="dict" to receive parsed agent responses as dictionary keys containing JSON strings.

from autohedge.main import AutoHedge
import json

# Initialize with dict output for structured access

auto = AutoHedge(output_type="dict")

# Execute full analysis pipeline

result = auto.run("Analyse AAPL and generate a trade plan.")

# Parse structured JSON outputs

quant_data = json.loads(result["quant"])
risk_data = json.loads(result["risk"])
exec_data = json.loads(result["execution"])

print("Technical Analysis:", quant_data)
print("Risk Assessment:", risk_data)
print("Execution Order:", exec_data)

The auto.run() method returns the conversation history containing the Director's thesis and each agent's structured JSON payload, enabling direct parsing into Python dictionaries for downstream automation.

Summary

  • AutoHedge implements a strict structured output protocol across three of four agents
  • Schema definitions reside in autohedge/prompts.py with specific line references for each agent type
  • Execution Agent produces brokerage-API-compatible order objects with type, quantity, pricing, and time-in-force fields
  • Workers use output_type="str" configuration in autohedge/workers.py to ensure consistent JSON string delivery
  • The pipeline processes sequentially: Director → Quant → Risk → Execution

Frequently Asked Questions

What is the structured output format for the Quant Analyst?

The Quant Analyst returns a JSON object containing technical_score, volume_score, trend_strength, volatility, probability_score (all float values between 0-1 where applicable), plus a nested key_levels object specifying support, resistance, and pivot price levels.

Does the Director agent return structured data?

No. According to the DIRECTOR_PROMPT implementation in autohedge/prompts.py, the Director returns free-form plain text representing the trading thesis. This unstructured output serves as contextual input for the three downstream agents that enforce JSON schemas.

How does the structured output from AutoHedge agents enforce schema compliance?

Schema enforcement relies on explicit JSON examples embedded directly in prompt templates within autohedge/prompts.py. The Agent definitions in autohedge/workers.py use output_type="str" to capture raw string responses, while the prompts themselves instruct the LLM to return only valid JSON matching the specified structure.

Can the Execution Agent's output connect directly to live brokerage APIs?

Yes. The Execution Agent's structured output in autohedge/prompts.py uses standard brokerage fields including order_type, quantity, entry_price, stop_loss, take_profit, and time_in_force, making it compatible with most trading APIs without additional transformation.

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 →