Build Your First AI Agent · Lesson 1 of 8
Lesson 1 — What an agent actually is
45 minutes. The mental model, before we write code.
---
A chatbot takes input, produces output, then waits for the next input. It has no memory of last conversation, no ability to act on its own, no access to anything beyond what you paste in.
An agent is different in three specific ways:
- It uses tools. When it doesn't know something, it can call out — read a file, query a database, send an HTTP request — to get the info. The model itself can decide *when* to call a tool and *which* tool to call.
- It runs multi-step. "Read the inbox → match each email to a customer → draft a reply per customer → log results" is one task. The agent decides what step comes next based on what the previous step returned.
- It maintains state. Across steps within one task. Sometimes across sessions, too.
Every agent — Claude's, OpenAI's, Anthropic's customer-built ones, the one you're about to build — runs the same loop:
```
- User gives task
- Model thinks → either responds OR requests a tool call
- If tool call: run the tool, capture result
- Send tool result back to model
- Model thinks again → respond OR request another tool call
- Repeat until model responds with a final answer
```
That loop is *the* core of agent engineering. Everything else — memory, state, errors, approvals — is layered on top.
For a real-world business agent, here are the building-block tools you'll define:
- Read — read a file, an email, a database row
- Search — find matching records, search the web
- Write — create a draft, log a record
- Send — actually transmit something (email, message)
- Wait/escalate — ask a human before proceeding
Note the asymmetry: Read and Search and Write are safe to give the agent. Send is dangerous. Most real-world agent designs put a human approval in front of any "send" tool. That's the approval gate we'll build in Lesson 7.
By the end of the 8 lessons, you'll have:
- An agent that reads a shared mailbox
- For each new customer email, drafts a reply using a custom prompt
- Looks up the customer in your CRM (or a local SQLite, if you don't have a CRM)
- Drafts a follow-up scheduling suggestion
- Logs the proposed action to an audit table
- Waits for human approval before sending
It's a small, useful, real-world agent. Once you can build one like this, you can build any number of variants.
Before the next lesson, install Node.js (v20+), set up a directory for the course, install `@anthropic-ai/sdk`, and get an Anthropic API key from console.anthropic.com.
```bash mkdir my-first-agent cd my-first-agent npm init -y npm install @anthropic-ai/sdk echo 'ANTHROPIC_API_KEY=sk-ant-...' > .env ```
When `node -e "console.log(process.env)"` shows the key (with `dotenv` loaded), you're ready.
→ Lesson 2 — Tools and tool definitions