What makes an AI agent worth building
AI agents handle multi-step tasks that traditionally need manual effort, context, and judgment — the kind of work that’s awkward to automate with hardcoded rules. Instead of enumerating every edge case, an agent uses context to decide its next action, reducing tedious steps while still allowing human review for consequential decisions.
The agents that actually work well are narrow and domain-specific. Here’s a practical path to building one.
Prototype manually before writing code
Before any code, simulate the agent yourself. Take real inputs — screenshots, API responses, messy CSVs — and feed them into an LLM by hand, guiding it through the workflow with prompts that mirror what the final system would use. Perform the resulting actions yourself and note which steps feel repetitive; those are your automation candidates.
Expect rough results initially. When building v0.dev in 2023, LLMs couldn’t reliably produce HTML. Progress came from narrowing scope and using structured inputs with Tailwind, not from better models. If the model can’t make headway even with adjustments, the task may not suit an agent. If it nearly works, keep going.
Automate the loop with plain code
Once the manual simulation shows promise, start coding. Build the input collection layer with APIs, scrapers, or screenshots, then model the agent as a loop or state machine: gather input, run deterministic computation where possible, call the model only when reasoning is needed, evaluate the result, and decide whether to continue.
LLMs are non-deterministic. For any step that doesn’t need judgment — parsing, calculating, sorting — write a normal function.
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,
});
}
This isn’t a new paradigm. Agents are regular programming: if statements, loops, and switches all apply. The agent is “working” when it consistently produces acceptable output with little or no intervention. For common patterns, see the AI SDK agent docs.
Reliability comes from iteration
With an end-to-end agent running, shift to quality. Tighten the loop: refine prompts, make tool calls precise, cut unneeded retries, and replace model calls with deterministic code wherever possible. For incomplete results, consider a second model to critique and continue the first model’s work.
Hands-on testing against real examples is your primary tool at this stage. Once the core loop stabilizes, add structured evaluations to verify performance across a broad input range and catch regressions as the agent evolves.
When to use an agent
Agents make sense when the task resists traditional automation, manual prompting shows promise, and you keep the scope tight while building on solid software practices. Optimization combines intuition with structured evaluation.
The end result can feel like magic, but nothing about it is. It’s just well-structured systems with reasoning layered in where it matters.



