How the AutoHedge Multi-Agent Pipeline Works: From Market Analysis to Trade Execution
AutoHedge orchestrates a four-stage multi-agent pipeline where a central Trading Director delegates to specialized Sentiment, Quant, Risk, and Execution agents, transforming high-level trading tasks into structured trade orders through sequential hand-offs.
The AutoHedge multi-agent pipeline provides an autonomous trading workflow that decomposes complex market analysis into discrete, specialized tasks. Implemented in The-Swarm-Corporation/AutoHedge repository, this architecture leverages a director-first delegation pattern to route trading intelligence through a curated chain of AI agents, culminating in executable trade parameters.
Pipeline Architecture: The Four-Stage Flow
AutoHedge implements a director-first → specialized agents → hand-off pattern. While the pipeline involves six distinct operational steps, they logically compress into four conceptual stages: Task Ingestion and Direction, Market Intelligence Gathering, Risk Evaluation, and Order Execution. This architecture ensures that a single natural language request undergoes progressive refinement—from ticker discovery to sentiment analysis, quantitative modeling, risk filtering, and finally, structured order generation.
Stage 1: Task Ingestion and Director Discovery
Initializing the Trading Task
The pipeline begins in autohedge/main.py (lines 33-50), where the AutoHedge class receives user input through its run method. This method instantiates a Conversation object and immediately delegates to the director agent:
# From autohedge/main.py#L33-L50
def run(self, task: str):
conversation = Conversation()
# Task added to conversation context
return self.director_agent.run(task=task)
The Trading Director Agent
Located in autohedge/workers.py (lines 80-87), the director_agent serves as the pipeline's orchestrator. It utilizes the DIRECTOR_PROMPT system prompt, which incorporates DIRECTOR_TICKER_DISCOVERY_PROMPT to parse the user's objective and generate a JSON array of relevant tickers plus an overarching market thesis.
The director configures handfuls=ALL_AGENTS (lines 72-78), ensuring that upon completion, the ticker list and thesis automatically pass to the next phase. This hand-off mechanism eliminates manual chaining between agents.
Stage 2: Market Intelligence Gathering
Sentiment Analysis with EXA Search
The sentiment_agent (defined in autohedge/workers.py, lines 26-33) processes the director's ticker selection using the EXA search tool (exa_search). This tool, implemented in autohedge/tools/exa_search_tool.py, retrieves recent news articles and social media posts.
The agent applies the SENTIMENT_PROMPT (lines 40-80 of autohedge/prompts.py) to generate normalized sentiment scores and extract key thematic drivers for each security.
Quantitative Technical Analysis
Next, the quant_agent (autohedge/workers.py, lines 59-69) consumes both the director's thesis and sentiment output. Using the QUANT_PROMPT (lines 24-38 of autohedge/prompts.py), this agent produces a detailed quantitative snapshot including:
- Technical indicators and trend analysis
- Volume profile and volatility metrics
- Probability assessments and key price levels
Stage 3: Risk Evaluation and Position Sizing
The risk_agent (autohedge/workers.py, lines 35-45) receives the accumulated intelligence—thesis, sentiment scores, and quantitative data—to evaluate trade viability. Guided by the RISK_PROMPT (lines 84-119 of autohedge/prompts.py), it calculates:
- Position sizing based on portfolio constraints
- Maximum drawdown and downside scenarios
- Market exposure correlation risks
- An overall risk score that gates progression to execution
Stage 4: Order Execution and Result Delivery
Trade Construction
The final specialized agent, execution_agent (autohedge/workers.py, lines 47-57), activates only if the risk score meets threshold requirements. Using the EXECUTION_PROMPT (lines 120-138 of autohedge/prompts.py), it constructs structured trade orders specifying:
- Order type (market, limit, stop)
- Quantity and directional bias (long/short)
- Entry price, stop-loss, and take-profit levels
- Time-in-force constraints
Output Collection
The AutoHedge object aggregates the full conversation history—containing intermediate outputs from all agents—and formats the result according to the output_type parameter specified at initialization (autohedge/main.py, lines 52-60). Supported formats include "list" (message array), "dict" (structured object), or "string" (concatenated text).
Running the AutoHedge Pipeline
Initialize the system and execute a complete trading workflow:
from autohedge.main import AutoHedge
# Initialise with dict output for structured data
hedge = AutoHedge(output_type="dict")
# Run full pipeline
result = hedge.run(
task="Identify high‑growth tech stocks and propose trade ideas for the next month."
)
print(result) # Conversation history including director, sentiment, quant, risk, and execution steps
To inspect the director's ticker discovery independently:
from autohedge.workers import director_agent
tickers = director_agent.run(
"Given the task, discover which tickers should be analyzed."
)
print(tickers) # JSON array of ticker symbols
Summary
- The pipeline initiates in
autohedge/main.py, where theAutoHedgeclass manages task ingestion and result formatting. - The Trading Director (
autohedge/workers.pylines 80-87) discovers tickers usingDIRECTOR_TICKER_DISCOVERY_PROMPTand propagates context viahandfuls=ALL_AGENTS. - The Sentiment agent leverages the EXA search tool to score market sentiment per ticker.
- The Quant agent generates technical metrics including volatility, trend probability, and key levels.
- The Risk agent filters opportunities by evaluating drawdown limits, position size, and market exposure.
- The Execution agent produces actionable trade orders with defined entry, exit, and risk parameters.
Frequently Asked Questions
How does the Trading Director select which tickers to analyze?
The Trading Director utilizes the DIRECTOR_TICKER_DISCOVERY_PROMPT defined in autohedge/prompts.py to parse natural language tasks and extract relevant securities. Implemented in autohedge/workers.py (lines 80-87), the director_agent outputs a JSON array of ticker symbols that subsequent agents consume for focused analysis, ensuring the entire pipeline targets securities aligned with the user's market thesis.
What external data sources power the Sentiment agent?
The Sentiment agent relies on the EXA search tool implemented in autohedge/tools/exa_search_tool.py to fetch real-time news and social media content. This tool feeds raw textual data to the sentiment_agent (autohedge/workers.py, lines 26-33), which processes inputs through the SENTIMENT_PROMPT template to generate quantitative sentiment scores and thematic summaries.
Can risk parameters be customized within the AutoHedge pipeline?
Yes, risk evaluation logic resides in the risk_agent (autohedge/workers.py, lines 35-45) and is fully configurable via the RISK_PROMPT in autohedge/prompts.py (lines 84-119). You can modify position sizing algorithms, adjust maximum drawdown thresholds, or add custom exposure constraints by editing this prompt template without altering the core agent logic.
What output formats does the AutoHedge multi-agent pipeline support?
The AutoHedge class in autohedge/main.py (lines 52-60) supports three output formats via the output_type parameter: "list" returns the conversation as an array of message objects, "dict" provides a structured conversation hash, and "string" concatenates all agent outputs into readable text. This flexibility accommodates integration with both automated trading systems and manual review workflows.
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 →