<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: grahammccain</title>
    <description>The latest articles on DEV Community by grahammccain (@grahammccain).</description>
    <link>https://dev.to/grahammccain</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3864299%2Faf068cac-f0f7-4b6d-8f25-ea88b6f8746d.png</url>
      <title>DEV Community: grahammccain</title>
      <link>https://dev.to/grahammccain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/grahammccain"/>
    <language>en</language>
    <item>
      <title>Multi-Agent Stock Research with CrewAI + Chart Library</title>
      <dc:creator>grahammccain</dc:creator>
      <pubDate>Mon, 06 Apr 2026 17:23:46 +0000</pubDate>
      <link>https://dev.to/grahammccain/multi-agent-stock-research-with-crewai-chart-library-4jgi</link>
      <guid>https://dev.to/grahammccain/multi-agent-stock-research-with-crewai-chart-library-4jgi</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Crew Design: Two Specialist Agents
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Pattern Analyst&lt;/strong&gt; -- 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%."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regime Analyst&lt;/strong&gt; -- 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.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;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."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Defining the Tools
&lt;/h2&gt;

&lt;p&gt;Each agent gets curated tools from Chart Library's Python SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;crewai crewai-tools chartlibrary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pattern Analyst tools:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;chart_intelligence&lt;/code&gt; -- calls &lt;code&gt;cl.intelligence(symbol, date)&lt;/code&gt; for 10 most similar historical patterns + forward returns&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;scenario_stress_test&lt;/code&gt; -- calls &lt;code&gt;cl.scenario(symbol, market_move_pct)&lt;/code&gt; for "what if SPY drops 5%?"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;daily_top_picks&lt;/code&gt; -- calls &lt;code&gt;cl.discover(limit=10)&lt;/code&gt; for today's top patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Regime Analyst tools:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;market_regime&lt;/code&gt; -- calls &lt;code&gt;cl.regime(compact=True)&lt;/code&gt; for SPY, QQQ, and 11 sector ETFs&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;crowding_detector&lt;/code&gt; -- calls &lt;code&gt;cl.crowding()&lt;/code&gt; for systematic risk signals&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sector_rotation&lt;/code&gt; -- calls &lt;code&gt;cl.sector_rotation(lookback)&lt;/code&gt; for momentum rankings&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Building the Tasks
&lt;/h2&gt;

&lt;p&gt;The order matters: regime assessment first (establishes context), then stock analysis (uses that context), then synthesis (combines both).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 1 - Regime Assessment:&lt;/strong&gt; Check SPY/QQQ, identify leading/lagging sectors, evaluate crowding risk.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 2 - Stock Analysis:&lt;/strong&gt; 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."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 3 - Synthesis:&lt;/strong&gt; Produces a structured briefing: Market Environment, Stock Highlights, Risk Factors, Bottom Line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the Crew
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;crew&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Crew&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;agents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pattern_analyst&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;regime_analyst&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;regime_task&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;analysis_task&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;synthesis_task&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sequential&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;crew&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;kickoff&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example Output
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Regime Analyst&lt;/strong&gt; checks SPY: 7 of 10 historically similar regimes gained over 10 days. Tech (XLK) and Industrials (XLI) leading. Moderate crowding in large-cap tech.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Pattern Analyst&lt;/strong&gt; analyzes each symbol:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NVDA&lt;/strong&gt;: 10 matches, top match 94% similarity, 8/10 positive over 5 days (+3.1% avg)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AAPL&lt;/strong&gt;: More mixed -- 6/10 positive, +0.8% average&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TSLA&lt;/strong&gt;: Historically volatile, wide outcome range&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;synthesis&lt;/strong&gt; combines both: bullish regime supports NVDA, AAPL is neutral, TSLA's wide range means sizing matters more than direction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extending the Crew
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Risk Manager agent&lt;/strong&gt;: Run stress tests for -3%, -5%, -10% market moves across the watchlist&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portfolio Optimizer agent&lt;/strong&gt;: Suggest position sizes based on conviction and correlation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hierarchical process&lt;/strong&gt;: A Research Director that delegates dynamically instead of fixed sequence&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Start with two agents and add complexity only when you hit a real limitation. Multi-agent systems are powerful but harder to debug.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The complete working example is at &lt;a href="https://github.com/grahammccain/chart-library-mcp" rel="noopener noreferrer"&gt;github.com/grahammccain/chart-library-mcp&lt;/a&gt; in examples/crewai_tutorial.py.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Get your free API key at &lt;a href="https://chartlibrary.io/developers" rel="noopener noreferrer"&gt;chartlibrary.io/developers&lt;/a&gt; and build your first research crew today. 24M patterns. 10 years. One API call.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>crewai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Use an MCP Server for Stock Analysis with Claude</title>
      <dc:creator>grahammccain</dc:creator>
      <pubDate>Mon, 06 Apr 2026 17:17:12 +0000</pubDate>
      <link>https://dev.to/grahammccain/how-to-use-an-mcp-server-for-stock-analysis-with-claude-b9c</link>
      <guid>https://dev.to/grahammccain/how-to-use-an-mcp-server-for-stock-analysis-with-claude-b9c</guid>
      <description>&lt;p&gt;Model Context Protocol (MCP) is an open standard that lets AI assistants like Claude connect to external data sources and tools. Instead of copying data into a prompt, you install an MCP server that gives the AI direct access to a service's API.&lt;/p&gt;

