What an AI agent is, explained with a game NPC: brain, tools and the think-act-observe loop

An AI agent is a language model with tools that plans, acts and checks the result until the goal is reached. A game NPC makes it easy to see: brain and body, the thought-action-observation loop, ReAct and MCP, plus a hands-on chat exercise.
An AI agent is a program built on a language model that understands what you want, makes its own plan and carries it out with the help of tools until the goal is reached. The easiest way to see this is through an NPC, a non-player character in a video game. What follows is a lesson from our course rewritten as an article: it starts with a merchant who can say exactly one line and ends with a character who calls for backup on their own. At the end there is a practice exercise you can do in any AI chat in a single sitting.

Short on time? Five points
- Agent = brain + body. The brain is a language model: it thinks and plans. The body is its tools: whatever the agent can actually do.
- The model itself can only write text. Pictures, search and sending emails come from tools that developers have connected to it.
- An agent works in a loop: thought → action → observation. It repeats the loop until the task is done.
- The main defense against made-up results is stopping after the action. The agent has to wait for the real result instead of inventing one.
- You have probably already built an agent's "brain" if you have ever written a system prompt: a role, rules, steps and criteria for checking the work.
NPCs: an agent you have met a thousand times
If you have played The Sims, Skyrim, GTA or Minecraft, you have met NPCs, the non-player characters. They are the merchants, guards and villagers. They answer you, hand out quests, point the way, and sometimes attack or run away.
Walk up to a merchant and say, "I want to buy a sword." A good merchant understands the request and replies, "I have two swords, an iron one and a golden one." Behind that small scene are three steps, and they sit at the core of every AI agent:
- Understand: what does the player want? A sword.
- Plan: what needs to happen? Show the goods and name the prices.
- Act: lay out the swords and wait for the player to choose.
It is as if the merchant has a small brain in their head that thinks, decides and acts. That brain is what we are going to take apart.
Three levels of agency
Not every NPC is an agent. The difference is how many decisions it makes on its own.
| Level | How the NPC behaves | What it looks like when working with AI |
|---|---|---|
| 1. Barely an agent | says the same line no matter what you do | a single prompt: you set the style and tone, and the model answers within that frame |
| 2. Rule-following agent | reacts to your words and choices, but only within a script | an assistant with a system prompt: role, rules, steps, self-check |
| 3. High-level agent | builds its own plan, picks its reaction, uses tools and calls other NPCs | an agent with tools in Make or n8n: it searches, records, sends, and hands a task to another agent |
Level one. You tell the model "answer briefly, in a business tone" and add some prompting tricks, such as "rate your confidence" or promising a reward for a good answer. The model changes its manner but makes no decisions. It is like the robot that was built for exactly one job: passing the butter.
Level two. An assistant with a good system prompt already reacts: it asks clarifying questions, checks itself, and changes its answer based on your feedback. Ask it to "act as a focus group of five different customers" or "grade your own work more strictly," and it will adjust. But it has no tools: all it can do is write text.
Level three. The agent gets a goal, not a command. It decides for itself which steps are needed, which tools to use for them and who to call for help. These are the agents people build in Make and n8n.
How a simple NPC differs from a high-level agent
A simple NPC answers with lines that were written in advance. It offers a menu of choices and canned replies, and it makes no decisions of its own.
A high-level agent:
- understands the situation and the goal. "The village is under attack. My job is to protect it";
- sets its own subtasks. Call for help, pick up a weapon, go to the gates, fight, check whether more help is needed;
- picks a tool for each subtask. To call for help, it sends a signal to other NPCs. To find a weapon, it looks in its inventory. To attack, it uses a combat skill;
- plans several steps ahead. Out of potions? Get potions first, then go help;
- changes the plan on the fly. More enemies show up, so it calls for more help. It takes damage, so it looks for a potion. The goal is reached, so it goes back to its usual routine;
- works in a team. It sends tasks to other NPCs, receives "come help" signals, and agrees on "let's attack together."
Here is what the inner voice of such an NPC might sound like 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 and arrows. Getting into position by the gates. If allies come, we act together. If not, I fall back to get potions.
That is the difference between following a script and thinking.
The agent's brain and body
Picture an agent as two parts.
The brain is the language model. All the thinking happens here: the model works out the situation, reasons about it and decides what to do next.
The body is its abilities and tools. Everything the agent can actually do. A human has no wings, so "fly" is not in the list of actions, but "walk," "run," "jump" and "grab" are. It is the same with an agent: whatever has been connected to it is what it can do.
If you have gone through our lessons on system prompts, you have already built an agent's brain:
- a role: who it is;
- rules: how it thinks and what it does not do;
- steps: which actions it takes and in what order;
- checking criteria: how it judges its own work before handing it over;
- an output format: what should come out at the end.
To let an agent go beyond text, all that is left is to add the body to this brain.
How the brain writes an answer: three animations
To understand why an agent needs tools, it helps to see once how a model produces text at all. Each animation below is followed by a plain-English explanation.

