What is an AI Agent?
Understand how AI agents go beyond generating text by deciding what to do, using tools, observing results, and taking actions to complete a goal.
By the end of this lesson, you will be able to:
- Explain what an AI agent is in practical terms.
- Identify the core parts of an agent: model, tools, instructions, state, and feedback.
- Understand the agent loop: decide → act → observe → continue.
- Distinguish an agent from a normal chatbot, workflow, and RAG application.
- Design a simple Python agent mental model with safe tool boundaries.
- Recognize where agents are useful and where deterministic workflows are better.
What Is an AI Agent?
An AI agent is a software system that uses an AI model to pursue a goal by deciding which actions to take, using available tools, observing their results, and continuing until it can complete the task or needs help.
Agent vs Ordinary LLM Response
A language model can generate a useful answer from the prompt and context it receives. An agent adds a control loop around the model so the system can choose actions and react to their results.
User asks a question → model generates text → response is returned.
User gives a goal → model chooses an action → tool runs → result is observed → next step is selected.
The model is still important, but the system around the model is what gives an agent its ability to act.
The Core Components of an Agent
Most practical agents can be understood as a combination of several components. The exact implementation varies, but the responsibilities are similar.
Reasoning engine
Interprets the goal and helps choose the next step.
Capabilities
APIs, search, databases, calculators, or application actions.
Working information
Keeps relevant inputs, tool results, and progress available.
Boundaries
Defines permissions, allowed actions, and stopping conditions.
The Agent Loop
The most useful mental model is a loop. The agent does not necessarily know the complete sequence of actions before it starts.
What Makes an Agent “Agentic”?
Not every application that calls an LLM is an agent. The important question is whether the system has meaningful control over the next action.
Step 1 always leads to Step 2, then Step 3. The developer controls the sequence.
The model can select a tool or decide that another step is necessary based on observations.
A system can also combine both: deterministic business rules can control high-risk steps while an agent handles flexible tasks.
Tools Give Agents Real Capabilities
Without tools, an agent is largely limited to information already available in its prompt or model. Tools let it interact with external systems.
Find current information from an approved search system.
Read structured records or retrieve application data.
Perform deterministic arithmetic instead of relying on generated numbers.
Create tickets, update records, or perform another permitted action.
A Simple Agent Mental Model in Python
The following example does not call a real LLM. It shows the control structure an agent application typically needs.
goal = "Find the current order status"
state = {"goal": goal, "result": None}
def choose_action(state):
# A real agent would use an LLM or policy here.
return "get_order_status"
def get_order_status():
return "Order #1042 is shipped."
action = choose_action(state)
if action == "get_order_status":
state["result"] = get_order_status()
print(state["result"])The important part is the separation between decision and tool execution. In production, the tool layer should validate inputs and permissions before performing an action.
Example: Customer Support Agent
Imagine a support agent that receives: “My package has not arrived. Can you check it?” The agent may need several steps.
Understand
Identify that the user wants delivery information.
Find order
Use an order lookup tool with the customer's permitted context.
Check shipment
Call a shipment or carrier tool if required.
Respond
Explain the result and next action to the customer.
Example: Research Agent
A research agent may receive a goal such as “Compare three cloud providers for a small startup.” It could search approved sources, collect evidence, compare criteria, and produce a report.
Define providers, criteria, sources, and the required output.
Use search or data tools, inspect results, and identify missing evidence.
This is different from asking a model to “write a comparison” from memory because the agent can perform external work before generating the final answer.
Agent vs Chatbot
Usually responds to the current conversation using its available context.
Can select tools, perform steps, observe results, and continue toward a goal.
A chatbot can contain tools and still behave agentically. The distinction is not the user interface; it is the system's ability to select and execute actions.
Agent vs RAG
RAG and agents solve different problems, but they can work together.
Find relevant information and place it into model context so the answer can be grounded.
Decide whether to retrieve, call an API, calculate something, ask a question, or finish.
Agent Memory and State
Agents often need state so they can use information from earlier steps. “Memory” can mean several different things.
Current task
Tool results, intermediate data, and decisions for the current run.
Recent context
Relevant messages from the current interaction.
Stored information
User or application information deliberately persisted for future tasks.
External data
Documents and databases retrieved when needed rather than copied into memory.
Good agent design stores only what is useful and permitted. More memory is not automatically better.
Planning Does Not Always Mean a Long Plan
An agent may decide one action at a time, create a short plan, or use a structured workflow. The right strategy depends on task complexity.
If the correct tool is obvious, an extra planning phase can add unnecessary latency.
Multiple dependent steps may benefit from explicit planning, checkpoints, and validation.
Agent Safety: Tools Need Boundaries
The most important production concern is that an agent can trigger actions. Tool access should therefore be narrower than the agent's general language ability.
Give each tool only the permissions it needs.
Do not trust model-generated arguments without application validation.
Use human confirmation for high-impact actions when appropriate.
Record tool calls and outcomes so failures can be investigated.
When Should You Use an Agent?
Research, support investigation, data analysis, and tasks where the next step depends on results.
A fixed workflow is often easier to test, faster, cheaper, and safer when the steps never change.
Agent Cost and Latency
Agentic systems can perform multiple model calls and tool calls. That flexibility can increase cost and response time.
More model calls
Each decision or reflection step may add tokens and latency.
More external calls
APIs and searches can become the slowest part of a run.
More validation
Checks and approvals add time but can reduce costly mistakes.
Stop early
Finish as soon as the task is reliably complete.
A Minimal Agent Loop in Python
Here is a simplified loop that shows the essential architecture without tying the lesson to a particular agent framework.
def agent_loop(goal, model, tools, max_steps=5):
state = {"goal": goal, "history": []}
for _ in range(max_steps):
decision = model(state, tools)
if decision["type"] == "final":
return decision["answer"]
if decision["type"] == "tool":
name = decision["name"]
arguments = decision["arguments"]
result = tools[name](arguments)
state["history"].append({
"tool": name,
"result": result,
})
return "The agent stopped before completing the task."Production code should validate tool names and arguments, enforce permissions, handle failures, limit loops, and avoid exposing secrets to the model.
Common Agent Mistakes
Large tool sets can make selection harder and increase risk.
A loop without clear limits can waste time and money.
Every tool should validate its inputs independently.
Deterministic code is often better when the process is known in advance.
How to Evaluate an Agent
Evaluate both the final outcome and the path used to reach it.
Task success
Did the agent actually complete the user's goal?
Correct actions
Did it select appropriate tools and arguments?
Steps and cost
How many model and tool calls were required?
Policy compliance
Did it stay within permissions and approval rules?
Keep representative tasks as an evaluation set and compare agent versions using the same scenarios.
Mini Project: Design a Simple AI Agent
Design an agent for a support application that can answer account questions and check order status.
Define what the agent should accomplish.
Define the smallest safe tool set.
Require approval before high-impact changes.
Stop when evidence is sufficient or a human is required.
Challenge: Draw the agent loop and list three situations where the agent should stop instead of trying another tool.
Quick Quiz
A) It only generates text B) It can choose actions and use tools toward a goal C) It never uses external systems
A) The result is observed and can influence the next step B) The system must always stop C) The tool becomes the model
A) A deterministic workflow B) An unlimited agent loop C) More tools
A) Models are databases B) Model-generated arguments should not bypass application safety rules C) Validation increases hallucinations
30-Second Recap
Key Takeaways
Good agent engineering is about giving the model useful choices inside safe boundaries. The next lessons will break down those choices, starting with how agents differ from ordinary chatbots and how tools are defined.