&lt;p&gt;Chart Library's MCP server gives Claude (and any MCP-compatible AI) access to 24 million pre-computed chart pattern embeddings, real-time regime data, sector analysis, and forward return statistics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation: Two Commands
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;chartlibrary-mcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Get a free API key at &lt;a href="https://chartlibrary.io/developers" rel="noopener noreferrer"&gt;chartlibrary.io/developers&lt;/a&gt; (200 calls/day free)&lt;/li&gt;
&lt;li&gt;Add the server to Claude Desktop: &lt;strong&gt;Settings &amp;gt; Developer &amp;gt; MCP Servers &amp;gt; Add&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Enter the command: &lt;code&gt;chartlibrary-mcp --api-key YOUR_KEY&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Restart Claude Desktop -- Chart Library tools appear in the tools panel&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;The MCP server also works with &lt;strong&gt;Cursor&lt;/strong&gt;, &lt;strong&gt;Windsurf&lt;/strong&gt;, and any editor or agent framework that supports MCP.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What the 19 Tools Do
&lt;/h2&gt;

&lt;p&gt;You never call them directly -- Claude picks the right tool based on your question:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pattern Intelligence (3 tools)&lt;/strong&gt;: Search for similar chart patterns, analyze ticker+date combos, get full intelligence reports with AI summaries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Market Context (4 tools)&lt;/strong&gt;: Market regime for SPY/QQQ, sector rotation rankings, crowding detection, scenario analysis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discovery (3 tools)&lt;/strong&gt;: Today's top patterns, trending tickers, interesting setups&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portfolio &amp;amp; Alerts (4 tools)&lt;/strong&gt;: Add holdings, portfolio analysis, pattern alerts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data &amp;amp; Utilities (5 tools)&lt;/strong&gt;: Ticker lookup, historical prices, API usage, accuracy stats&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example Conversation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;You:&lt;/strong&gt; "What does NVDA's chart look like right now? Anything interesting?"&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Claude calls: &lt;code&gt;get_intelligence(symbol="NVDA")&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Claude:&lt;/strong&gt; "NVDA's current intraday pattern closely matches 10 historical setups. The top match is AMD from August 2024 at 93% similarity. The average 5-day return is +1.6% with 7 of 10 matches moving higher."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You:&lt;/strong&gt; "What's the broader market doing? Should I be worried?"&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Claude calls: &lt;code&gt;get_regime()&lt;/code&gt;, &lt;code&gt;get_crowding()&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Claude:&lt;/strong&gt; "The current SPY regime most closely resembles March 2024 -- a slow grind higher on moderate volume. 8 of 10 similar periods saw gains over 10 days. However, the crowding detector shows elevated correlation across tech stocks, which historically precedes short-term pullbacks in about 40% of cases."&lt;/p&gt;

