Implementation:51bitquant Ai hedge fund crypto Workflow create workflow
| Knowledge Sources | |
|---|---|
| Domains | Workflow_Orchestration, Graph_Architecture |
| Last Updated | 2026-10-28 14:00 GMT |
Overview
Concrete tool for building the LangGraph `StateGraph` DAG that orchestrates data fetching, strategy execution, risk management, and portfolio decisions provided by the `Workflow` class.
Description
Workflow.create_workflow constructs a `StateGraph(AgentState)` DAG. One `DataNode` per interval fans out from `start_node` and merges into `merge_data_node` (an `EmptyNode`). Each configured strategy is dynamically loaded via import_strategy_class and wired from the merge node into `risk_management_node`, which feeds `portfolio_management_node` and then `END`. The entry point is `start_node`. The resulting graph is compiled by `Agent.__init__` into a `CompiledGraph`.
Usage
Use this method to assemble the trading pipeline. It is called once per `Agent` construction (both for backtest and live runs). Pass the configured `intervals` and `strategies` from `Settings.signals`.
Code Reference
Source Location
- Repository: ai-hedge-fund-crypto
- File: src/agent/workflow.py
Signature
class Workflow:
@staticmethod
def create_workflow(intervals: List[Interval], strategies: List[str]) -> StateGraph:
workflow = StateGraph(AgentState)
# start_node -> per-interval DataNode -> merge_data_node
# merge_data_node -> per-strategy node -> risk_management_node
# risk_management_node -> portfolio_management_node -> END
...
return workflow
Import
from src.agent.workflow import Workflow
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| intervals | List[Interval] | Yes | Timeframes for DataNode fan-out |
| strategies | List[str] | Yes | Strategy class names (e.g. `["MacdStrategy"]`) dynamically imported from `src.strategies.{name}` |
Outputs
| Name | Type | Description |
|---|---|---|
| return | StateGraph | Uncompiled `StateGraph(AgentState)`; compile via `.compile()` before invoking |
Usage Examples
Build and Compile the DAG
from src.agent.workflow import Workflow
from src.utils.constants import Interval
# 1. Build the graph
graph = Workflow.create_workflow(
intervals=[Interval.MIN_30, Interval.HOUR_1, Interval.HOUR_4],
strategies=["MacdStrategy"],
)
# 2. Compile into an executable graph
app = graph.compile()
# 3. Invoke with initial state
final_state = app.invoke({
"messages": [],
"data": {"primary_interval": Interval.HOUR_1, "intervals": [...], "tickers": [...], "portfolio": {...}, "end_date": ..., "analyst_signals": {}},
"metadata": {"show_reasoning": False, "model_name": "gpt-4o", "model_provider": "openai", "model_base_url": None},
})
Inside the Agent (typical path)
# Agent.__init__ compiles the graph automatically
from src.agent.agent import Agent
agent = Agent(intervals=settings.signals.intervals, strategies=settings.signals.strategies)
# agent.agent is the compiled graph
Related Pages
Implements Principle
- Principle:51bitquant_Ai_hedge_fund_crypto_DAG_Pipeline_Orchestration
- Principle:51bitquant_Ai_hedge_fund_crypto_Strategy_Plugin_Architecture