Module 1 of 6 · 40 minutes

What makes an AI agent

'Agent' is the most hyped word in AI. This module gives you precise definitions — and the judgement to know when an agent is the right tool.

By · Last updated

Learning objectives

  • Define workflows and agents
  • Describe the augmented LLM building block
  • Decide when an agent is justified
  • Place systems on an autonomy spectrum
  • See in code who chooses the next step in a workflow and in an agent
  • Estimate how token use grows with the number of steps
Running the code — and practice mode

Every code block in this course is a live cell: press Run and it runs in your browser, and you can edit it and run it again. A real LLM needs a secret API key, and a key must never sit in a web page. So on these pages the cells talk to a small pretend model built into the page. It can ask for tools, read their results and reply, which is everything an agent loop needs. The code is what you'd write for the real thing (it uses Anthropic's Python SDK; OpenAI, Google and Microsoft SDKs follow the same pattern with different field names). The pretend model's decisions come from simple word-matching rules, not real AI, so it is far more predictable than a real model. To use a real one, copy the code into a notebook such as Google Colab and add your own key (see Python for AI, Module 5).

1.1 From chatbots to agents

A chatbot answers. An agent pursues a goal: it decides what to do next, uses tools — search, code, files, APIs — observes the results, and keeps going until the job is done or it needs help.

Anthropic's widely cited guide Building effective agents (December 2024) draws a useful line between two kinds of "agentic system":

Workflows

LLMs and tools orchestrated through predefined code paths. You decide the steps; the LLM does the work inside each step. Predictable and easier to test.

Agents

LLMs that dynamically direct their own processes and tool usage, typically in a loop guided by feedback from the environment. Flexible, but less predictable and more expensive.

Workflowyour code decides the pathStep 1(LLM)Step 2(LLM)Step 3(LLM)Agentthe LLM decides the pathLLM decidesnext actionTool ATool BDone?observepredictable · easy to testcheaper · less flexible
Workflows follow a path you design; agents choose their own next step in a loop. Both use the same building blocks.

1.2 The building block: an augmented LLM

Every agentic system starts with an LLM augmented with three capabilities:

  • Tools — functions it can call to fetch information or take actions (Module 2).
  • Retrieval — access to knowledge, for example through RAG (see the RAG course).
  • Memory — information carried across steps or sessions (Module 4).
LLMToolssearch, code, APIsRetrievalyour documentsMemorystate across steps
The augmented LLM: the building block of every agentic system.

1.3 When to use an agent — and when not to

The most important design advice from practitioners is: start with the simplest thing that works. Often that's a single well-prompted LLM call with retrieval. Add workflows when a task splits naturally into fixed steps. Reach for an autonomous agent only when:

  • the steps can't be predicted in advance (open-ended problems);
  • the task benefits from trying, observing and adjusting;
  • success can be checked (tests pass, data reconciles, the user confirms);
  • the extra cost, latency and risk are worth it.

Coding agents are a strong fit: the steps are open-ended, but tests give clear feedback. A refund-approval process with fixed rules is a poor fit: a workflow is safer and cheaper.

1.4 The autonomy spectrum

LevelWhat the AI doesExample
1. AssistantSuggests; a human does everythingDrafts an email reply
2. WorkflowExecutes fixed steps you designedClassify ticket → retrieve policy → draft reply
3. Supervised agentPlans and acts; a human approves key actionsResearches and prepares a refund, waits for approval
4. Autonomous agentPlans and acts within boundaries, reports backFixes failing tests in a sandbox and opens a pull request

Move up the ladder only as far as the task needs and your safeguards allow.

1.5 The difference, in code

The definitions become concrete once you see who chooses the next step. First a workflow. The two steps and their order are written in Python; the model only fills them in:

Python · a workflow: the path is fixed in codeimport anthropic, json
client = anthropic.Anthropic()          # the real SDK reads ANTHROPIC_API_KEY from the environment
MODEL = "YOUR-MODEL-NAME"               # copy a current model name from your provider's docs

def call_llm(prompt):                   # thin wrapper: one prompt in, text out
    r = client.messages.create(model=MODEL, max_tokens=400,
                               messages=[{"role": "user", "content": prompt}])
    return r.content[0].text.strip()

def workflow(msg):                      # YOUR code decides the steps: classify, then reply
    category = call_llm("Classify this customer message as REFUND, TECHNICAL or OTHER. "
                        f"Reply with one word only.\n\nMessage: {msg}")
    if category == "REFUND":
        reply = call_llm("You handle refund requests. Policy: damaged items can be refunded "
                         f"within 30 days. Draft a reply to: {msg}")
    else:
        reply = call_llm(f"Politely answer or redirect this general enquiry: {msg}")
    return category, reply

category, reply = workflow("My board arrived cracked and I'd like my money back")
print(category)
print(reply)

Now the other kind. Here the model is handed a list of tools and a message, and it chooses what happens next. Nothing in the Python says which tool goes with which message:

Python · the model chooses the next steptools = [
    {"name": "get_order_status", "description": "Look up the delivery status of an order.",
     "input_schema": {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]}},
    {"name": "issue_refund", "description": "Refund money to the customer for an order.",
     "input_schema": {"type": "object", "properties": {"order_id": {"type": "string"}, "amount": {"type": "number"}},
                      "required": ["order_id", "amount"]}},
]

for msg in ["Where is my order GFY-10422?",
            "Please refund £12 for order GFY-10423",
            "Where is my order?"]:
    r = client.messages.create(model=MODEL, max_tokens=500, tools=tools,
                               messages=[{"role": "user", "content": msg}])
    block = r.content[0]
    if r.stop_reason == "tool_use":
        print(f"{msg!r}\n   model asks for: {block.name}({block.input})")
    else:
        print(f"{msg!r}\n   model replies:  {block.text}")

Three messages, three different next steps, and the third was a question back to the customer because the order number was missing. That choice is the whole difference: in a workflow your code holds the steering wheel, in an agent the model does. Notice too that the model only asked for a tool. Nothing has been looked up or refunded yet; Module 2 covers who actually runs it.

1.6 What autonomy costs

An agent works in a loop, and on every turn of the loop the whole conversation so far is sent again: the instructions, the tool definitions, and every earlier tool call and result. So the tokens you pay for grow faster than the number of steps. The arithmetic is worth running once:

Python · tokens sent by a ten-step agentbase = 1200        # tokens sent on step 1: system prompt + tool definitions + the goal
per_step = 400     # tokens each step adds: the model's tool request + the tool's result

total = 0
for step in range(1, 11):
    sent = base + per_step * (step - 1)
    total += sent
    if step in (1, 2, 5, 10):
        print(f"step {step:2}: sends {sent:5,} tokens   running total {total:6,}")

print(f"\nA single call would have sent {base:,} tokens. Ten steps sent {total / base:.0f} times as much.")

Ten steps cost 25 times one call here, not ten times, because later steps carry everything that came before. Change per_step to 2000 (a tool that returns a long web page) and run it again. This is why Module 4 spends time on keeping context small, and why "could a workflow do this?" is always the first question. Providers' prompt caching discounts the repeated part, which softens the bill but not the latency of ten round trips.

1.7 Where agents are today

Three kinds of agent are in everyday use: coding agents that edit a codebase and run its tests, research agents that plan many searches and write a cited report, and computer-use agents that operate a browser or desktop by looking at the screen. All three are the same loop you will build in Module 4, with different tools attached.

The plumbing has also standardised. The Model Context Protocol, which connects agents to tools (Module 2), was donated by Anthropic to the Linux Foundation's Agentic AI Foundation in December 2025, alongside contributions from OpenAI and Block. Google's Agent2Agent protocol (A2A), which lets separately built agents talk to each other, has been a Linux Foundation project since June 2025. For you this means tools and agents built to these standards are not tied to one vendor.

Exercise: workflow or agent?

Turn the checklist from section 1.3 into a function. recommend(task) takes a dictionary of four yes/no answers and returns "agent" only if the steps are unpredictable and success can be checked and the cost is worth it; otherwise "workflow". Try it on both tasks.

Your turnfix_tests   = {"steps_unpredictable": True,  "success_checkable": True,  "worth_the_cost": True}
refund_rule = {"steps_unpredictable": False, "success_checkable": True,  "worth_the_cost": False}

def recommend(task):
    ...   # return "agent" or "workflow"

print("Fix failing tests ->", recommend(fix_tests))
print("Approve refunds   ->", recommend(refund_rule))
Show a solution
fix_tests   = {"steps_unpredictable": True,  "success_checkable": True,  "worth_the_cost": True}
refund_rule = {"steps_unpredictable": False, "success_checkable": True,  "worth_the_cost": False}

def recommend(task):
    if task["steps_unpredictable"] and task["success_checkable"] and task["worth_the_cost"]:
        return "agent"
    return "workflow"

print("Fix failing tests ->", recommend(fix_tests))
print("Approve refunds   ->", recommend(refund_rule))
Exercise: find the budget limit

Your budget is 60,000 tokens per task. With 1,200 base tokens and 400 added per step, what is the largest number of steps an agent can take before the running total goes over budget? Use a loop.

Your turnbase, per_step, budget = 1200, 400, 60_000

# Add up the tokens step by step and stop before the total passes the budget
Show a solution
base, per_step, budget = 1200, 400, 60_000

total, step = 0, 0
while True:
    sent = base + per_step * step          # step 0 is the first call
    if total + sent > budget:
        break
    total += sent
    step += 1

print(f"{step} steps fit in the budget, using {total:,} tokens")

Key takeaways

  • Workflows follow predefined code paths; agents direct their own steps and tool use.
  • Agents are built from an LLM augmented with tools, retrieval and memory.
  • Start simple; use agents for open-ended tasks with checkable success.
  • Move up the autonomy ladder only as far as needed and as safeguards allow.
  • In a workflow your code chooses the next step; in an agent the model does.
  • Every step resends the whole conversation, so token cost grows faster than the step count.