Large Language Models
Simple LLMs from zero: chat APIs, tokens and cost, JSON actions, and when not to call a model.
- 0120 min
What Is an LLM?
A large language model continues text. Treat it as a guessing policy over tokens, not as a database or a mind.
- 0219 min
Base vs Chat Models
A base model continues text. A chat model answers as an assistant. Hosted APIs almost always give you chat.
- 0320 min
Open Weights vs Hosted APIs
Closed: you send text and get text. Open weights: you can host and fine-tune. Neither one is truth.
- 0421 min
Vendor APIs
Chat is an HTTP POST with a model name and a message list. The SDK is a thin costume. The server is stateless.
- 0520 min
Errors and Retries
401, 429, 5xx, and timeouts are agent outcomes. Retry only what is safe to repeat. Map errors in code, not in the prompt.
- 0619 min
Streaming
Streaming shows tokens as they arrive. The model is the same. Parse only finished text, or native tool events.
- 0721 min
Tokens and Cost
Vendors charge for tokens both ways. Agent loops resend a growing prompt, so cost climbs every step.
- 0819 min
Spend Caps
Put a dollar (or token) cap next to max steps. When the cap hits, do not call. Fail closed or hand off.
- 0920 min
Prompt Caching
Some vendors cheapen a stable prefix. Caching helps only if the first bytes stay the same. Put volatile text last.
- 1021 min
Chat Transcripts
System, user, assistant, and tool roles — the document the model actually reads. If the list is wrong, the policy is wrong.
- 1122 min
System Prompts
Specs beat vibes. Write a system prompt like an API contract: tools, schemas, stop rules, forbidden actions.
- 1220 min
Tool Messages
Tool output is data. Do not promote it to system. Encode untrusted blobs. Keep ids for parallel calls.
- 1319 min
Safety Filters
Vendors may refuse or blank a completion. That is a finish reason, not an empty JSON object. Do not parse it as an action.
- 1422 min
Structured Output
JSON, validation, and a short retry — how agents return actions instead of essays. Never exec the string.
- 1519 min
Finish Reason
stop, length, tool_calls, content_filter — read this before you blame the weights or parse truncated JSON.
- 1620 min
Decoding Knobs
Temperature, max tokens, and stop sequences — the runtime policy around the same weights. Wrong knobs look like model failures.
- 1721 min
Hallucinations
Fluent lies are the default. Make unsupported claims fail a check before they reach the user.
- 1820 min
Citations
Every number, id, and quote should point at a chunk or a tool payload you can open. Invented ids are fake evidence.
- 1919 min
When to Abstain
I don’t know is a feature. After tools fail, do not invent a balance. Put abstain in the schema.
- 2022 min
Context Engineering
What earns a seat in the window: goal, spec, tools, latest observation — nothing else by default. Pack in code.
- 2120 min
Choosing Models
There is no best model. There is a best model for a step, under cost, latency, privacy, and your eval.
- 2220 min
Routing Models
A cheap router picks small vs large. Escalate once if JSON fails. Measure how often you escalate.
- 2321 min
Log the Call
Request id, model, usage, finish reason, knobs, and the message list — or you cannot debug the bill or the bug.
- 2422 min
When Not to Use an LLM
If a lookup, regex, or workflow can do the job, skip the model. Save it for branches you cannot draw.