The model writes one piece at a time. It takes the text so far, predicts the next piece, adds it, and feeds the whole thing back into itself. It goes around like this until it outputs a special "end" marker.

The pieces are called tokens. Before it starts, the model cuts the text into tokens, which are words and parts of words, and turns them into numbers. For the next token it gets a score for every option, converts the scores into probabilities and picks a suitable one. In the animation, after "Paris is the city" the most likely next token turns out to be "of."

Not all words matter equally. In the phrase "The capital of France is…", the words that matter most for the next word are "capital" and "France." The model can "look" at the right words more strongly than at the rest. This mechanism is called attention, and every modern language model is built on it.
What follows from this. A model is a very clever predictor of the next word. It cannot find out today's weather, open a website or send an email on its own: what it knows is limited to what it was trained on. Tools do everything else.
Tools: the agent's superpowers
You ask a chatbot to draw the Eiffel Tower made of broccoli, and it does. But we have just established that a model can only write text. How is that possible?
The developers of the app connected a tool to the model: a separate function that draws pictures. The model writes, "draw this," the program around it calls the image generator, and you see a picture. With tools, an agent can:
- search for fresh information on the internet;
- do calculations;
- create images and video;
- send emails and messages;
- work with other services such as a calendar, a spreadsheet or a customer database.
By the way, image and video generators are also simple "NPCs for content." In the past a video needed a film crew. Now you describe a reference, get a script as text, and generate frames from it. It is the same principle: the brain writes the assignment and the tool does the job.
What a tool is made of
A tool is a function with a description. Each one has four parts:
| Part | Example for a calculator |
|---|---|
| Name | calculator |
| Description: what it does | multiplies two whole numbers |
| Inputs | a is a whole number, b is a whole number |
| What it returns | a whole number, the result |
In code it looks like this. You do not need to program anything, just look at how it is put together:
```python
@tool
def calculator(a: int, b: int) -> int:
"""Multiply two whole numbers."""
return a * b
```
The @tool marker tells the program: "This is a tool. Pull out its name, description and inputs, and show them to the model."
How the model "presses" a tool
A model cannot run a function by itself. Here is what actually happens:
- The model sees a list of tools with descriptions in its instructions.
- When it needs a tool, it writes a command as text, for example, "call calculator with the numbers 2 and 5."
- The wrapper program around the model catches that command, really calls the function and hands the result back to the model.
To the user it looks as if the AI does everything itself. In reality the tool is called behind the scenes.
Why the description is everything
An agent has to know exactly which tools exist, what each one does, what data it needs and what it returns. If a tool is not described, the model cannot use it properly. A poor description is the most common reason an agent "acts dumb."
What MCP is
MCP is a common standard for describing tools so that different systems can understand each other. A tool described through MCP can be plugged into any agent that supports the standard. It is like a universal socket: any appliance with the right plug works in any matching socket.
The thought → action → observation loop
Now for the main part: how an agent works over time. It runs in a loop of three steps:
- Thought. The model decides what the next step is.
- Action. The agent calls a tool with the right data.
- Observation. The agent receives the result and takes it into account.
Then back to thought, until the goal is reached. In programmers' terms, it is a "while" loop: it keeps going while the task is unsolved.

