What Are AI Agents? How They Work, With Examples
An AI agent is a program that uses a large language model (LLM) to decide what to do next, takes actions with tools, looks at the results, and repeats until the task is done. A chatbot only answers. An agent acts.
Chatbot vs agent: a clear example
Ask a chatbot: "What is the weather in Delhi and should I carry an umbrella?" It can only answer from memory, so it guesses or says it does not know.
Give the same request to an agent with a weather tool:
- The model thinks: "I need the current weather."
- It calls
get_weather("Delhi"). - The tool returns: "Rain, 24°C".
- The model reads the result and answers: "It is raining in Delhi. Yes, carry an umbrella."
The model did not get smarter. It got the ability to act and to see the result.
The four parts of an AI agent
Every agent, simple or complex, has the same parts:
- Model. The LLM that reads the situation and decides the next step. See what an LLM is.
- Tools. Functions the model may call: search the web, run code, read a file, send an email, query a database. This is explained in LLM function calling.
- Loop. Code that runs the model, executes the tool it asked for, gives the result back, and repeats.
- Instructions and memory. The system prompt that explains the job and rules, plus the history of what has happened so far.
Here is the loop in simple code:
messages = [system_prompt, user_task]
for step in range(MAX_STEPS):
reply = llm(messages, tools=tools)
if reply.tool_call is None:
print(reply.text) # the model is done
break
result = run_tool(reply.tool_call) # your code runs the tool
messages.append(reply)
messages.append(tool_result(result))
That small loop is the core of every agent framework. You can build one yourself with the guide to building an AI agent from scratch in Python.
AI agents vs agentic AI
These two terms are used together a lot, so here is the difference:
- AI agent: one system that works toward a goal with tools.
- Agentic AI: the general style of building software this way. It also covers systems where several agents work together, each with its own role.
In daily use, "agentic" just means "the model decides the steps", in contrast to a fixed workflow where the programmer decides them.
Workflows vs agents
Not every task needs an agent.
| Workflow | Agent | |
|---|---|---|
| Who decides the steps | The programmer | The model |
| Predictable | Yes | Less |
| Cost and speed | Lower, faster | Higher, slower |
| Best for | Tasks with known steps | Open tasks where steps are not known in advance |
- Who decides the steps — Workflow: The programmer; Agent: The model
- Predictable — Workflow: Yes; Agent: Less
- Cost and speed — Workflow: Lower, faster; Agent: Higher, slower
- Best for — Workflow: Tasks with known steps; Agent: Open tasks where steps are not known in advance
If you can draw the steps as a flowchart, write a workflow. Use an agent when the path depends on what is found along the way, such as debugging code or researching a question.
Real examples of AI agents
- Coding agents read a codebase, edit files, run tests, and fix errors until the tests pass. See AI coding assistants.
- Research agents search the web many times, read pages, and write a report with sources.
- Customer support agents look up an order, check the refund policy, and start the refund.
- Data agents write SQL, run it, look at the result, and fix the query if it fails.
The main risks
Agents take real actions, so mistakes cost more than a wrong sentence.
- Errors add up. If each step is right 95 percent of the time, a 20-step task finishes correctly only about 36 percent of the time. Keep tasks short and check results.
- Endless loops. An agent can repeat the same failing step. Always set a maximum number of steps and a spending limit.
- Dangerous actions. An agent with access to a production database can delete it. Give the smallest permissions that work, and ask a person to approve actions that cannot be undone.
- Prompt injection. A web page or email the agent reads can contain hidden instructions. Read prompt injection explained before you connect an agent to outside content.
How tools are connected: MCP
Writing a custom connection for every tool is slow. The Model Context Protocol (MCP) is an open standard that lets any agent talk to any tool server in the same way. See what an MCP server is.
FAQ
What is an AI agent in simple words?
It is an AI model that can use tools and keep working in a loop until a task is finished, without a person guiding each step.
Is ChatGPT an AI agent?
A plain chat is not. When the product searches the web, runs code, or completes multi-step tasks for you, it is working as an agent.
Do I need a framework to build an AI agent?
No. An agent is a loop around an LLM API call with tools. Frameworks help with larger projects, but starting without one teaches you how agents really work.
Are AI agents reliable?
They are reliable for short, well-defined tasks with good tools and clear checks, such as running tests. They are much less reliable for long tasks with no way to verify progress.