Skip to content
Dashboard

The no-nonsense approach to AI agent development

CTO, Vercel

Link to headingStep 1: Prototype the agent by hand

Link to headingStep 2: Automate the loop

import { streamText, tool } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { z } from "zod";
async function stockAnalysisAgent(
symbol: string,
startDate: string,
endDate: string
) {
return streamText({
model: anthropic("claude-4-sonnet-20250514"),
system: `You are a professional stock analyst AI powered by Claude Sonnet. You MUST perform a comprehensive analysis using BOTH available tools.
ANALYSIS STRUCTURE:
- Technical Analysis: Use price data, P/E ratio, beta, 52-week range, volume patterns
- Fundamental Analysis: Use news sentiment, earnings data, market cap, industry trends
- Investment Recommendation: Clear BUY/SELL/HOLD with specific price targets and reasoning
IMPORTANT: You MUST use both tools before providing any analysis. Do not wait or ask - call both tools immediately and concurrently.
NOTE: The news search uses Finnhub as the primary source (more reliable for stock news) with NewsAPI as fallback.`,
prompt: `Analyze ${symbol.toUpperCase()} stock comprehensively. Use BOTH the getStockData and searchNews tools to gather complete market data, then provide detailed technical and fundamental analysis with a clear investment recommendation.`,
tools: {
getStockData: tool({
description:
"Get real-time stock price, volume, financial metrics, and historical data for a given symbol using Finnhub API",
parameters: z.object({
symbol: z.string().describe("Stock symbol (e.g., NVDA, AAPL, TSLA)"),
}),
execute: async ({ symbol }) => {
return getStockData(symbol, startDate, endDate);
},
}),
searchNews: tool({
description:
"Search for recent news and analysis about a stock or company using Finnhub (primary) and NewsAPI (fallback)",
parameters: z.object({
query: z
.string()
.describe(
'Search query for news (e.g., "NVIDIA", "Apple earnings", "Tesla Model 3")'
),
}),
execute: async ({ query }) => {
return searchNews(query, startDate, endDate);
},
}),
},
maxSteps: 5,
});
}

Example of a stock analysis agent

Link to headingStep 3: Optimize for reliability

Link to headingTakeaways

Ready to build?

Get started with the AI SDK to build reliable, scoped AI agents using real software patterns.

Try AI SDK