LLM Fundamentals for Agent Builders
Tokens, context windows, temperature, and model selection — the basics every agent founder needs before writing code.
Choosing a model
Most successful agents use 2-3 models in a pipeline, not one model for everything. Use frontier models (GPT-4o, Claude Sonnet) for planning, complex reasoning, and customer-facing copy. Use smaller, faster models (GPT-4o-mini, Haiku, Gemini Flash) for classification, extraction, routing, and high-volume tasks.
A typical pipeline: a cheap model classifies the incoming request ($0.0001/call), a mid-tier model extracts structured data ($0.001/call), and a frontier model only runs for the final synthesis or complex decision ($0.01-0.05/call). This cuts costs 5-10x versus running everything through the best model.
Do not over-optimize model selection before you have production traffic. Start with one good model, measure cost per completed task, then split the pipeline where you see the biggest cost/quality tradeoffs. The model that wins benchmarks rarely wins your P&L.
Context is your product
Agents fail when they lack the right context, not when the model is too dumb. A support agent without access to the customer's billing history, past tickets, and your refund policy will hallucinate answers regardless of model size.
Invest in three context layers: retrieval (RAG over your knowledge base), structured inputs (JSON schemas, form fields, API responses), and conversation history (what happened earlier in this session). The goal is giving the model exactly what a skilled human operator would see — no more, no less.
Context window size matters less than context quality. 10 well-chosen chunks with metadata filters beat 100 random chunks every time. Track a 'context sufficiency' metric: how often does the agent escalate because it could not find relevant information? That number tells you where to invest.
Cost control
Track cost per completed task, not cost per token. A task that costs $0.02 at 10,000 tasks/month ($200 inference cost) is viable at $500/month pricing. A task that costs $2.00 is not viable at any reasonable SaaS price point.
Practical cost controls: cache repeated lookups (customer profiles, policy docs), batch similar requests (classify 50 tickets in one call instead of 50 calls), cap max agent loop iterations (10-15 steps), and use smaller models for deterministic steps. Set per-tenant daily budgets to prevent one customer from blowing your margin.
Build a cost dashboard from day one. Plot inference cost as a percentage of revenue — target under 20% at scale, under 40% during early pilots. If inference eats 60% of revenue, your pricing or architecture needs fixing before you scale sales.