&lt;h2&gt;
  
  
  MCP vs. REST API: When to Use Which
&lt;/h2&gt;

&lt;p&gt;Both access the same data. The difference is the interface:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;th&gt;Best Choice&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Conversational research&lt;/td&gt;
&lt;td&gt;MCP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Automated trading systems&lt;/td&gt;
&lt;td&gt;REST API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Building dashboards&lt;/td&gt;
&lt;td&gt;REST API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ad-hoc market analysis&lt;/td&gt;
&lt;td&gt;MCP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-agent workflows&lt;/td&gt;
&lt;td&gt;Either&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Many users keep the MCP server running in Claude Desktop for quick research while also calling the REST API from their trading scripts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Get Started
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;chartlibrary-mcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The free tier gives you 200 calls per day -- more than enough for a full day of research. For more advanced use cases, check out the &lt;a href="https://chartlibrary.io/blog/build-stock-research-agent-langchain" rel="noopener noreferrer"&gt;LangChain tutorial&lt;/a&gt; and &lt;a href="https://chartlibrary.io/blog/multi-agent-stock-research-crewai" rel="noopener noreferrer"&gt;CrewAI tutorial&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Chart Library: 24 million chart pattern embeddings. 10 years of history. Pattern intelligence for AI agents. &lt;a href="https://chartlibrary.io/developers" rel="noopener noreferrer"&gt;chartlibrary.io/developers&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>mcp</category>
      <category>claude</category>
      <category>python</category>
    </item>
    <item>
      <title>Build a Stock Research Agent with LangChain + Chart Library in 20 Minutes</title>
      <dc:creator>grahammccain</dc:creator>
      <pubDate>Mon, 06 Apr 2026 17:17:11 +0000</pubDate>
      <link>https://dev.to/grahammccain/build-a-stock-research-agent-with-langchain-chart-library-in-20-minutes-39o5</link>
      <guid>https://dev.to/grahammccain/build-a-stock-research-agent-with-langchain-chart-library-in-20-minutes-39o5</guid>
      <description>&lt;p&gt;Most AI trading agents work with raw price data: OHLCV bars, moving averages, maybe some technical indicators. They can tell you &lt;em&gt;what the price is&lt;/em&gt;, but not &lt;em&gt;what it means&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Chart Library's API gives agents something they can't get anywhere else: pre-computed pattern similarity across 24 million embeddings spanning 10 years and 19,000+ symbols. Instead of asking "what's the price of NVDA?", your agent can ask "find the 10 most similar historical charts to NVDA right now and tell me how those patterns resolved."&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up
&lt;/h2&gt;

&lt;p&gt;You need three packages and two API keys:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;langchain langchain-openai chartlibrary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Get a free Chart Library API key at &lt;a href="https://chartlibrary.io/developers" rel="noopener noreferrer"&gt;chartlibrary.io/developers&lt;/a&gt; (200 calls/day on the free tier)&lt;/li&gt;
&lt;li&gt;Set your environment variables: &lt;code&gt;CHART_LIBRARY_KEY=cl_...&lt;/code&gt; and &lt;code&gt;OPENAI_API_KEY=sk-...&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can swap OpenAI for Anthropic, Groq, Ollama, or any LangChain-compatible model. Just change the LLM initialization -- the tools stay the same.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Creating the Tools
&lt;/h2&gt;

&lt;p&gt;LangChain agents work by selecting from a set of tools based on the user's question. Each tool wraps one or more API calls and returns a formatted string the LLM can reason over. We define five tools that cover Chart Library's core capabilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  The chart_intelligence Tool
&lt;/h3&gt;

&lt;p&gt;Here's the core tool that powers most agent interactions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@tool&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;chart_intelligence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Get full pattern intelligence for a stock ticker.
    Returns the 10 most similar historical chart patterns,
    what happened after those patterns (1/3/5/10-day forward
    returns), and an AI-generated summary.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;intelligence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;compact&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Format matches, forward returns, and summary
