← Back to Table of Contents

Chapter 1 β€” What Are Agents?

β€œAn agent is anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators.” β€” Stuart Russell & Peter Norvig, Artificial Intelligence: A Modern Approach

The Big Idea

An AI agent is a system that uses a large language model (LLM) as its reasoning engine to autonomously decide what actions to take in order to accomplish a goal. Unlike a chatbot that simply responds to prompts, an agent can observe, reason, act, and iterate β€” without human intervention at each step.

Chatbot vs. Agent
πŸ’¬ Traditional LLM (Chatbot)
  • Receives a prompt
  • Generates a response
  • Done β€” waits for next prompt
  • No memory across turns (unless managed)
  • Cannot take actions in the world
πŸ€– AI Agent
  • Receives a goal
  • Plans steps to achieve the goal
  • Uses tools (search, code, APIs)
  • Observes results and adapts
  • Loops until the goal is met

The Spectrum of Agency

Not every system is either a plain LLM or a fully autonomous agent. There’s a spectrum:

The Agency Spectrum
🌟 Fully Autonomous Agent Self-directed goal pursuit, minimal human oversight
πŸ”„ Agentic Workflow Multi-step reasoning with tool use, human checkpoint gates
πŸ”§ Augmented LLM LLM + function calling / RAG β€” single tool use per turn
πŸ“ Prompted LLM Chain-of-thought, few-shot β€” still just text in, text out
πŸ’¬ Basic LLM Single prompt β†’ single completion

Most production systems today operate in the middle β€” agentic workflows β€” rather than at the fully autonomous extreme. The sweet spot is giving the LLM enough autonomy to be useful while keeping humans in the loop for critical decisions.

When to Use Agents (and When Not To)

Use Agents When… Stick with Plain LLMs When…
The task requires multiple steps and tool use The task is a single-turn Q&A
The output depends on external information (APIs, databases, web) All information is in the prompt/context
You need adaptive behavior β€” the next step depends on what happened The pipeline is deterministic and fixed
The task involves creating + validating (write code β†’ run tests β†’ fix) Simple generation (summarize, translate)
There are too many possible paths to hardcode A simple if/else pipeline works

A Minimal Agent in Code

Here’s the simplest possible agent pattern in Python β€” a loop that thinks and acts:

from openai import OpenAI

client = OpenAI()
tools = [...]  # tool definitions

messages = [{"role": "user", "content": "Find the weather in Tokyo and suggest what to wear"}]

# The agent loop
while True:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=messages,
        tools=tools,
    )
    
    message = response.choices[0].message
    messages.append(message)
    
    # If the model wants to use a tool β†’ execute it and continue
    if message.tool_calls:
        for tool_call in message.tool_calls:
            result = execute_tool(tool_call)  # your function
            messages.append({
                "role": "tool",
                "tool_call_id": tool_call.id,
                "content": result,
            })
    else:
        # No tool calls β†’ the agent is done
        print(message.content)
        break

That’s it. The essence of every agent is this loop: call the LLM β†’ if it wants to act, execute the action β†’ feed the result back β†’ repeat. Everything else (memory, planning, multi-agent orchestration) builds on this foundation.

Key Terminology

Term Definition
Agent A system that uses an LLM to autonomously decide actions toward a goal
Tool An external function the agent can invoke (search, calculator, API call)
Agent Loop The observe β†’ think β†’ act cycle that drives agent behavior
Agentic Workflow A multi-step pipeline where the LLM makes routing/action decisions
Function Calling The LLM’s ability to output structured tool invocations instead of text
Grounding Connecting the agent to real-world data sources (search, databases)
Guardrails Safety constraints that limit what an agent can do

What’s Next

Now that you know what agents are and when to use them, let’s look at how we got here β€” the research and ideas that led to the current agent paradigm.

Next: Chapter 2 β€” History & Evolution β†’


Last updated: April 2026