Please enable JavaScript to use CodeHS

Agent Tutorial

What are AI agents?

An AI agent is more than a chatbot. It is an LLM that can think, use tools, remember what happened, and take actions to reach a goal.

AI ~10 min Beginner friendly
The Big Idea

What is an AI agent?

A basic chatbot waits for you to ask a question and then answers in text. An AI agent goes further. It has a goal, makes a plan, uses tools, and keeps working until the job is done.

Think of the difference like this: a chatbot is a helpful librarian who answers questions. An agent is a helpful assistant who can look up the book, photocopy the pages, email them to you, and put a reminder on your calendar.

🧠

Brain

An LLM that reasons, plans, and writes text.

🛠️

Tools

Functions the agent can call, like search, email, or a calculator.

📝

Memory

A place to store facts about the task and past actions.

🎯

Goal

The job the agent is trying to finish.


The Loop

The agent loop

Most agents follow a loop:

  1. Think: What do I need to do next?
  2. Act: Use a tool or take an action.
  3. Observe: What happened? What did I learn?
  4. Repeat: Go back to step 1 until the goal is reached.

This loop lets the agent handle complex tasks that have many steps. It is like a student solving a word problem: read, plan, try, check, adjust.

Key idea: the agent uses the LLM to decide what to do, but it uses tools to actually do things in the world.


Interactive

Plan with an agent

Choose a goal and click Next step to watch the agent think, act, and observe. See how it uses different tools along the way.


Tools

Tools and memory

Tools are what make an agent useful. A tool is just a function the agent can call. Common tools include:

  • Search: look up current facts on the web.
  • Calculator: do math accurately.
  • Email / message: send information to a person.
  • Code runner: write and run a small program.
  • Database: save or read records.

Memory keeps track of what the agent has already done. Without memory, the agent would forget the plan halfway through. With memory, it can handle long, multi-step tasks.

Watch out: giving an agent access to powerful tools also means it can make bigger mistakes. That is why agent safety and human oversight matter.


Code

A simple agent loop

An agent repeats the same basic cycle: think, act, observe. This Python agent decides which tool to call based on a keyword in the user's request.


Your Turn

Check yourself

Think of a task you do every week, like planning a weekend trip or doing a homework assignment. Name one tool an AI agent could use to help, and one thing it would need to remember during the task.

Example: For planning a trip, the agent could use a map tool to find routes and a calendar tool to check dates. It would need to remember your budget and the number of travelers.


Check Yourself

Quick quiz

1. What makes an AI agent different from a basic chatbot?

2. Which of these is an example of an agent tool?

3. Why does an agent need memory?

Keep learning about AI

Agents can use many tools, but one of the most powerful is the ability to write code. Next, see how coding agents work.

Part of the “Are LLMs smarter than a 5th grader?” tutorial series.