&lt;/span&gt;    &lt;span class="c1"&gt;# into a readable string for the LLM
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;formatted_result&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tool extracts the top 3 matches with similarity scores, forward return statistics (average return, win rate) for each horizon, and the AI-generated summary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Market Regime and Sector Tools
&lt;/h3&gt;

&lt;p&gt;Beyond individual stocks, agents need market context:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;market_regime&lt;/strong&gt; -- calls the &lt;code&gt;/regime&lt;/code&gt; endpoint for SPY, QQQ, and all 11 S&amp;amp;P sector ETFs with historical pattern matching&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;sector_rotation&lt;/strong&gt; -- sector momentum rankings&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;crowding_detector&lt;/strong&gt; -- checks if many stocks are trading the same pattern (signals systematic risk)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;scenario_analysis&lt;/strong&gt; -- stress-tests a stock against a hypothetical market move&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Building the Agent
&lt;/h2&gt;

&lt;p&gt;With the tools defined, assembling the agent takes about 10 lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ChatOpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gpt-4o-mini&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;chart_intelligence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;market_regime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="n"&gt;crowding_detector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scenario_analysis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="n"&gt;sector_rotation&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_tool_calling_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;executor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AgentExecutor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_iterations&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example Conversation
&lt;/h2&gt;

&lt;p&gt;Here's what a real session looks like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User:&lt;/strong&gt; "What does NVDA's chart look like right now? How did similar patterns play out?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agent calls:&lt;/strong&gt; &lt;code&gt;chart_intelligence("NVDA")&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agent:&lt;/strong&gt; "NVDA's current chart pattern matches 10 historical patterns with high similarity. The top match is AMD from 2023-08-14 at 94% similarity. Looking at what happened after these patterns: over 5 days, the average return was +1.8% with 7 of 10 matches moving higher. Over 10 days, the average was +2.4% with 6 of 10 positive."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User:&lt;/strong&gt; "What about the broader market? Is there anything concerning?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agent calls:&lt;/strong&gt; &lt;code&gt;market_regime()&lt;/code&gt;, &lt;code&gt;crowding_detector()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agent:&lt;/strong&gt; "SPY's 30-day change is at +3.2%, with 8 of 10 similar historical regimes seeing positive 10-day returns. However, the crowding detector is showing elevated readings -- many stocks are trading in lockstep, which historically signals higher correlation risk."&lt;/p&gt;

&lt;h2&gt;
  
  
  Extending the Agent
&lt;/h2&gt;

&lt;p&gt;The five tools above cover the core use cases, but Chart Library's API has more endpoints you can wrap:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Alerts&lt;/strong&gt;: Let the agent set up pattern alerts ("tell me when a chart similar to AAPL 2024-01-15 appears again")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portfolio analysis&lt;/strong&gt;: Connect the agent to a user's portfolio for nightly pattern monitoring&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Historical backtest&lt;/strong&gt;: Run pattern-based backtests to validate strategies&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-timeframe&lt;/strong&gt;: Search across 5min, 15min, 30min, 1hr, or multi-day windows&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The full tutorial code is on GitHub at &lt;a href="https://github.com/grahammccain/chart-library-mcp" rel="noopener noreferrer"&gt;github.com/grahammccain/chart-library-mcp&lt;/a&gt; in the examples/ directory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What's Next: Multi-Agent Workflows
&lt;/h2&gt;

&lt;p&gt;A single agent is useful. The next level is multi-agent workflows where specialized agents collaborate -- a Pattern Analyst, a Regime Strategist, and a Risk Manager that discuss, debate, and produce a unified research brief.&lt;/p&gt;

&lt;p&gt;Chart Library's MCP server (&lt;code&gt;pip install chartlibrary-mcp&lt;/code&gt;) works with any MCP-compatible agent framework -- including Claude Desktop, Cursor, and Windsurf.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Get a free API key at &lt;a href="https://chartlibrary.io/developers" rel="noopener noreferrer"&gt;chartlibrary.io/developers&lt;/a&gt; and start building. 24 million chart pattern embeddings, 10 years of history, one API call.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>langchain</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
