When you ask a single AI agent to research a stock, it tries to do everything at once: check the chart pattern, assess the market, evaluate sectors, and synthesize a view. The result is usually shallow.
Multi-agent systems fix this by splitting work across specialists -- exactly how institutional research desks operate. CrewAI lets you build that structure with AI agents and Chart Library's pattern intelligence API.
The Crew Design: Two Specialist Agents
Pattern Analyst -- specializes in individual stock chart analysis. Uses Chart Library's intelligence endpoint to find historically similar charts, reads forward return statistics, and runs scenario stress tests. Always cites specific numbers: "7 of 10 similar patterns went up over 5 days, averaging +2.3%."
Regime Analyst -- specializes in the market-wide environment. Checks SPY/QQQ regime status, sector rotation, and crowding risk. Frames everything as historical analogy: "similar conditions historically led to..." rather than predictions.
Agent backstories matter more than you'd expect. A backstory that says "you never make predictions, you present historical context" produces very different output than "you are a bold market forecaster."
Defining the Tools
Each agent gets curated tools from Chart Library's Python SDK:
pip install crewai crewai-tools chartlibrary
Pattern Analyst tools:
-
chart_intelligence-- callscl.intelligence(symbol, date)for 10 most similar historical patterns + forward returns -
scenario_stress_test-- callscl.scenario(symbol, market_move_pct)for "what if SPY drops 5%?" -
daily_top_picks-- callscl.discover(limit=10)for today's top patterns
Regime Analyst tools:
-
market_regime-- callscl.regime(compact=True)for SPY, QQQ, and 11 sector ETFs -
crowding_detector-- callscl.crowding()for systematic risk signals -
sector_rotation-- callscl.sector_rotation(lookback)for momentum rankings
Building the Tasks
The order matters: regime assessment first (establishes context), then stock analysis (uses that context), then synthesis (combines both).
Task 1 - Regime Assessment: Check SPY/QQQ, identify leading/lagging sectors, evaluate crowding risk.
Task 2 - Stock Analysis: For each symbol in your watchlist, report match count, quality, forward returns. Receives Task 1's output as context -- so findings can be framed like "NVDA's bullish pattern aligns with the current risk-on regime."
Task 3 - Synthesis: Produces a structured briefing: Market Environment, Stock Highlights, Risk Factors, Bottom Line.
Running the Crew
crew = Crew(
agents=[pattern_analyst, regime_analyst],
tasks=[regime_task, analysis_task, synthesis_task],
process=Process.sequential,
verbose=True
)
result = crew.kickoff()
Example Output
The Regime Analyst checks SPY: 7 of 10 historically similar regimes gained over 10 days. Tech (XLK) and Industrials (XLI) leading. Moderate crowding in large-cap tech.
The Pattern Analyst analyzes each symbol:
- NVDA: 10 matches, top match 94% similarity, 8/10 positive over 5 days (+3.1% avg)
- AAPL: More mixed -- 6/10 positive, +0.8% average
- TSLA: Historically volatile, wide outcome range
The synthesis combines both: bullish regime supports NVDA, AAPL is neutral, TSLA's wide range means sizing matters more than direction.
Extending the Crew
- Risk Manager agent: Run stress tests for -3%, -5%, -10% market moves across the watchlist
- Portfolio Optimizer agent: Suggest position sizes based on conviction and correlation
- Hierarchical process: A Research Director that delegates dynamically instead of fixed sequence
Start with two agents and add complexity only when you hit a real limitation. Multi-agent systems are powerful but harder to debug.
The complete working example is at github.com/grahammccain/chart-library-mcp in examples/crewai_tutorial.py.
Get your free API key at chartlibrary.io/developers and build your first research crew today. 24M patterns. 10 years. One API call.
Top comments (0)