Part 1 · Foundations: The World of AI Agents

Chapter 1What Is an AI Agent? From Chatbots to Autonomous Systems

We begin with the single most important idea in the book: what actually separates an *agent* from a plain chatbot or a script. By the end of this chapter you will be able to look at any AI product and say whether it is agentic, and why.

A definition you can actually use

An AI agent is a system that uses a language model as its reasoning engine to decide which actions to take, takes those actions using tools, observes the results, and repeats until a goal is met. The key words are decide, act, and observe. A chatbot answers; an agent acts.

Compare two systems. The first takes your question and returns text. The second takes your goal — "book me the cheapest flight to Lyon next Friday" — then searches, compares, fills a form, and reports back. Only the second one chooses its own steps. That capacity to choose is the heart of agency.

The agent loop

Almost every agent, no matter how advanced, runs some version of the same cycle. We will return to this loop in every chapter, so it is worth memorizing now.

  1. Perceive — read the goal and any new information from the environment.
  2. Reason — decide what to do next (often "call a tool" or "give the final answer").
  3. Act — execute the chosen action, such as running a search or calling an API.
  4. Observe — read the result of the action.
  5. Repeat — feed the observation back in and loop until the goal is done.
Figure 1.1 — The core agent loop: Perceive → Reason → Act → Observe, repeating until the goal is satisfied.
Figure 1.1 — The core agent loop: Perceive → Reason → Act → Observe, repeating until the goal is satisfied.

A first taste in code

Here is the smallest possible "agent" — a loop that lets the model choose between answering directly or calling a calculator tool. Do not worry about every detail yet; just notice the loop and the decision.

python
def tiny_agent(goal):
    history = [{"role": "user", "content": goal}]
    while True:
        decision = model_choose_action(history)   # reason
        if decision.type == "final_answer":
            return decision.text                   # done
        result = run_tool(decision.tool, decision.args)  # act
        history.append({"role": "tool", "content": result})  # observe
Practice

Exercises

  1. 1In your own words, write a two-sentence definition of an AI agent and one sentence explaining how it differs from a chatbot.
  2. 2List three apps or products you have used recently. For each, decide whether it is agentic, and justify your answer using the 'decide / act / observe' test.
  3. 3Sketch (on paper) the agent loop for a system whose goal is 'find and summarize the three most-cited papers on a topic'. Name the tools it would need.
  4. 4Identify one task in your own daily life that an agent could automate. Describe the goal, the tools required, and what 'done' looks like.
View detailed solutions for all chapters →