Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Y-Research-SBU/QuantAgent/llms.txt

Use this file to discover all available pages before exploring further.

Each node in the QuantAgent pipeline is a self-contained function that reads from IndicatorAgentState, performs its analysis, and returns a partial state update. LangGraph merges these updates automatically before invoking the next node.

Indicator Agent

The Indicator Agent is the first node in the graph. It receives raw OHLCV data and uses graph_llm bound to five TA-Lib tools to compute technical indicators. Tools available:
ToolComputes
compute_macdMACD line, signal line, histogram
compute_rsiRSI values
compute_rocRate of Change values
compute_stochStochastic %K and %D
compute_willrWilliams %R values
The agent follows a two-phase invocation loop:
1

Initial tool call

The LLM is prompted with the OHLCV data and asked to call whichever indicator tools it needs. All tool results are appended to the message history as ToolMessage objects.
2

Multi-call iteration (up to 5 rounds)

After tool results are available, the LLM is re-invoked. If it issues more tool calls (common with Claude, which may batch calls across turns), those are executed and appended. This loop repeats until the LLM returns a plain text response or the 5-iteration cap is hit.
3

Report extraction

The final text response becomes indicator_report in state. If the LLM returns empty content (a known behavior with some providers), the agent walks back through the message history to find the last non-empty text message.
# indicator_agent.py — iteration cap for multi-call LLMs like Claude
max_iterations = 5
while iteration < max_iterations:
    final_response = chain.invoke(messages)
    if not final_response.tool_calls:
        break
    # execute additional tool calls and continue
State written: messages, indicator_report

Pattern Agent

The Pattern Agent generates a candlestick chart from the last 40 candles and passes it to a vision LLM for pattern identification. Tool available: generate_kline_image — renders OHLCV data as a candlestick chart and returns a base64-encoded PNG.
1

Check for precomputed image

If pattern_image is already present in state (e.g., pre-generated before graph invocation), the agent skips tool generation and proceeds directly to vision analysis.
2

Generate chart (if needed)

agent_llm is bound to generate_kline_image and prompted to call it. The tool returns pattern_image (base64 PNG) and pattern_image_description. If the tool returns no image, it is retried up to 3 times with a 4-second wait between attempts.
3

Vision analysis

graph_llm receives a multimodal message containing the chart image and a reference list of 16 classical candlestick patterns (e.g., Inverse Head and Shoulders, Double Bottom, Bullish Flag, Symmetrical Triangle). The model identifies any matching patterns and explains its reasoning.
The 16 patterns the vision LLM is evaluated against include:
  • Inverse Head and Shoulders, Double Bottom, Rounded Bottom, Hidden Base
  • Falling Wedge, Rising Wedge, Ascending Triangle, Descending Triangle
  • Bullish Flag, Bearish Flag, Rectangle, Island Reversal
  • V-shaped Reversal, Rounded Top, Expanding Triangle, Symmetrical Triangle
State written: messages, pattern_report

Trend Agent

The Trend Agent generates a trendline-annotated candlestick chart from the last 50 candles and uses a vision LLM to predict short-term directional bias. Tool available: generate_trend_image — runs the trendline fitting algorithm (see Technical analysis) and overlays support and resistance lines on the chart. The chart encodes four trendlines:
  • Blue line — close-based support (from fit_trendlines_single)
  • Red line — close-based resistance (from fit_trendlines_single)
  • White lines — high/low-based support and resistance channels (from fit_trendlines_high_low)
1

Check for precomputed image

If trend_image is already in state, the agent skips tool generation.
2

Generate trendline chart (if needed)

agent_llm is bound to generate_trend_image and prompted to call it. The tool returns the base64-encoded chart.
3

Vision analysis

graph_llm receives the annotated chart and is asked to analyze how price interacts with the support and resistance lines — whether candles are bouncing, breaking through, or compressing — and to predict the short-term trend: upward, downward, or sideways.
State written: messages, trend_report, trend_image, trend_image_filename, trend_image_description

Decision Agent

The Decision Agent is the final node. It reads all three upstream reports and synthesizes them into a single structured trade decision using graph_llm (no tools, no vision). The agent’s prompt enforces strict decision logic:
  • Only act on confirmed signals — avoid emerging, speculative, or conflicting signals
  • Prioritize decisions where all three reports align in the same direction
  • Weight recent strong momentum (MACD crossover, RSI breakout) over weak oscillator hints
  • HOLD is explicitly prohibited — the output must be LONG or SHORT
  • Risk-reward ratio must be between 1.2 and 1.8
Output format The Decision Agent returns a JSON block written to final_trade_decision:
{
  "forecast_horizon": "Predicting next 3 candlesticks (45 minutes)",
  "decision": "LONG",
  "justification": "MACD shows bullish crossover confirmed by RSI break above 55. Bullish flag pattern nearing breakout. Support trendline holding with upward slope.",
  "risk_reward_ratio": "1.5"
}
State written: final_trade_decision, messages, decision_prompt

State fields reference

The complete IndicatorAgentState fields that flow through the pipeline:
class IndicatorAgentState(TypedDict):
    # Input
    kline_data: dict           # OHLCV data
    time_frame: str            # e.g. "15min", "4hour"
    stock_name: dict           # instrument identifier

    # Indicator Agent outputs
    rsi: List[float]
    macd: List[float]
    macd_signal: List[float]
    macd_hist: List[float]
    stoch_k: List[float]
    stoch_d: List[float]
    roc: List[float]
    willr: List[float]
    indicator_report: str

    # Pattern Agent outputs
    pattern_image: str               # base64 PNG
    pattern_image_filename: str
    pattern_image_description: str
    pattern_report: str

    # Trend Agent outputs
    trend_image: str                 # base64 PNG
    trend_image_filename: str
    trend_image_description: str
    trend_report: str

    # Decision Agent outputs
    final_trade_decision: str        # JSON string
    decision_prompt: str
    analysis_results: str
    messages: List[BaseMessage]