Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 39 ยท Getting Started

What Is an AI Agent?

Learn what an AI agent is, how it differs from a chatbot or a plain script, and the perceive, decide, act loop behind every agent, with runnable Python.

An AI agent is a program that pursues a goal by repeatedly looking at its situation, deciding what to do next, and doing it, until the goal is met or it gives up. The "deciding" part is usually done by a large language model (LLM), but the idea is older than LLMs: a thermostat, a game bot and a robot vacuum are all agents in the classic sense. What is new is that a language model can decide in open-ended situations, using plain English instructions instead of hand-written rules.

This course teaches you to build such agents from first principles. You will learn the loop, tools, planning, memory, multiple agents, evaluation, safety and deployment. Most examples run right here in your browser, so you can experiment as you read.

No real LLM is called on this site, because a hosted model needs an API key and a network. Every runnable example uses a small scripted stand-in, labelled as such, that plays the role of the model. The control flow around it (loops, tools, state, limits) is exactly what you would write for a real model. Real provider code is shown in read-only blocks.

Agent, chatbot, script: what is the difference?

A plain script follows steps you wrote in advance. A chatbot answers one message at a time and forgets that it could do anything beyond talking. An agent has three extra ingredients:

  1. A goal that takes more than one step to reach.
  2. Tools that let it affect the world (search, read a file, run code, send a request).
  3. A loop that feeds the result of each action back in, so the next decision can use it.
flowchart LR
  G["Goal"] --> D["Decide<br/>(LLM or rules)"]
  D --> A["Act<br/>(call a tool)"]
  A --> O["Observe<br/>(tool result)"]
  O --> D
  D --> F["Finish<br/>(final answer)"]

The agent loop: decide, act, observe, repeat, until the decision is to finish.

The word "agentic" describes a spectrum rather than a yes or no. A prompt that asks the model one question is at the low end. A system that plans, uses a dozen tools, checks its own work and runs for an hour is at the high end. In between are many useful designs, and you will meet them in the coming lessons.

The simplest agent: a thermostat

You do not need a model to see the loop. A thermostat perceives a temperature, decides whether the room is too cold, and acts by switching a heater. Then the world changes and it perceives again.

Python A thermostat is an agent

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the output and find the three phases in the code. The program never ends with "the answer". It keeps the world near a goal. Many real agents are like this: they monitor and react. Others, like a coding agent, run until a task is finished.

An agent that needs a decision each step

A thermostat has a fixed decision rule. A language-model agent replaces decide with a call to the model: you describe the goal and the situation in text, and the model returns the next action. The surrounding code stays almost the same.

Here is a toy task: reach a target number starting from 1 using only two tools, add_three and double. The fake_llm function below is a stand-in that plays the model with a simple rule. In a real agent this function would be an API call.

Python Stand-in: a tiny goal-driven agent

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice three details that will matter later:

  • The loop has a step limit. An agent that can loop must be stopped by something other than hope. The loop-control lessons cover this properly.
  • The decision comes back as text ("double"). The program must check that text before running anything. Tool calling formalizes this.
  • The agent keeps a history. Real models are stateless, so the program has to carry the memory. See agent state and messages.

Where agents are useful

Agents shine when the path to the goal is not known in advance, the task involves several systems, and a mistake is cheap to detect or undo. Typical examples are fixing a failing test in a codebase, researching a question across many documents, triaging support tickets, and filling in data across several spreadsheets.

They are a poor fit when a fixed sequence of steps would do (a normal program is faster, cheaper and predictable), or when one wrong action is costly and cannot be reversed. Use cases and limits walks through the decision.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which set of ingredients makes a system an agent rather than a one-shot chatbot?

    An agent pursues a multi-step goal, can act through tools, and uses each result to decide the next step.
  2. 2. In the thermostat example, which function plays the role that an LLM plays in a language-model agent?

    decide turns the current situation into the next action. A language-model agent asks the model to do exactly that.
  3. 3. Why does the toy agent have a max_steps limit?

    Without a limit, a confused agent can loop indefinitely and waste time and money.
  4. 4. Which task is the best candidate for an agent?

    The path is unknown in advance, needs several tools, and the result (tests pass) is easy to verify.

Summary

  • An agent pursues a goal through a loop of deciding, acting and observing.
  • Tools let it change the world; the loop lets each result steer the next step.
  • Agentic is a spectrum, from one prompt to long autonomous runs.
  • The decision step can be rules or an LLM; the surrounding program stays similar.
  • Always bound the loop and validate what the decision step returns.

Next: LLMs as the Agent's Brain