hands-on guide to AI agents

Build an agent that
thinks, acts,
and learns.

From zero to your first autonomous AI — step by step. No fluff, just the concepts that matter and the code to prove it.

agent.py
# The agentic loop — the heart of every agent
while True:
    response = client.messages.create(
        model="claude-sonnet-4-5",
        tools=tools,
        messages=messages
    )

    if response.stop_reason == "tool_use":
        result = run_tool(response)
        messages.append(result)
    else:
        print(response.content)
        break

$ python agent.py
→ Searching for AI news...
→ Summarising 12 articles...
✓ Done in 4 steps.
5
Progressive challenges
4
Core concepts covered
1
Agent you'll own by the end

An LLM answers. An agent acts.

You've used ChatGPT. An LLM gives you one answer. An agent has goals, tools, and the ability to keep going until the job is done.

Plain LLM

One shot, one answer

You send a message. It sends one back. No memory of what came before, no tools, no way to act on the world.

Input Model Output
AI Agent

Goals, tools, and loops

You give it a goal. It plans, calls tools, observes results, and decides whether it's done. Many steps, not one.

Goal Think Act Observe
↻ loops until done

Four things every agent is made of.

No matter how complex an agent gets, it is always built from the same four pieces. Click each one to expand.

01

Tools

how it touches the world

+

Tools are functions the agent can call — web search, a calculator, a database query, an API. Without tools, an agent is just a chatbot with ambition. Tools give it the ability to act.

tool: web_search("AAPL price")
returns: { price: 189.42, change: "+1.2%" }
02

Memory

what it holds onto

+

Memory is the growing conversation history — every tool call, every result, every decision — passed back in on each step. This is how the agent knows what it already tried.

messages: [
  { role: "user", content: "research X" },
  { role: "tool", result: ... } ← appended
]
03

Planning

how it decides what's next

+

Planning is the model reasoning about what to do next. In powerful agents you make it explicit — prompting the model to write a plan before it acts.

system: "Before acting, write your plan."
think: "Search first, then summarise."
04

The loop

what makes it autonomous

+

The loop is your runner — code that keeps calling the model until it decides it's done. Tool call? Run it and loop. Final answer? Stop. This is the engine of every agent.

while not done:
  resp = model(messages)
  if resp.tool_call: loop
  else: done = True

The agentic loop, walked through.

Exactly what happens from the moment you give an agent a goal to the moment it returns an answer.


What a minimal agent actually looks like.

This is the whole pattern. Every challenge builds a more capable version of exactly this.

agent.py
# 1. Define what tools the agent can use
tools = [{
  "name": "web_search",
  "description": "Search the web for current information",
  "parameters": { "query": { "type": "string" } }
}]

# 2. Seed memory with the user's goal
messages = [{ "role": "user", "content": "Summarise today's AI news" }]

# 3. The loop
while True:
    response = client.messages.create(
        model="claude-sonnet-4-5",
        tools=tools,
        messages=messages
    )
    if response.stop_reason == "tool_use":
        result = run_tool(response.tool_call)
        messages.append(response)      # agent's turn
        messages.append(result)         # tool result
    else:
        print(response.content)        # final answer
        break

Now build it.

Five challenges. Each one adds a capability to a single agent you will own by the end.

#
Challenge
Difficulty
Points
01
Your first tool
Give your agent the ability to search the web
Easy
100 pts
02
Tool chaining
Add a second tool and teach it to decide
Easy
150 pts
🔒 Locked
03
Memory
Give your agent context that persists
Medium
200 pts
🔒 Locked
04
Planning loop
Make your agent reason before it acts
Medium
250 pts
🔒 Locked
05
Error handling
Teach it to recover when things go wrong
Hard
300 pts
🔒 Locked

Ready to start building?

Sign in with Google to track your progress and unlock challenges as you go.

Start Challenge 1 →