Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
How AI agents work: tool calling, the agent loop, planning and memory, the Model Context Protocol, and the risks of prompt injection and runaway actions.
Quick answer: A language model can only produce text. An agent is a language model placed in a loop with tools. The application tells the model which tools exist and what each does. When the model decides it needs one, it outputs a structured request, such as "call search_flights with these arguments". The application runs that function for real and feeds the result back to the model. The model reads it and decides the next step: call another tool, or give a final answer. Repeating this cycle lets the model look things up, run code, edit files and take actions, working through tasks with many steps.
On its own, a language model:
Tools remove those limits. Instead of guessing an answer from memory, the model can check. That also cuts down on fabricated answers; see why LLMs hallucinate.
The developer gives the model a list of tools. Each has a name, a plain-language description, and a schema for its inputs.
{
"name": "get_weather",
"description": "Get the current weather for a city. Use when the user asks about weather conditions.",
"input_schema": {
"type": "object",
"properties": {
"city": { "type": "string" },
"units": { "type": "string", "enum": ["celsius", "fahrenheit"] }
},
"required": ["city"]
}
}
Given "Do I need an umbrella in Lahore today?", the model does not answer directly. It outputs a structured request:
{ "tool": "get_weather", "input": { "city": "Lahore", "units": "celsius" } }
The model does not run anything. It writes a request, in the same way it writes any other text; see how LLMs predict the next word. Models are trained to produce these requests in a reliable format.
Your code receives the request, checks it, calls the real weather service, and gets a result.
The result is added to the conversation. The model reads it and continues: "Yes, light rain is expected this afternoon, so take an umbrella."
A single tool call is useful. An agent repeats the cycle until the task is done.
loop:
model looks at the goal, the history and the tool results so far
if it needs more information or must act:
it requests a tool -> the application runs it -> the result is added
else:
it gives the final answer and the loop ends
Suppose the task is "find out why the checkout tests fail and fix it". A coding agent might read the test output, open the relevant file, search the codebase for a function, edit the code, rerun the tests, see a new failure, fix that, and run them again until they pass. Nobody scripted those steps. The model chose each one based on what it had just seen.
This pattern of alternating reasoning and action was described in the paper ReAct: Synergizing Reasoning and Acting in Language Models.
Anthropic's guide Building Effective AI Agents draws a helpful line:
| Workflow | Agent | |
|---|---|---|
| Who decides the steps | The developer, in code | The model, as it goes |
| Predictability | High | Lower |
| Best for | Well-defined, repeatable tasks | Open-ended tasks where the steps cannot be known in advance |
| Cost and latency | Lower | Higher |
The guide's advice is to use the simplest thing that works. Many problems are solved by a single well-prompted model call with retrieval, or by a fixed chain of calls. Reach for an agent when the task really does need flexible, multi-step decision-making.
Retrieval is just one kind of tool. An agent that decides when and what to search is sometimes called agentic RAG; see how RAG works.
Every application used to wire up each tool by hand. The Model Context Protocol (MCP) is an open standard for this. A tool provider runs an MCP server that exposes its tools and data in a common format. Any compatible AI application can connect to it. The project describes it as being like a USB-C port for AI applications: one standard connector in place of many custom ones.
Much of an agent's success depends on its tools.
src/app.py?" lets the model recover.Good systems counter these with step limits, verification (run the tests, check the result), and checkpoints.
Giving a model the ability to act raises the stakes.
The underlying principle: the application, not the model, enforces what is allowed.
Judge agents on outcomes, not on fluent explanations. Did the tests pass? Was the right record updated? Build a set of realistic tasks with checkable results, and track success rate, number of steps, cost and time.
A system in which a language model repeatedly chooses and uses tools, observing the results, in order to complete a task with multiple steps.
A feature that lets a model request that the application run a specific function with specific arguments, and then use the returned result.
No. The model outputs a request. The surrounding application runs the tool and returns the result to the model.
The Model Context Protocol, an open standard for connecting AI applications to external tools and data sources through a common interface.
An agent is a simple idea: a language model, a set of tools, and a loop. The model decides, the application acts, and the result informs the next decision. What makes agents work in practice is unglamorous engineering: well-described tools, managed context, verification, and firm limits on what the agent is permitted to do.