# How to Integrate AutoHedge with Custom Trading Strategies: 3 Proven Methods

> Learn how to integrate AutoHedge with custom trading strategies using three proven methods. Enhance your trading with custom Director prompts, Agent additions, or class subclassing.

- Repository: [Swarms/AutoHedge](https://github.com/The-Swarm-Corporation/AutoHedge)
- Tags: how-to-guide
- Published: 2026-09-08

---

**You can integrate AutoHedge with custom trading strategies by injecting a custom Director prompt, adding a bespoke Agent to the `ALL_AGENTS` hand-off chain, or subclassing the `AutoHedge` class to override the workflow execution.**

The [The-Swarm-Corporation/AutoHedge](https://github.com/The-Swarm-Corporation/AutoHedge) repository implements a modular, multi-agent trading pipeline where a **Director** agent orchestrates workflow and delegates tasks to specialized agents. Because the system exposes integration points as plain Python objects in [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) and [`autohedge/prompts.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/prompts.py), you can compose custom pipelines without modifying the core codebase.

## Understanding AutoHedge's Modular Architecture

AutoHedge operates as a sequential multi-agent system. The **Director** extracts tickers from user tasks and manages the conversation flow by routing messages through the `ALL_AGENTS` list. Each agent—**Sentiment**, **Quant**, **Risk**, **Execution**, and any custom additions—communicates via a shared `Conversation` object that stores JSON-style messages using loguru and `swarms.Conversation` as implemented in [`autohedge/main.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/main.py) (lines 33-60).

## Method 1: Inject a Custom Director Prompt

You control ticker discovery and high-level strategy criteria by redefining the `DIRECTOR_PROMPT` in [`autohedge/prompts.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/prompts.py) (lines 5-22). This prompt determines how the Director interprets user tasks and which initial thesis it generates before handing off to specialized agents.

## Method 2: Add a New Agent to the Hand-Off Chain

Create a `swarms.Agent` instance that implements your proprietary logic—such as a statistical arbitrage model or machine-learning predictor—and insert it into the `ALL_AGENTS` list in [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) (lines 72-77). The Director automatically routes messages to agents in the order they appear in this list.

## Method 3: Subclass the AutoHedge Class

For advanced control, subclass `AutoHedge` and override the `run` method or replace the internal `director_agent` reference. This approach lets you pre-process tasks, feed additional context, or change output formats while retaining the underlying conversation management.

## Step-by-Step Integration Guide

Follow these specific steps to plug your custom strategy into the existing pipeline:

1. **Define the custom prompt**. Write a string describing your strategy's goals, risk limits, or proprietary signals. Reference the `DIRECTOR_PROMPT` structure in [`autohedge/prompts.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/prompts.py).

2. **Instantiate the Agent**. Use `swarms.Agent` with your prompt, select a model (e.g., `gpt-4.1` or a local LLM), and specify `output_type="dict"` for structured responses. See the `sentiment_agent` implementation in [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) (lines 26-34) for the exact pattern.

3. **Update the hand-off list**. Append your agent to `ALL_AGENTS` in [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) (lines 72-77). Position matters—the Director invokes agents sequentially.

4. **Re-initialize the Director**. Ensure the `director_agent` definition in [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) (lines 80-86) points to the updated `ALL_AGENTS` list via its `handoffs` parameter.

5. **Execute the pipeline**. Instantiate `AutoHedge` and call `run(task=...)` as demonstrated in [`example.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/example.py) (lines 1-11). The system will automatically invoke your custom logic within the agent chain.

## Code Examples

Below is a complete implementation showing how to add a proprietary signal agent and insert it into the pipeline.

```python

# custom_strategy.py

from swarms import Agent
from autohedge.workers import ALL_AGENTS, director_agent
from autohedge.prompts import DIRECTOR_PROMPT, _SYSTEM_SUFFIX

# 1️⃣ Define a prompt that describes your proprietary signal logic

CUSTOM_SIGNAL_PROMPT = """
You are a Proprietary Signal Agent. Your job is to:
1. Receive a stock ticker and any existing thesis.
2. Apply your own algorithm (e.g., a statistical arbitrage model) and output a JSON object:
{
    "signal": "long" | "short",
    "confidence": float,   # 0‑1

    "extra_note": str
}
"""

# 2️⃣ Create the Agent

custom_signal_agent = Agent(
    agent_name="Custom-Signal",
    system_prompt=CUSTOM_SIGNAL_PROMPT + _SYSTEM_SUFFIX,
    model_name="gpt-4.1",               # you may replace with a local model

    output_type="dict",
    max_loops=1,
    verbose=True,
)

# 3️⃣ Insert it into the hand‑off chain (e.g., after Sentiment, before Quant)

ALL_AGENTS.insert(1, custom_signal_agent)  # position matters

# 4️⃣ Re‑initialize the Director so it sees the updated hand‑offs

director_agent = Agent(
    agent_name="Trading-Director",
    system_prompt=DIRECTOR_PROMPT + _SYSTEM_SUFFIX,
    model_name="gpt-4.1",
    max_loops=1,
    handoffs=ALL_AGENTS,
)

# 5️⃣ Use AutoHedge as usual

from autohedge import AutoHedge

auto = AutoHedge(name="my‑custom‑fund")
result = auto.run(task="Find opportunities in the tech sector for the next week.")
print(result)   # will include output from your Custom‑Signal agent

```

If you prefer to avoid modifying global state, subclass `AutoHedge` and replace the director reference:

```python

# subclass_example.py

from autohedge import AutoHedge
from autohedge.workers import director_agent as base_director
from custom_strategy import custom_signal_agent, director_agent as custom_director

class MyCustomAutoHedge(AutoHedge):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Replace the director used by the instance

        self.director_agent = custom_director

# Run with the subclass

my_fund = MyCustomAutoHedge(name="my‑custom‑fund")
print(my_fund.run(task="Evaluate cryptocurrency markets for a short‑term swing."))

```

## Key Source Files for Integration

| File | Purpose | Critical Lines |
|------|---------|----------------|
| [`autohedge/prompts.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/prompts.py) | Prompt templates for Director and agents | 5-22 (`DIRECTOR_PROMPT`) |
| [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) | Agent definitions and `ALL_AGENTS` list | 26-34, 72-77, 80-86 |
| [`autohedge/main.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/main.py) | Core `AutoHedge` class and conversation logic | 33-60 |
| [`example.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/example.py) | Reference implementation | 1-11 |

## Summary

- **Three integration methods** exist: custom Director prompts, new Agent insertion, and class subclassing.
- The `ALL_AGENTS` list in [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) controls execution order; agents communicate via a shared `Conversation` object.
- You can use proprietary models or local LLMs by changing the `model_name` parameter when instantiating `swarms.Agent`.
- No core codebase modification is required—integration happens through composition and subclassing.

## Frequently Asked Questions

### Do I need to fork or modify the AutoHedge repository to add custom strategies?

No. You can import the library and compose your own pipeline by manipulating the `ALL_AGENTS` list or subclassing `AutoHedge`. All integration points are exposed as plain Python objects in [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) and [`autohedge/prompts.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/prompts.py).

### Why does the order of agents in `ALL_AGENTS` matter?

The Director routes messages sequentially through the `handoffs` list. If your proprietary signal agent must execute after sentiment analysis but before risk management, you must `insert` it at the correct index in `ALL_AGENTS` (e.g., position 1).

### Can I integrate custom language models or proprietary APIs?

Yes. When creating a `swarms.Agent` instance, set `model_name` to any identifier supported by your Swarms backend, including local LLM endpoints. You can also attach custom tools via the `tools` parameter to call proprietary data APIs.

### How does the Director handle failures or invalid outputs from my custom agent?

Each agent produces JSON-style messages stored in the `Conversation` object. The Director passes the full conversation history to subsequent agents. If your custom agent outputs invalid JSON, the next agent in the chain receives the raw text and may attempt to parse or report the error as part of its reasoning loop.