Example 1. The guard at the gate
The player walks up to the guard at a castle gate: "Open the gate!"
- Thought: "I've been told to open the gate. Who is this? Can I open it for anyone? I'll check for a pass."
- Action: check the player's inventory.
- Observation: the player has a pass.
- Thought: "I'll open it."
- Action: call the function that opens the gate.
- Observation: the gate opened.
- Answer: "Go ahead, the gate is open!"
And if the gate did not open? A new thought: "Why not? I'll check the lock." A new action: repair the lock. A new observation: it worked or it didn't. The guard goes around the loop again until the task is done or he realizes he can't do it.
Example 2. A helper that knows the weather
Now an example from real life. We built a weather helper that has a single tool, a weather service. The user asks: "What's the weather in New York right now?"
Thought. "The person needs the weather right now. I don't know it myself, but I have a weather tool. I'll call it first."
Action. The helper writes a command in a strict format called JSON. It is just text with a clear structure of "what to do" and "with what data":
```json
{
"action": "get_weather",
"action_input": {
"location": "New York"
}
}
```
Observation. The tool returns: "New York: partly cloudy, 15 °C, humidity 60%." This reply is added to the text the model sees.
Updated thought. "I have the data, so I can answer."
Final answer. "Right now in New York it's partly cloudy, 15 °C, with 60% humidity."
What matters here:
- the loop repeats until the goal is reached. If the tool had returned an error, the helper would have tried again or tried a different way;
- the tool takes the agent beyond what it knows. The model doesn't know today's weather, but the tool does;
- every observation sharpens the next thought. That is why the final answer rests on facts, not a guess.
The agent's thoughts: "step by step" and ReAct
A simple NPC always reacts the same way: the player walks up, so "Hello"; the player attacks, so it runs away. A smart NPC has an inner dialogue: "What is happening right now? What am I trying to achieve? What is the best way to act?"
Here are the kinds of thoughts it can have:
| Type of thought | What it sounds like for an NPC |
|---|---|
| Planning | "First I'll scout the area, then report to the captain" |
| Analysis | "The player is wounded, so I should offer a potion" |
| Decision | "Better to dodge. Fighting alone is too dangerous" |
| Problem solving | "My axe is broken, so I'll repair it or take another" |
| Memory | "The player helped me before, so they can be trusted" |
| Self-check | "I made a mistake last time, so I'll be more careful now" |
| Goal | "My job is to hold the gate until the guards arrive" |
| Priorities | "First I'll help my ally, then go on patrol" |
There are two popular ways to get a model to think like this.
"Step by step" (in the literature, Chain of Thought). The model splits a task into stages and reasons through them in order instead of jumping straight to the answer. The player asks for a potion: "First I need herbs, so I go to the forest. I have the herbs, so I go to the shop. I mix them. The potion is ready."
ReAct comes from the words "reason" and "act." After each thought, the model really does something and looks at the result. Someone asks the merchant, "Do you have a healing potion?" Thought: "I'll check my stock." Action: check the inventory. Observation: two potions. Thought: "I can sell one." Action: "Yes, I have some. Want to buy?" If there had been no potion: thought, "I need to restock," and action, order from the alchemist.
| "Step by step" | ReAct | |
|---|---|---|
| Reasoning in steps | yes | yes |
| Actions and tools | no, only an inner monologue | yes, after each step of thought |
| Where it works best | simple reasoning, puzzles, calculations | multi-step tasks, working with the outside world |
Actions: how the agent says what to do
An action is not a phrase but a concrete intervention in the world: open a chest, pick up an item, call for help, send a message. So that the program can understand the agent, actions are written in a strict form. There are three ways to do it:
| Type of agent | How it describes an action | Example |
|---|---|---|
| JSON agent | a structured command | {"action": "heal", "target": "player"} |
| Function-calling agent | a command to run a specific function | heal_player("player_id") |
| Code agent | writes a whole piece of a program | a loop that sends idle guards to their posts |
A code agent is the most flexible. Instead of one command, it writes a ready-made program, for example, "find all idle NPCs, send them to the castle, start the patrol." The upsides: complex logic with repeats and conditions is easy to write in code, code is easier to check, and it connects straight to outside services. There is also a serious downside: code written by a model has to be checked for safety before it runs.
Why the agent must stop after an action
This is the most important rule in the whole article. The agent should:
- give a clear command, such as "open chest No. 12";
- stop and wait for the real result;
- only then think about what comes next.
If you do not stop the model after the "Action" line, it will happily write the "Observation" itself. That means it will make up the result: "the chest is open, there's gold inside." This is how agent hallucinations are born. The right pattern is: act, get the result, think, then act again.
Observation: the agent's eyes and ears
An observation is what the agent finds out after its action. Without this step it can neither learn nor adjust.
| Kind of observation | Example |
|---|---|
| System error | "The lock is jammed, the door didn't open" |
| Change in data | "A potion appeared in the inventory, so the purchase worked" |
| Change in the environment | "It started to rain" |
| Check result | "The player has 10 health points left" |
| Time-based event | "Time is up, the quest has failed" |
Here is how the agent uses an observation:
- it takes an action, such as trying to open a chest;
- it gets an observation: "the chest is locked";
- it remembers that;
- it plans the next step with the new knowledge: "I need a key, so I'll look for one or ask the player."
Without observation, an NPC looks ridiculous: it keeps trying to break into a chest that is already open, or runs away from an enemy that was beaten long ago.
Where this is useful in real life
The same loop works in assistants: first break down the task, then pick up a tool, then check the result. A combination of email, calendar, search and automation is exactly an NPC agent, only instead of a village it works in your workday.
People usually come to agents by a ladder like this:
- The system prompt gets more complex. Instead of "answer questions," you describe a line of thought: "First assess the task, then decide whether a tool is needed, then act."
- Tools appear. Search, sending messages, working with spreadsheets, generation.
- Roles appear. One agent is the "chief strategist," the others are executors, each with its own subtask.
If you want to see how ready-made assistants are built on the inside, take a look at the AI assistants section of the platform, which has 200+ AI assistants for different professions and tasks. How to make your own and hand it to a client is covered in the article on building your own AI assistant. And if you want a big-picture view of how an agent differs from an ordinary chat, here is our breakdown of the basics.
Practice: build your own NPC agent in any chat
You need neither code nor n8n for this. All you need is any AI chat: ChatGPT, Claude or Gemini. You will play the part of the "wrapper program" and bring the agent the results of its actions yourself. That way you will see the thought → action → observation loop and the stop rule with your own eyes.
Step 1. Open a new chat and paste in this instruction in full:
```
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.
- check_inventory: check whether an item is in stock. Input: {"item": "name"}. Returns the quantity and the price.
- order_from_alchemist: order an item from the alchemist. Input: {"item": "name", "count": number}. Returns the delivery time.
- 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" and stop. Now you are the game. Reply with something like this:
```
Observation: healing potion, 1 in stock, price 50 coins.
```
Step 4. Watch the merchant rework the plan: one potion is not enough, so he needs to order from the alchemist. Keep replying with observations until he gets to the "Answer."
What to check:
- whether the model stopped after the "Action." If it wrote the "Observation" itself, strengthen the stop rule in the instruction. This is exactly the mistake that makes agents invent results;
- whether the merchant changed his plan when there was not enough stock;
- what happens if you send back an error: "Observation: the alchemist is closed until morning."
Step 5, for your portfolio. Replace the fantasy setting with a real business. The merchant becomes an online store consultant. check_inventory becomes a stock check in a spreadsheet. order_from_alchemist becomes an order from a supplier. give_item becomes placing the order. The same instruction with real products is already a prototype of an assistant you can show to a client. Save the conversation: it is a clear demonstration of how your agent thinks.
Check yourself
- Which description fits an AI agent best? A) a model that reasons, plans and uses tools to reach a goal; B) a system that only processes text; C) a conversation partner that answers and does nothing else; D) a database that stores information.
- Why does an agent need planning? A) to remember the past; B) to choose the order of actions and the right tools; C) to act at random; D) to translate text.
- Why does an agent need tools? A) they add nothing; B) they are just data storage; C) they limit the agent; D) they let it do what the model alone cannot: search, calculate, draw.
- How does an action differ from a tool? A) an action is a step the agent takes, and a tool is what that step is carried out with; B) they are the same thing; C) tools only store data; D) actions always need a model, while tools do not.
- What role does the language model play in an agent? A) it is the database; B) it is the brain: it understands the task and plans the actions; C) it only works with images; D) it has nothing to do with agents.
- What best illustrates an AI agent? A) a page with ready-made answers; B) a calculator; C) a voice assistant that understands a command, thinks it over and sets a reminder or sends a message; D) an NPC that always says one line.
Answers: 1 is A, 2 is B, 3 is D, 4 is A, 5 is B, 6 is C.
And three questions to think about. They are easy to work through together with an AI: ask it the question and argue with its answer.
- Which NPC behavior would look ridiculous without the "observation" step?
- What task, in a game or in life, could only a high-level agent solve, and not a simple NPC?
- Which tools would you give your NPC to make it smarter?
FAQ
What is an AI agent in simple terms?
It is a program built on a language model that receives a goal, makes its own plan, carries out actions with the help of tools and checks the result until the goal is reached. An ordinary AI chat only replies with text, while an agent also acts.
How is an AI agent different from a chatbot?
A chatbot answers messages within a script or an instruction. An agent receives a goal, breaks it into steps and picks the tools itself: search, spreadsheets, email, generation. It also changes its plan if the result of a step is not what it expected.
What is the "thought, action, observation" loop?
It is the way an agent works: the model decides what to do (thought), calls a tool (action) and gets the result (observation). Then it thinks again with that result in mind, until the task is solved. The approach is called ReAct.
Why do agents make up results, and how do you stop it?
If you do not stop the model after the command to act, it writes a plausible result itself instead of the real one. The fix is a rule in the instruction and a setting in the program: after the "Action" line, the model stops and waits for the tool's real answer.
What is MCP?
MCP is a common standard for describing tools for AI agents. A tool described under this standard can be plugged into any agent that supports it, like an appliance with a universal plug in a universal socket.
Want to know why your bot acts dumb? Read Why your bot is dumb: the anatomy of a system prompt.