AI Agents
An LLM with hands. What could go wrong?
▶ the lesson · narrated sketch video · tap for sound
the intro
An agent is an LLM in a loop with tools: the model decides which tool to call, sees the result, and continues until the task is done. The failure modes are loops and hallucinated arguments, so real agents need iteration limits, logging, and validation.
fun fact ✦
Most “AI agents” in production are one prompt, one tool, and a very confident marketing page.
the docs
the deep dive
the ideas behind the video — concepts, diagrams, a walkthrough and the traps to avoid
A chatbot answers and stops. An agent answers, calls a function, reads the result, and decides what to do next — a while-loop wrapped around the model, with tools as its hands. The loop is where both the magic and the money live: every turn costs tokens, and a confused agent will happily orbit forever. The craft is designing tools and stop conditions it cannot get lost in.
the loop is where the magic and the money are
key terms
tool
A function the model may call: a clear name, a description it can read, typed parameters. The description is the documentation.
search_orders(email: string)agent loop
Model decides, tool runs, result returns, model continues until done. One call is a chatbot; the loop is the agent.
one pass = chatbot, loop = agentMCP
Model Context Protocol: an open standard for plugging tools and data into any compliant model client.
write once, use with any clientiteration cap
A max on loop turns. Without it, a confused agent orbits until your budget does.
5-10 turns plus a failure pathhow it works
- 1Write tools like an API
Clear names, honest descriptions, typed parameters. A vague description produces hallucinated arguments.
- 2Run the loop
The model picks a tool, you execute it, and the result goes back into the conversation history.
- 3Log every step
Prompt, tool call, result, decision. When it derails, the log is the only witness.
- 4Cap and bail out
Max iterations and max tokens, plus a failure path that returns something useful instead of throwing.
the code, explained
the agent loop, no framework required
side by side
one-call chatbot
- one prompt, one reply
- predictable cost per user
- cannot act, only talk
agent loop
- plans multi-step work
- calls tools mid-answer
- cost scales with turns
- needs caps, logs, retries
The unbounded loop is the classic agent incident: a confused model retries a failing tool forever, at token prices, overnight. Cap iterations at 5-10, cap tokens per turn, and make the failure path return something useful instead of throwing.
quick answers
Do I need an agent framework?
No. The loop is a while-statement and an array. Frameworks help with orchestration, but start hand-rolled so you understand every step.
What is MCP, in one line?
An open protocol so a tool you build once works with any compliant model client, instead of one integration per vendor.
When is a plain LLM call enough?
More often than the hype says. No state, no side effects, one step — skip the loop and ship the call.
quick hits about AI Agents
short answers · interviews, tips, trivia & hidden gems