An AI agent is a program built on a language model that takes a goal, makes its own plan and carries it out with tools until the job is done. The fastest way to see it is through a video game NPC: start with a merchant who can say exactly one line and end with a guard who calls for backup on his own.
The five-point version
- Agent = brain + body. The brain is a language model that thinks and plans. The body is its tools: whatever it can actually do.
- A model alone only writes text. Pictures, search and sending email come from tools that developers connected to it.
- An agent runs in a loop: thought → action → observation. It repeats until the task is solved.
- The main defense against invented results is stopping after the action. The agent waits for the real result instead of writing one itself.
- If you have ever written a system prompt, you have built a brain. Role, rules, steps, checking criteria and output format are the same parts.
Start with a merchant
Say to a shop NPC, "I want to buy a sword." A good one answers, "I have two, an iron one and a golden one." Three steps happened there, and they sit at the core of every agent:
- Understand. The player wants a sword.
- Plan. Show the goods and name the prices.
- Act. Lay out the swords and wait for a choice.
Three levels of agency
Not every NPC is an agent. The difference is how many decisions it makes on its own.
| Level | NPC behavior | In AI terms |
|---|---|---|
| 1. Barely an agent | says the same line whatever you do | a single prompt: you set style and tone, the model answers inside that frame |
| 2. Rule-following | reacts to your words, but only within a script | an assistant with a system prompt: role, rules, steps, self-check |
| 3. High-level | builds its own plan, uses tools, calls other NPCs | an agent with tools in Make or n8n: it searches, records, sends, hands a task to another agent |
Level two can ask clarifying questions and grade its own work more strictly, but it has no tools. All it can do is write text. Level three gets a goal instead of a command and decides which steps and tools it needs.
Here is the inner voice of a level-three NPC when the player shouts "Goblins are attacking the village!":
I need to protect the village. How many goblins? I can't handle them alone. Sending a signal to the neighbors. Taking my bow. Getting into position by the gates. If allies come, we act together. If not, I fall back for potions.
It understands the goal, sets subtasks, picks a tool for each, changes the plan on the fly and works in a team. That is the difference between following a script and thinking.
Brain and body
The brain is the language model. A model is a very good predictor of the next word: it takes the text so far, predicts the next piece (a token), adds it and feeds everything back in, until it outputs an end marker. It cannot check today's weather, open a site or send an email, because what it knows is limited to its training.
The body is everything you connect. A human has no wings, so "fly" is not an action. Same for an agent: it can do exactly what has been plugged in.
Tools: where the superpowers come from
You ask a chatbot to draw the Eiffel Tower made of broccoli and it does. But a model only writes text, so how? The app's developers connected a tool, a separate function that draws pictures. The model writes "draw this", the program around it calls the generator, and you see a picture.
A tool is a function with a description, and it has four parts:
| Part | Example: a calculator |
|---|---|
| Name | calculator |
| Description | multiplies two whole numbers |
| Inputs | a and b, whole numbers |
| Returns | a whole number |
In code it looks like this:
@tool def calculator(a: int, b: int) -> int: """Multiply two whole numbers.""" return a * b The @tool marker tells the program to pull out the name, description and inputs and show them to the model.
The model never runs the function itself. It sees the tool list, writes a command as text ("call calculator with 2 and 5"), and the wrapper program catches it, calls the function and hands the result back. To the user it looks like the AI did everything. In reality the call happened behind the scenes.
That is why the description is everything. A poorly described tool is the most common reason an agent "acts dumb".
MCP is a common standard for describing tools, so a tool described that way plugs into any agent that supports it. Think of a universal socket.
The loop: thought, action, observation
- Thought. The model decides the next step.
- Action. The agent calls a tool with the right data.
- Observation. It receives the result and takes it into account.
Then back to thought, until the goal is reached. In programmer terms it is a while loop that runs while the task is unsolved.
Example: a guard at a gate. The player says "Open the gate!"
- Thought: who is this? I'll check for a pass.
- Action: check the player's inventory.
- Observation: there is a pass.
- Thought: I'll open it.
- Action: call the open-gate function.
- Observation: the gate opened.
- Answer: "Go ahead."
If the gate had not opened, the next thought would be "why not?", the next action "check the lock", and the guard goes around the loop again.
Example: a weather helper with one tool. The user asks, "What's the weather in New York right now?" The helper thinks: "I don't know it, but I have a weather tool." Then it writes a command in JSON:
{ "action": "get_weather", "action_input": { "location": "New York" } } The tool returns "New York: partly cloudy, 15 °C, humidity 60%". That reply is appended to the text the model sees, and the final answer rests on a fact instead of a guess. If the tool had returned an error, the helper would retry or try another way.
"Step by step" versus ReAct
Two popular ways to make a model reason:
| Step by step (Chain of Thought) | ReAct | |
|---|---|---|
| Reasoning in stages | yes | yes |
| Actions and tools | no, inner monologue only | yes, after each thought |
| Best for | puzzles, calculations | multi-step tasks, the outside world |
ReAct comes from "reason" and "act". Asked "Do you have a healing potion?", the merchant thinks "I'll check stock", checks the inventory, sees two potions, and only then answers.
The one rule that prevents hallucinated results
An action is written in a strict form (a JSON command, a function call, or a whole snippet of code) so the program can read it. Then comes the rule.
After the action line, the agent must:
- give a clear command, such as "open chest No. 12";
- stop and wait for the real result;
- only then think about the next step.
If you do not stop the model after "Action", it will happily write the "Observation" itself: "the chest is open, there's gold inside". That is how agent hallucinations are born. Observation is also what lets an agent adjust: without it an NPC keeps trying to break into a chest that is already open.
Your turn: build an NPC agent in any chat
No code needed. Open ChatGPT, Claude or Gemini. You play the wrapper program and bring the results back yourself, so you see the loop and the stop rule with your own eyes.
Step 1. Paste this into a new chat:
You are an NPC merchant named Born in a fantasy game. Your goal is to help the player buy what they need. You have tools. You do not run them yourself: you only write the command, and the game will send you the result. 1. check_inventory: check whether an item is in stock. Input: {"item": "name"}. Returns the quantity and the price. 2. order_from_alchemist: order an item from the alchemist. Input: {"item": "name", "count": number}. Returns the delivery time. 3. give_item: hand an item to the player. Input: {"item": "name"}. Returns whether it worked. Work strictly in this format: Thought: what you are thinking right now and what you plan to do. Action: a command in JSON format, for example {"action": "check_inventory", "action_input": {"item": "healing potion"}} After the "Action" line, STOP and write nothing more. Never make up a result yourself: wait for the "Observation:" message from the game. When the task is solved, write: Thought: why it is time to answer. Answer: what you say to the player, in character as a merchant, no more than three sentences. Step 2. Write as the player: "Hi, do you have a healing potion? I need three."
Step 3. The model should write a Thought and an Action, then stop. You are the game. Reply:
Observation: healing potion, 1 in stock, price 50 coins. Step 4. Watch it rework the plan: one potion is not enough, so it orders from the alchemist. Keep sending observations until it reaches "Answer".
Check three things: did it stop after "Action" (if it wrote the Observation itself, strengthen the stop rule); did it change the plan when stock ran short; what happens if you send an error such as "Observation: the alchemist is closed until morning".
Bonus: swap the fantasy for a real shop. check_inventory becomes a spreadsheet lookup, order_from_alchemist a supplier order. Same instruction, now a prototype assistant you can show a client.
The full lesson, including a quiz and FAQ, is on our blog: What an AI agent is, explained with a game NPC.
This article was written with the help of AI and fact-checked by the AI SKILLS team.