Case study 03
Stock AI
Ask about any stock in plain English. An agent fetches live market data and answers.
Ask about any listed company. The agent looks up live prices, metrics, financials and screeners itself.
Data from Yahoo Finance, may be delayed. Answers are written by an LLM and are not investment advice.
Overview
Stock AI is an HTTP API for stock market data with an LLM agent on top. You ask a question such as "What is Nvidia trading at and what is its P/E?" and the agent decides which data it needs, calls the right tools, and answers in Markdown with tables.
It merges two earlier projects, an MCP server of stock tools and a LangGraph stock screener, into one FastAPI service. The same tools are also available as an MCP server, so Claude Desktop or an IDE can use them directly.
It is built to be called from a public website: API-key auth, per-IP rate limits, restricted CORS, response caching and clear error codes. The live demo on this site calls it through a server-side proxy so the key never reaches the browser.
What it does
Tool-calling agent
A LangChain agent on Groq's gpt-oss-120b chooses between ticker search, prices, company info, income statements and screeners for each question.
Conversation memory
Each conversation has a thread ID, so follow-ups like "and its revenue trend?" keep context. Old turns are trimmed to bound cost.
Plain data endpoints
The same data is available as JSON without the LLM: search, price history, company metrics, financials and 15 Yahoo Finance screens.
MCP server
An optional MCP server exposes the tools over stdio for Claude Desktop and IDE assistants.
Built for public traffic
API keys with zero-downtime rotation, per-IP rate limits with standard headers, CORS limited to known origins, and cached responses.
Graceful failure
Typed errors for bad input, unknown tickers, rate limits, provider outages and timeouts, each with a Retry-After hint where it helps.
How it works
- 01The client sends a question, plus the thread ID of an ongoing conversation.
- 02The API checks the key and rate limit, then loads that thread's recent history.
- 03The agent plans which tools to call and fetches live data from Yahoo Finance through yfinance, using cached results where fresh enough.
- 04The model writes a Markdown answer from the data and returns it with the list of tools it used.
- 05The thread is saved, so the next message continues the same conversation.
Stack
- Python
- FastAPI
- LangChain
- LangGraph
- Groq
- gpt-oss-120b
- yfinance
- MCP
- Docker
- Render
- uv
- pytest