A language model on its own is a text predictor: you give it words, it gives you words back. An agent is what you get when you wrap that model in a loop that lets it take actions in the world - search the web, query a database, call an API, run code - observe the results, and decide what to do next. The model becomes less like an autocomplete and more like a colleague who can actually do things.
The Three Ingredients
Tools are functions the model is allowed to call - each with a name, a description, and a schema of arguments. Memory is what the agent carries between steps: the conversation so far, results of previous actions, relevant retrieved facts. The loop is the control flow that ties them together: reason, act, observe, repeat.
The Reason-Act Loop
The core pattern (often called ReAct, for Reason + Act) is a cycle:
1. THINK - the model reasons about what to do next
2. ACT - it chooses a tool and arguments
3. OBSERVE - the tool runs; its result is fed back in
4. repeat until the model decides it has the answer, then ANSWER
Concretely, for "What was our revenue last quarter compared to the same quarter last year?":
THINK: I need two numbers from the database.
ACT: query_db("SELECT revenue WHERE quarter='Q3-2026'")
OBSERVE: 4.2M
THINK: Now the year-ago figure.
ACT: query_db("SELECT revenue WHERE quarter='Q3-2025'")
OBSERVE: 3.1M
THINK: I have both. 4.2 vs 3.1 is +35%. I can answer.
ANSWER: Revenue was $4.2M, up 35% year over year.
How the Model Calls a Tool
You do not parse free text hoping to spot an intent. Modern models have native tool-calling: you pass the tool definitions alongside the prompt, and the model responds with a structured request to call a specific tool with specific arguments. Your code executes it and returns the result.
tools = [{
"name": "query_db",
"description": "Run a read-only SQL query against the analytics warehouse.",
"parameters": { "sql": "string" }
}]
# The model replies with a tool call, not prose:
# { "tool": "query_db", "arguments": { "sql": "SELECT ..." } }
# Your runtime runs it, appends the result, and loops.
The description matters enormously. The model decides whether and how to use a tool almost entirely from its name and description - treat those as prompt engineering, not documentation.
Memory: Short-Term and Long-Term
Short-term memory is the running context of the current task - every thought, action, and observation appended as the loop turns. It is bounded by the context window, which is why long agent runs eventually need summarization: compress older steps into a short recap so the window does not overflow.
Long-term memory persists across sessions - user preferences, facts learned earlier, past outcomes - usually stored externally and retrieved (via RAG) when relevant. This is what lets an agent remember that you prefer metric units or that a customer already tried a fix last week.
Where Agents Go Wrong
Loops that never end. An agent can get stuck repeating an action or chasing its own tail. Always cap the number of steps and fail gracefully when the cap is hit.
Compounding errors. Each step conditions on the last, so one bad observation can derail everything after it. Short chains are more reliable than long ones; design tasks to need few steps.
Dangerous actions. The moment an agent can write to a database, send an email, or spend money, a wrong decision has real consequences. Gate irreversible actions behind confirmation, give tools the narrowest permissions possible, and make every write idempotent so a retry is safe.
Tool sprawl. Give an agent forty tools and it chooses poorly. A small, well-described toolset beats a large one; if you have many, retrieve the relevant few for each task rather than presenting all of them.
The Mental Model
An agent is not a smarter model - it is the same model given hands and a feedback loop. Its intelligence lives in the reasoning; its usefulness lives in the tools and the guardrails around them. Build the loop simple, keep the tools few and sharp, cap the steps, and protect anything irreversible. Most of what separates a reliable agent from a flaky demo is not the prompt - it is that engineering discipline around the loop.