Building AI Agents from Scratch with Python · Foundations
What Is an Agent, Really?
An agent, in the sense this guide uses the word, is a program that:
- Observes some state of the world (a user message, a file, an API response).
- Decides what to do next using a model, not a fixed script.
- Takes an action that changes the world (calls a tool, writes a file, sends a reply).
- Repeats, using the result of its own action as the next observation.
That's it. No agent framework, no buzzwords — just a loop with a model making the branching decisions instead of an if/else chain.
The model doesn't have to be an LLM. Historically, "agent" comes from reinforcement learning, where the decision-maker could be a Q-table. What's new in the last few years is using a language model as the decision-maker, because language models are good at picking actions described in natural language.
Why this definition matters
A lot of confusion in this space comes from calling three very different things "agents":
| Thing | Has a loop? | Decides its own next step? | Example |
|---|---|---|---|
| Chatbot | No | No — one request, one response | A support widget that answers FAQs |
| Workflow / pipeline | Yes | No — the sequence is fixed in code | A nightly ETL job with retries |
| Agent | Yes | Yes — the model picks the next action | A coding assistant that decides which file to open next |
If the sequence of steps is fixed at write-time, you have a workflow, and you should keep it that way — it's easier to test, debug, and reason about. Reach for an agent only when the next step genuinely depends on what happened, in a way you can't enumerate in advance.