Building AI AgentsA Complete Guide from Zero
Plain-language referenceEditor · Brain · Agent · Frameworks

Building AI Agents


A complete, plain-language guide from zero — the developer's workshop, how the model thinks, and the leap from chatbot to autonomous agent.

Every technical term is defined the first time it appears, in plain words, often with an analogy. Wherever a word is industry shorthand, the plain meaning comes first and the buzzword second. Diagrams are redrawn as flowcharts; code snippets are short and illustrative — meant to show you what things look like, not full tutorials.

8 Parts 18 Diagrams Glossary No prior knowledge assumed

How to read this guide

The guide moves in a deliberate order. Each part assumes the one before it — read straight through the first time, then use it as a reference.

01The Developer Toolkit — the workshop you build in
02Tech Stacks — what you build software with
03How the Brain Works — LLMs, tokens, embeddings
04From Chatbot to Agent — the leap to something that acts
05Making an Agent Intelligent — planning, reliability
06Frameworks — LangChain, LangGraph, Claude Agent SDK
07Multi-Agent Systems & Deep Agents
08Putting It Together — first project, deploy, cost, security

Part 01The Developer Toolkit

Before you build anything, you set up a workshop. These are the tools every software project uses, agents included — the basics of how you write, save, and share code.

1.1  What a code editor is, and why VS Code

PlainA code editor is a text editor built specifically for writing code. It's like Microsoft Word, but instead of helping you write essays it helps you write instructions for a computer — coloring your code so mistakes stand out, auto-completing words, and flagging errors before you run anything.

VS Code (Visual Studio Code) is the most popular free code editor in the world, made by Microsoft. People use it because:

  • It works on Windows, Mac, and Linux.
  • It has extensions — small add-ons that teach the editor new tricks (e.g. one that understands Python, or one that connects to AI assistants).
  • It has a built-in terminal, so you can write and run code in the same window.
Analogy

Think of VS Code as a fully equipped kitchen. The stove, knives, and counters are all there. Extensions are like specialized appliances — a pasta maker, an ice-cream churn — you add when a recipe needs them.

When people say IDE (Integrated Development Environment), they mean a code editor with extra built-in tooling for running and debugging programs. VS Code sits between a plain editor and a full IDE — light by default, powerful once you add extensions.

1.2  The terminal (command line) in plain terms

PlainThe terminal is a text-based way to give your computer commands by typing them instead of clicking icons. You type a command, press Enter, and the computer does it.

You've always controlled your computer through a GUI (Graphical User Interface — the windows, icons, and buttons you click). The terminal is the older, text-only alternative — a CLI (Command Line Interface). Developers use it because it's faster and more precise for many tasks, and most programming tools are designed to be controlled this way. A few commands you'll see constantly:

Terminal
cd my-project        # "change directory" — move into a folder
ls                   # "list" — show what's in the folder (dir on Windows)
mkdir agent-app      # "make directory" — create a new folder
python app.py        # run the Python program named app.py
Analogy

The GUI is ordering food by pointing at pictures on a menu. The terminal is telling the chef exactly what you want in words. Slower to learn, but you can order anything, precisely.

1.3  Version control — what git actually does

The problem it solves: you've all done this — report_final.doc, report_final_v2.doc, report_final_ACTUALLY_final.doc. Now imagine that with thousands of files and five people editing at once. Chaos.

PlainGit is a tool that takes snapshots of your project over time, so you can see exactly what changed, when, and by whom — and rewind to any earlier snapshot if you break something. Each snapshot is called a commit: a saved checkpoint with a short message describing what you did (“added login feature,” “fixed crash on empty input”). The core loop looks like this:

Edit filesin your editor git addstage your changes git commitsave a checkpoint git pushupload to GitHub
↻  then back to editing — repeat for every change
Fig. 01The git workflow loop — edit, stage, commit, push, repeat.

Key terms, all defined:

  • Repository (repo): the project folder git is tracking. It holds your files plus the full history of every commit.
  • Commit: one saved checkpoint.
  • Branch: a parallel copy of your project where you can try something risky without touching the working version. If it works, you merge it back in; if not, you throw the branch away. The main, trusted version usually lives on a branch called main.
  • Merge: combining the changes from one branch into another.
Analogy

Git is a video game with unlimited save slots. A commit is a save point. A branch is starting a “what if” playthrough from a save without overwriting your main game. Merge is importing the good stuff from the experiment back into your main save.

1.4  GitHub vs git — the difference, and why it matters

This trips up almost everyone at first, so let's be precise.

  • Git is the tool that runs on your computer and tracks history. It works completely offline.
  • GitHub is a website (owned by Microsoft) where you store a copy of your git repository in the cloud so others can see it, collaborate, and where the world can find open-source code. (GitLab and Bitbucket are competitors that do the same thing.)
Analogy

Git is the camera that takes the photos. GitHub is the shared photo album in the cloud where the family can all view and add pictures.

Why it matters for agents specifically: almost every agent framework and tool lives on GitHub — you'll go there constantly to read docs, report bugs, and copy starter projects. Cloning a repo (git clone <url>) downloads someone's project to your machine so you can run it; this is how you'll start most experiments. A pull request (PR) is a proposal to merge your changes into someone else's project — the heart of collaboration.

The GitHub CLI (gh) lets you do GitHub things — create repositories, push code, open pull requests — by typing commands instead of clicking around the website. Its biggest convenience is painless sign-in: gh auth login opens your browser, you click “authorize,” and you're done. Once it's set up, putting a brand-new project online is three commands:

Terminal
git init                                # start tracking this folder
git add . && git commit -m "Initial commit"     # save a first checkpoint
gh repo create my-project --public --source=. --push   # create + upload

1.5  Environments and packages — why “it works on my machine” happens

The problem: your project depends on dozens of pieces of code written by other people — packages or libraries. Project A might need version 1 of a library; Project B might need version 2. If you install everything globally, they collide.

  • Package / library: pre-written code you install and use, so you don't reinvent the wheel. Example: requests (fetching web pages), langchain (building agents).
  • Package manager: the tool that downloads and installs packages. In Python it's pip; in JavaScript it's npm.
  • Virtual environment: an isolated bubble for one project, with its own private set of packages and versions, so projects don't interfere with each other.

A typical Python setup, with every line explained:

Terminal · Python
python -m venv .venv          # create a private bubble for this project
source .venv/bin/activate     # step inside it (Windows: .venv\Scripts\activate)
pip install langchain anthropic   # install packages — only inside this bubble
Analogy

A virtual environment is a separate toolbox for each job. Project A's toolbox has a 1-inch wrench; Project B's has a 2-inch wrench. They never get mixed up, because each job carries its own box.

You'll also hear about API keys here. An API key is a secret password that proves you're allowed to use a paid service (like Claude's or OpenAI's models). You store it in a hidden file (usually .env) and never put it on GitHub — leaking a key lets strangers spend your money.

.env · never committed
# .env file — kept secret, never committed to git
ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxx

Part 02Tech Stacks

What you build different kinds of software with — and where an agent actually lives in the picture.

2.1  What “tech stack” means

PlainA tech stack is the full set of technologies — languages, frameworks, databases, and services — you combine to build a particular piece of software. “Stack” because the pieces layer on top of one another. There's no single “correct” stack; you pick tools that fit the job, the same way you'd pick different vehicles for a city commute vs. hauling furniture.

2.2  Front-end, back-end, database — the restaurant analogy

Most software that people interact with has three layers:

User clicks, types Front-endwhat you see requests Back-endthe logic & rules reads / writes Databasestored info
Fig. 02The three layers of most software — dining room, kitchen, pantry.
  • Front-end: everything the user sees and touches. Built with HTML, CSS, and JavaScript, often using a framework like React. (The dining room: menus, tables, decor.)
  • Back-end: the hidden logic that processes requests, enforces rules, and talks to the database. Built in Python, JavaScript (Node.js), Java, Go. (The kitchen: where orders are cooked.)
  • Database: where information is stored permanently — users, messages, orders. (The pantry and walk-in fridge.)
Where agents live

An AI agent is almost always back-end logic. It receives a request, thinks, calls tools, and returns an answer. It may have a simple front-end (a chat window), but the intelligence is back-end. This is why Python dominates agent work — it's a back-end language with the richest AI ecosystem.

2.3  Databases — SQL vs the rest

Two broad families, defined simply:

  • SQL databases (relational): store data in tables with rows and columns, like linked spreadsheets. Strict structure. Examples: PostgreSQL, MySQL, SQLite. SQL (Structured Query Language) is the language you use to ask them questions.
  • NoSQL databases: more flexible — store data as documents or key-value pairs without a rigid table structure. Examples: MongoDB, Redis.

For agents you'll also meet a special kind:

  • Vector database: stores the meaning of text as lists of numbers (explained in Part 3 under embeddings). It lets an agent find information by similarity of meaning rather than exact keyword match. Examples: Pinecone, Chroma, Weaviate, pgvector. This is the backbone of letting an agent “read your documents.”

2.4  Typical stacks by project type

Project typeTypical stackWhy
Simple websiteHTML + CSS + JavaScriptNo logic or storage needed
Web app (SaaS tool)React + Node.js or Python + PostgreSQLStandard, well-supported combo
Data / ML projectPython + pandas + Jupyter notebooksPython's data libraries are unmatched
AI agentPython + an LLM API + a framework + a vector DBThe agent-building default
Automation scriptPython alone, or a no-code toolOften just a single file

2.5  Where Python fits and why it dominates AI

Python is a programming language designed to be readable — its code looks almost like English. It won the AI world for three reasons:

  • The libraries are there. Nearly every AI tool — PyTorch, TensorFlow, LangChain, the official Claude and OpenAI SDKs — is built for Python first.
  • It's beginner-friendly. Less punctuation and ceremony than Java or C++, so you focus on ideas, not syntax.
  • The community is huge. Almost any error you hit has already been answered somewhere online.

A complete, runnable example of talking to Claude — note how readable it is:

Python
import anthropic                     # the official Claude library
client = anthropic.Anthropic()       # connects using your secret API key
message = client.messages.create(
    model="claude-sonnet-4-5",       # which model to use
    max_tokens=300,                  # cap on how long the reply can be
    messages=[
        {"role": "user", "content": "Explain what an API is in one sentence."}
    ],
)
print(message.content[0].text)       # show Claude's answer

That's the entire skeleton of every AI app: connect, send messages, read the reply. Everything else in this guide is about making what happens between “send” and “reply” smarter.

Part 03How the Brain Works

This is the engine inside every agent — LLMs from the ground up. Understand this part well and the rest clicks into place.

3.1  Neural networks, explained without math

PlainA neural network is a computer program loosely inspired by how brain cells connect. It's a giant web of simple math units (“neurons”) arranged in layers. Each connection has a weight — a number that says how strongly one unit influences the next. The only idea you really need: a neural network is a machine that learns patterns from examples by adjusting those weights. You don't program the rules; you show it millions of examples and it figures out the rules itself.

InputInput Output
input layer  →  hidden layers (weighted connections)  →  output
Fig. 03A neural network — simple units in layers, learning by tuning the weights between them.
Analogy

Teaching a child to recognize dogs. You don't list rules (“four legs, fur, tail”). You point at hundreds of dogs and say “dog.” Eventually the child generalizes. A neural network does this with numbers: it sees an example, guesses, checks how wrong it was, and nudges its weights to be a little less wrong next time. Repeat billions of times.

The process of nudging weights to reduce error is called training. The “how wrong was I” measurement is the loss, and the nudging method is backpropagation — you don't need the mechanics, just the intuition: guess, measure error, adjust, repeat.

3.2  What an LLM is and how it “predicts”

LLM stands for Large Language Model. Break it down: Language — it works with text. Model — it's a neural network (a trained pattern-machine). Large — it's enormous: trained on a huge chunk of the internet, books, and code, with hundreds of billions of weights.

What it actually does, at its core: an LLM predicts the next chunk of text, over and over. Given “The capital of France is,” it computes that “Paris” is the most likely next word and outputs it — then does it again, now including “Paris,” to predict what comes after. That's it. Everything impressive — answering questions, writing code, reasoning — emerges from doing next-word prediction extremely well at massive scale.

Analogy

It's autocomplete on your phone, but trained on essentially all written human knowledge and scaled up a billionfold. Your phone suggests one word; an LLM can continue for pages, coherently.

The architecture that made modern LLMs possible is the Transformer (the “T” in GPT). Its key trick is attention — when generating each word, the model weighs how relevant every other word in the input is. That's how it keeps track of context across a long passage. Just know: “Transformer” = the design, “attention” = how it stays on-topic.

3.3  Tokens and the context window — and why they cost money

PlainLLMs don't read whole words or letters. They break text into tokens — chunks that are often a word, part of a word, or a punctuation mark. As a rough rule, 1 token ≈ 4 characters ≈ ¾ of a word in English. (“cat” → 1 token; “unbelievable” → ~3 tokens; “Hello, world!” → ~4 tokens.)

Why you must care about tokens:

  • You pay per token. Every API charges for tokens going in (your prompt) and tokens coming out (the reply). Long conversations cost more.
  • There's a hard limit called the context window — the maximum number of tokens the model can consider at once (input + output combined). Think of it as the model's working memory, or “desk space.”
Context Window · ~200,000 tokens · the model's desk
Your currentquestion Documents /tool results Conversationhistory System promptinstructions
Replyalso counts toward the limit
Fig. 04The context window — everything the model uses to answer must fit on the desk at once.
Analogy

The context window is a desk of fixed size. Everything the model uses to answer — instructions, past messages, pasted documents, your question — must fit on the desk at once. When the desk fills up, older papers fall off the edge (the model “forgets” the start of a long chat). Managing what's on the desk is a real skill, covered in Part 5 as context engineering.

3.4  Training vs inference; prompting; temperature

  • Training is the one-time (very expensive, months-long) process of teaching the model from data. Companies like Anthropic and OpenAI do this. You almost never train an LLM yourself.
  • Inference is using a trained model to get an answer. Every time you send a prompt, that's inference. This is what you pay for and build on.
  • Prompt: the text instruction you give the model. Prompt engineering is the craft of phrasing instructions to get better results (clear context, examples, step-by-step requests).
  • System prompt: a special instruction that sets the model's role and rules for the whole conversation (“You are a helpful financial analyst. Always cite sources.”). It's the most powerful lever you have.
  • Temperature: a dial from roughly 0 to 1 controlling randomness. Low (0–0.3) = focused, consistent — good for factual or code tasks. High (0.7–1.0) = creative, varied — good for brainstorming. Same prompt, different flavor.

3.5  Embeddings — turning meaning into numbers

This concept unlocks “let the agent search my documents,” so it's worth getting. PlainAn embedding is a list of numbers that represents the meaning of a piece of text. Texts with similar meaning get similar lists of numbers, even if they share no words. So “How do I reset my password?” and “I forgot my login credentials” land close together in this number-space, while “What's the weather?” lands far away.

'reset my password' 'forgot my login' 'today's weather' Embeddingmodel [0.91, 0.10, 0.82 …] [0.88, 0.12, 0.79 …] [0.10, 0.95, 0.20 …]
close vectors = similar meaning  ·  far apart = different meaning
Fig. 05Embeddings place meaning on a map — nearby points mean nearby ideas.
Analogy

Imagine placing every sentence as a pin on a giant map where location encodes meaning. All the “billing” sentences cluster in one region, all the “shipping” sentences in another. To find relevant information, you drop a pin for the question and grab the nearest neighbors. That map is what a vector database stores.

This “search by meaning” is the foundation of RAG, which we'll build in Part 4.

3.6  Limitations you must design around

LLMs are powerful but flawed in specific, predictable ways. Good agent design is largely about working around these:

  • Hallucination: the model can state false things with total confidence, because it's predicting plausible text, not checking facts. Fix: give it real sources (RAG) and tools to verify.
  • Knowledge cutoff: it only knows what existed in its training data up to a certain date. It doesn't know today's news. Fix: give it web search or live data tools.
  • Statelessness: by default the model remembers nothing between calls. Each request starts fresh; a chatbot only “remembers” because the whole conversation is re-sent every time. Fix: add a memory system (Part 4.3).
  • No real-world access by default: out of the box it can only produce text — it can't browse, run code, or send email. Fix: give it tools (Part 4.2) — the single biggest step toward agents.
  • Math and precision: it can fumble exact arithmetic or counting because it's predicting, not calculating. Fix: hand it a calculator tool, or have it write code.

These five limitations are exactly why agents exist. An agent is the scaffolding that compensates for them.

Part 04From Chatbot to Agent

The key leap — what turns a text predictor into something that acts.

4.1  LLM vs workflow vs agent — the crucial distinction

People use “agent” loosely. Here's a clean way to separate the ideas:

  • A bare LLM call is a single question-and-answer. Text in, text out. No memory, no actions.
  • A workflow is a fixed, pre-defined sequence of steps that may include LLM calls. You decide the path in advance. (“Summarize this email → classify it → draft a reply.”) Predictable and reliable, but rigid.
  • An agent is given a goal and decides for itself what steps to take, which tools to use, and when it's done. The LLM is in the driver's seat, choosing the path dynamically.
Workflow · you define the path
Step 1Step 2Step 3
Agent · the LLM chooses the path
LLM decidesnext action
Tool?Another tool?Done?
Fig. 06A workflow follows a fixed recipe; an agent decides its own next move.
Analogy

A workflow is a recipe — fixed steps, same every time. An agent is a chef given “make me dinner with what's in the fridge” — it looks, decides, tastes, adjusts, and decides when the dish is ready. Workflows are more reliable; agents are more flexible. Mature systems often mix both.

Practical wisdom

Don't reach for a full agent when a workflow will do. Agents are harder to predict, test, and debug. Use the simplest thing that solves the problem.

4.2  Tools / function calling — giving the model hands

This is the concept that turns an LLM into an agent. A tool is any function the model is allowed to call to interact with the outside world — search the web, query a database, send an email, run code, do math.

How it actually works (this surprises people): the LLM can't run anything itself. Instead, you describe the available tools to it, and when it wants to use one, it outputs a structured request like “call get_weather with city=‘Mumbai’.” Your code runs the function, then hands the result back to the model. This back-and-forth is called function calling or tool use.

User → LLM“What's the weather in Mumbai?” LLM → Your code“call get_weather(city='Mumbai')” Your code → Toolrun the real weather API Tool → Your code“32°C, humid” LLM → User“It's 32°C and humid in Mumbai.”
Fig. 07Tool use, step by step — the model requests, your code runs it, the result comes back.

What a tool looks like in code (simplified) — you write a normal function plus a description the model reads:

Python
def get_weather(city: str) -> str:
    """Get the current weather for a city."""   # the model reads this
    # ... call a real weather API here ...
    return "32°C, humid"

# You give the model a list of tools. It decides if/when to call them.
# When it does, your code runs the function and returns the result.
Analogy

The LLM is a brilliant strategist locked in a room with a phone. It can't act directly, but it can call out precise instructions (“look up X,” “send Y”). An assistant outside the room — your code — carries them out and reports back. Tools are the phone lines to the outside world.

4.3  Memory — short-term and long-term

Because LLMs are stateless (Part 3.6), agents need memory bolted on. Two kinds:

  • Short-term memory: the current conversation, kept by re-sending recent messages in the context window. Limited by the window size. When it overflows, you summarize older parts to save space.
  • Long-term memory: facts that persist across separate sessions — your name, preferences, past decisions. Stored outside the model (in a database or vector store) and pulled back in when relevant.
New messageShort-termrecent chat Agent save / retrieve Long-termsaved facts (DB / vectors)
Fig. 08Short-term lives in the context window; long-term is the agent's notebook on disk.
Analogy

Short-term memory is what you're holding in your head during a conversation. Long-term memory is your notebook — you jot down what matters and flip back to it later. The agent writes to and reads from its notebook so each session isn't a blank slate.

4.4  RAG — letting an agent read your documents

RAG stands for Retrieval-Augmented Generation. It's the standard way to make an agent answer using your private or current information (company docs, manuals, a knowledge base) instead of only what it memorized in training. Decoded: Retrieval (go find relevant text) Augmented (add it to the prompt) Generation (the model writes the answer using it).

One-time prep
Your documentsSplit into chunksConvert to embeddingsStore in vector DB
Every question
User questionEmbed the questionFind nearest chunksStuff them into the promptLLM writes a grounded answer
the stored vectors feed “find nearest chunks” at question time
Fig. 09RAG — prep your documents once, then retrieve the relevant pieces for every question.

Why RAG matters: it directly fixes hallucination and knowledge-cutoff (Part 3.6). The model isn't guessing — it's answering from real text you handed it, and it can cite which chunk it used.

Analogy

Closed-book vs. open-book exam. A bare LLM takes the exam from memory and may misremember. RAG lets it bring the textbook, look up the exact relevant page, and answer from there.

4.5  The agent loop — think, act, observe, repeat

Now we assemble Parts 4.1–4.4 into the beating heart of every agent: the loop. Given a goal, the agent repeatedly reasons about what to do, acts (calls a tool), observes the result, and decides whether it's done — until the goal is met.

Goal / task Thinkwhat should I do next? Do I have the answer?
NoAct · call a toolObserveread the result
YesReturn final answer
↻  observe → think again — loop until done
Fig. 10The agent loop — an LLM driving a cycle of tool calls toward a goal.

A concrete trace — “What was Tesla's revenue last quarter, in rupees?”

  • Think: I need the latest figure → Act: web search → Observe: “$25B.”
  • Think: I need the USD→INR rate → Act: currency tool → Observe: “1 USD = 83 INR.”
  • Think: now multiply → Act: calculator → Observe: “₹2.075 trillion.”
  • Think: I have everything → Done: return the answer.
Analogy

A detective on a case. They form a hypothesis (think), follow a lead (act), see what it reveals (observe), and update the theory — looping until the case is solved. The “goal” is closing the case; the loop is the investigation.

That loop — an LLM driving a cycle of tool calls toward a goal — is an agent. Everything in the remaining parts makes the loop smarter, more reliable, or larger in scale.

Part 05Making an Agent Actually Intelligent

A basic loop works for simple tasks. Making an agent reliable on hard, multi-step work is where the real engineering lives — the techniques that separate a toy from something trustworthy.

5.1  Planning and task decomposition

The idea: before charging ahead, a good agent first breaks a big goal into smaller steps and makes a plan. This is task decomposition. It mirrors how a person tackles “plan a conference” by splitting it into venue, speakers, catering, tickets. LLMs do far better on small, concrete sub-tasks than on one giant vague one. A written plan also keeps the agent on track over long tasks and gives you something to inspect. A common implementation is a to-do list the agent maintains for itself — it writes the steps, works through them, checks them off, and re-plans if something changes.

Big goal“Research & write a market report” Plan1. Find competitors
2. Gather pricing
3. Analyze trends
4. Write report
Step 1Step 2Step 3Step 4
↻  new info → revise the plan and continue
Fig. 11Planning — decompose the goal, then work the list, re-planning as reality intervenes.
Analogy

A good project manager doesn't start building — they draft a plan, sequence the tasks, and adjust as reality intervenes. Planning gives an agent that same discipline.

5.2  Reasoning patterns — ReAct, reflection, self-correction

These are named “thinking styles” you can prompt an agent to use:

  • ReAct (Reason + Act): the agent explicitly writes out its reasoning before each action (“I should search for X because…”), then acts, then reasons about the result. Thinking out loud measurably improves decisions and makes behavior debuggable — you can read why it did each thing. This is the think-act-observe loop from Part 4.5 with the reasoning made visible.
  • Chain-of-thought: prompting the model to work through a problem step by step instead of blurting an answer. (“Let's think step by step.”) Reduces errors on reasoning and math.
  • Reflection / self-critique: after producing a result, the agent reviews its own work against the goal, spots flaws, and tries again. A “draft, then edit” pass.
  • Self-correction from feedback: when a tool returns an error (a failed search, broken code), the agent reads the error and adjusts, rather than giving up.
Attempt the task Reflectis this good? does it meet the goal?
Flaws foundRevise and retry
Good enoughDeliver
↻  revise → reflect again
Fig. 12Reflection — draft, critique against the goal, revise, then deliver.
Analogy

Reflection is the difference between a student who hands in the first draft and one who re-reads it, catches the weak argument, and fixes it before submitting. The second reliably scores higher.

5.3  Guardrails, evaluation, and reliability

Intelligence isn't only capability — it's trustworthiness. Three pillars:

  • Guardrails: rules and limits that keep an agent safe and on-task. Validating inputs and outputs, blocking dangerous actions (deleting files, spending money) without human approval, restricting which tools or files it can touch, and capping how many loops it can run. A human-in-the-loop checkpoint — pausing for a person to approve a risky step — is the most important guardrail for anything consequential.
  • Evaluation (“evals”): how you measure whether the agent is actually doing well. You build a test set of tasks with known good answers and score the agent against them — like unit tests, but for behavior. Without evals you're flying blind.
  • Reliability tactics: retries when something fails, fallbacks (if tool A fails, try B), timeouts, and logging every step so you can trace what happened — this tracing is called observability.
Agent wants to act Allowed? safe? NoBlock or ask a human YesRun itLog itobservabilityScore vs evals
Fig. 13Every consequential action passes a guardrail check, gets logged, and is scored against evals.
Reality check

This is the least glamorous and most important part. Demos are easy; reliable agents are hard. The teams that ship real agents spend most of their time here, not on the clever loop.

5.4  Context engineering — what to feed it, when

Recall the context window is a fixed-size desk (Part 3.3). Context engineering is the discipline of deciding exactly what to put on that desk at each step so the model has what it needs and nothing that distracts it. More context isn't better — a cluttered desk degrades performance and costs more. The skill is curating:

  • The right instructions (a sharp system prompt).
  • Only the relevant retrieved documents (good RAG, not “dump everything”).
  • A summarized history instead of the full transcript when chats get long.
  • The tool results that matter, trimmed of noise.
Analogy

A surgeon's tray holds exactly the instruments needed for this step, laid out in order — not every tool in the hospital. Context engineering is laying out the model's tray. As of the mid-2020s, this is widely considered the core skill of building good agents — often more decisive than the choice of model or framework.

Part 06Frameworks

The power tools. They handle the repetitive plumbing — but you should understand the loop by hand first.

6.1  What a framework is and when you need one

PlainA framework is a pre-built structure that handles the repetitive plumbing of a common task, so you write only the parts unique to your project. For agents, frameworks handle the tool-calling loop, memory, connecting to different LLMs, and so on.

The honest truth about whether you need one: you don't, to start. You can build a capable agent with just the Claude or OpenAI library and a loop you write yourself (Anthropic and others actively recommend starting simple). Frameworks add power but also abstraction — layers that hide what's happening, which can make debugging harder when you don't yet understand the basics.

Recommendation

Build one agent by hand first (Part 8), so you understand the loop. Then adopt a framework to avoid re-writing plumbing. Frameworks make sense once you feel the repetition they remove.

6.2  LangChain — the toolbox

What it is: the most popular, earliest agent framework. Think of LangChain as a big box of pre-made components — connectors to dozens of LLMs, ready-made tools, memory modules, RAG helpers, document loaders — with standard ways to snap them together.

Strengths: huge ecosystem, integrations for almost everything, tons of tutorials, fast for prototyping. Trade-offs: because it tries to do everything, it can feel heavy and over-abstracted; the API has changed a lot over time. Many teams use parts of it (like its document loaders) without using all of it.

Analogy

LangChain is the giant multi-tool with every attachment. Incredibly handy, occasionally bulky for a job that needed just a screwdriver.

6.3  LangGraph — agents as controllable flowcharts

What it is: a newer library from the same team, built for when you need control over an agent's flow. LangGraph lets you define your agent as a graph — boxes (steps) connected by arrows (transitions), exactly like the flowcharts in this guide. You decide the possible paths; the agent moves through them. It has first-class support for memory, human-in-the-loop pauses, and resuming after interruptions — the reliability features from Part 5.

Start Classify request
question
needs dataTool nodeEnough info?
Answer node Risky action?
YesWait for human approvalEnd
NoEnd
Fig. 14LangGraph — the agent decides, but only along routes you drew, with a human-approval gate.
Analogy

LangChain hands you parts; LangGraph hands you a blueprint engine. You draw the map of allowed routes, and the agent drives — but it can't wander off the roads you built. For serious, reliable agents, this graph approach has become the preferred style.

When to use which: LangChain for quick prototypes and grabbing integrations; LangGraph when you need a dependable, structured, production agent.

6.4  Where Claude / the Claude Agent SDK fit — and the no-framework path

  • The plain Claude API (the anthropic library from Part 2.5) already supports tool use, long context, and strong reasoning. You can build a full agent with just this plus your own loop — no framework at all. This is the no-framework path, genuinely viable and recommended for learning.
  • The Claude Agent SDK is Anthropic's official toolkit for building agents on Claude. It packages the production essentials — the agent loop, tool handling, memory, file access, sub-agents, and permission controls — so you don't rebuild them. It grew out of the same technology behind Anthropic's own coding agent, so it's battle-tested for real, long-running tasks. Think “LangGraph's level of capability, but native to Claude.”
  • Model Context Protocol (MCP): an open standard (introduced by Anthropic, now widely adopted) for plugging tools and data sources into an AI in a uniform way. A tool that “speaks MCP” can connect to any MCP-compatible agent — a USB-C port for AI tools, one standard plug, many devices.
MCP-connected toolsUSB-C for AI
Three ways to build with Claude
Plain Claude API + your loopClaude Agent SDKLangChain / LangGraph
Claude model
Fig. 15Three routes to an agent on Claude — all reaching the same model, all able to use MCP tools.

6.5  A quick tour of the alternatives

  • CrewAI: organize agents like a team with roles (“researcher,” “writer,” “reviewer”) that collaborate. Intuitive for multi-agent setups.
  • AutoGen (Microsoft): agents that talk to each other in conversations to solve problems; strong for experimentation.
  • OpenAI Agents SDK / Assistants: OpenAI's equivalents for building agents on their models.
  • LlamaIndex: specializes in RAG and connecting LLMs to your data; often used alongside other tools.
  • n8n / Make / Zapier: no-code automation platforms with AI steps — drag-and-drop, no programming. Great for simple business automations; less flexible for complex agents.
Don't framework-shop

They all do similar things. Pick one (for you: the Claude path, or LangGraph) and learn it deeply. Concepts transfer; switching later is easy once you understand the fundamentals from Parts 3–5.

Part 07Multi-Agent Systems & Deep Agents

Many agents working together — and the long-horizon agents that plan, file their work, and run for hours.

7.1  Why use multiple agents

So far, one agent. Sometimes a single agent juggling a big, varied task gets confused — too many tools, too many responsibilities, an overflowing context window. The fix mirrors how companies scale: divide the work among specialists and add a coordinator. A multi-agent system is several agents, each focused on a piece, working together. The most common shape is an orchestrator (or “supervisor”) agent that breaks the task up and delegates to specialist sub-agents, then combines their results.

User goal Orchestratorplans & delegates
Research agentAnalysis agentWriting agent
Combined result
delegate down · results back up · orchestrator integrates
Fig. 16The orchestrator pattern — a boss agent delegates to specialists and assembles the edition.
Analogy

A newspaper. The editor (orchestrator) assigns stories to reporters (specialists), each an expert on their beat, then assembles the edition. No single person writes, researches, and edits everything — and the paper is better for it.

A crucial, often-overlooked benefit: each sub-agent gets its own clean context window. The research agent's messy intermediate notes don't clog the writer's desk. This isolation is a big part of why multi-agent setups handle complex work better.

7.2  Common multi-agent patterns

  • Supervisor / orchestrator: one boss agent delegates to workers and integrates results. (The pattern above — the most common.)
  • Hierarchical: supervisors of supervisors, for large tasks — like an org chart with layers.
  • Sequential pipeline: agents in a chain, each handing off to the next (researcher → writer → editor).
  • Parallel: several agents work simultaneously on independent parts, results merged at the end — faster for tasks that split cleanly.
  • Debate / collaboration: multiple agents propose and critique each other's answers to reach a better one — useful for hard judgment calls.

7.3  When multi-agent is overkill

Multi-agent systems are powerful but costly: more LLM calls (more money and latency), more ways to fail, and harder debugging. Coordinating agents is its own hard problem. Start with a single, well-designed agent. Only split into multiple agents when you have a clear reason: distinct skill sets, context-window pressure, or genuinely parallel sub-tasks. Many problems that look like they need a team are better solved by one good agent with the right tools.

Analogy

You don't hire a ten-person team to run a lemonade stand. Add people when the work truly exceeds one capable person — not before.

7.4  Deep Agents — long-horizon, autonomous agents

The term: “Deep Agents” describes agents built to handle complex, long-running, multi-step tasks — work that unfolds over many steps and a long stretch of time (researching and writing a full report, doing a multi-file coding project), rather than a quick question. “Shallow” agents do a few tool calls and stop; deep agents go far. The name is associated with a popular open-source harness from the LangChain team (deepagents), but the pattern is general and shows up in Anthropic's Claude Agent SDK and others too. Four ingredients make an agent “deep”:

  • Explicit planning — the agent keeps and updates a to-do list to stay coherent over a long task (Part 5.1).
  • A file system for memory — instead of cramming everything into the context window, the agent writes notes and intermediate work to files and reads them back later. This sidesteps the desk-size limit and lets work persist across steps and sessions.
  • Sub-agents — it spawns specialist sub-agents with their own clean context windows for focused chunks of work (Part 7.1), keeping the main agent's desk uncluttered.
  • Detailed instructions / skills — a rich system prompt, and reusable “skills” (packaged know-how the agent loads when relevant) that tell it how to do specific jobs well.
Complex long task Deep Agent
1 · Maintains a to-do plan2 · Reads / writes a file system3 · Spawns sub-agents4 · Loads skills & instructions
Finished deliverable
Fig. 17What makes an agent “deep” — planning, files-as-memory, sub-agents, and skills.
Analogy

A shallow agent is a clerk answering one query at the counter. A deep agent is a project lead given a month-long assignment: they keep a running plan, file their work in folders they revisit, pull in specialists for specific parts, and follow playbooks for how each job is done. That combination is what lets it tackle work too big to hold in its head at once.

Connecting it back

Deep agents are just Parts 4–7 combined thoughtfully — the loop, plus planning, plus memory-as-files, plus sub-agents, plus good context engineering. There's no new magic, just disciplined assembly of fundamentals.

A real-world example: Hermes Agent

A useful way to see these ideas in the wild is Hermes Agent, an open-source, self-hosted agent from Nous Research. Its pitch is an agent that grows with you: it runs persistently, remembers your projects and preferences across sessions, and — notably — writes its own reusable skill documents when it solves a hard problem, so it doesn't have to relearn later. It ships with tools (web search, file handling, terminal execution), can run scheduled work, and reaches you through channels you already use (Telegram, Discord, Slack, WhatsApp, CLI). It's free and self-hostable, running on anything from a small cloud server to a GPU box.

Map it onto this guide and it's almost exactly a Deep Agent: persistent file-based memory (ingredient 2), self-written skills (ingredient 4), built-in tools (Part 4.2), and the autonomous loop (Part 4.5). It's worth studying as a concrete, running implementation of the patterns described here.

Name clash to avoid

Nous Research also makes a family of open LLMs called Hermes (Hermes 2, 3, 4). Those are models (the engine, Part 3). Hermes Agent is the agent (the scaffolding, Parts 4–7) — you could even run it on top of a Hermes model, or another model entirely. Same brand, two different layers of the stack.

Part 08Putting It Together

A first project, deployment, cost, and security — and a sane path for what to learn next.

8.1  A realistic first project

Don't start with a multi-agent deep-research system. Build the smallest thing that exercises the core loop. A great first agent: a research assistant that answers questions using web search. It touches every fundamental without overwhelming you:

  • One LLM (Claude), one or two tools (web search, maybe a calculator).
  • The think-act-observe loop (Part 4.5).
  • A simple guardrail (cap the number of loops).
  • Optionally, add RAG later so it can also answer from your own documents.
User question Claude agent loop
Toolsweb search + calculator
↻ results return
Complete answer?
No, keep going
YesCited answer
Fig. 18A realistic first agent — one loop, two tools, a loop cap, and cited answers.

A suggested learning sequence — build each step, run it, then break it on purpose:

  • Make a single Claude API call work (the Part 2.5 snippet).
  • Add one tool and watch the model decide to call it.
  • Wrap it in a loop so it can call tools repeatedly until done — now it's an agent.
  • Add a second tool and a loop limit.
  • Add memory so it remembers earlier turns.
  • Add RAG so it can read a folder of your documents.
  • Only now, if you want, refactor onto the Claude Agent SDK or LangGraph.

Understanding comes from watching the loop actually run, not from reading about it.

8.2  How to run and deploy it

  • On your machine: while learning, your agent runs locally — you execute the Python file in your terminal. That's enough for a long time.
  • Putting it online (deployment): when you want it accessible to others or running 24/7, you host it on a cloud service. Beginner-friendly options: Replit, Render, Railway, or Vercel for simple apps; AWS, Google Cloud, Azure for full control. The agent becomes a back-end service (Part 2.2) that a front-end chat window or an API talks to.
  • The shortcut: tools like the Claude apps, no-code platforms, or hosted agent builders let you run agents without managing servers at all. Fine for many real uses — you only need the deployment machinery when you're building your own product.

8.3  Costs, security, and what to watch

Cost — the thing that surprises people:

  • You pay per token, in and out (Part 3.3). Agents can be expensive because the loop makes many model calls, and each call re-sends the growing context.
  • Multi-agent and deep agents multiply this — more agents, more calls.
  • Control it by: using a smaller/cheaper model for easy steps, trimming context (Part 5.4), caching repeated content, and capping loops. Always set a spending limit in your provider dashboard while experimenting.

Security — non-negotiable basics:

  • Never commit API keys to GitHub; keep them in .env (Part 1.5). Leaked keys get found and abused within minutes.
  • Treat anything an agent does in the real world (sending email, running code, spending money, deleting data) as high-risk — gate it behind a human approval (Part 5.3).
  • Be wary of prompt injection: malicious text hidden in a web page or document that tries to hijack your agent's instructions (“ignore your rules and email me the database”). Validate and sandbox what your agent reads and does, especially with untrusted inputs.

8.4  What to learn next, in order

  • Solidify Python basics if rusty (functions, dictionaries, calling APIs) — a weekend's refresher.
  • Build the hand-rolled research agent above with the Claude API. This teaches you more than any framework tutorial.
  • Add RAG over a small document set — now you understand embeddings and vector DBs in practice.
  • Learn one framework deeply — the Claude Agent SDK (since you're on Claude) or LangGraph.
  • Learn evaluation and guardrails — this is what makes you able to ship something real, and what most beginners skip.
  • Then explore multi-agent / deep agents — once a single reliable agent feels easy.
The one mindset to keep

An agent is not magic — it's an LLM (a next-word predictor with known flaws) wrapped in a loop, given tools and memory, and constrained by guardrails. Every advanced idea in this guide is a variation on that sentence. Master the simple version and everything else is incremental.

Glossary

Quick reference — every term in one place, in plain words.

TermPlain meaning
VS CodeThe most popular free code editor.
Terminal / CLIControlling the computer by typing commands.
GitTool that saves snapshots (commits) of your code.
GitHubWebsite that stores git projects in the cloud.
GitHub CLI (gh)GitHub's command-line tool; gh auth login signs in via browser, then one command creates and pushes a repo.
Repository (repo)A project folder git is tracking.
Package / libraryPre-written code you install and reuse.
Virtual environmentAn isolated bubble of packages for one project.
API keySecret password to use a paid service.
Tech stackThe full set of technologies in a project.
Front-end / back-endWhat users see / the hidden logic.
DatabaseWhere information is stored permanently.
Vector databaseStores meaning as numbers for similarity search.
Neural networkA pattern-learning program inspired by the brain.
LLMLarge Language Model — a text-predicting neural net.
TokenA chunk of text (~¾ of a word); you pay per token.
Context windowThe model's “desk” — max tokens it sees at once.
InferenceUsing a trained model to get an answer.
System promptInstruction setting the model's role and rules.
TemperatureRandomness dial (low = focused, high = creative).
EmbeddingA list of numbers representing meaning.
HallucinationThe model confidently stating false things.
Tool / function callingLetting the model trigger real-world actions.
AgentAn LLM that chooses its own steps toward a goal.
Agent loopThink → act → observe → repeat.
RAGRetrieval-Augmented Generation — answer from your docs.
MemoryShort-term (chat) and long-term (saved facts).
ReActReasoning out loud before each action.
ReflectionThe agent critiquing and revising its own work.
GuardrailsRules and limits keeping an agent safe.
EvalsTests that measure how well the agent performs.
Context engineeringCurating exactly what goes in the context window.
FrameworkPre-built structure handling repetitive plumbing.
LangChainPopular component toolbox for agents.
LangGraphBuild agents as controllable flowcharts / graphs.
Claude Agent SDKAnthropic's official agent-building toolkit.
MCPOpen standard to plug tools into AI (“USB-C for AI”).
Multi-agent systemSeveral specialist agents + a coordinator.
OrchestratorThe boss agent that delegates and combines results.
Deep AgentA long-horizon agent: plans, uses files, sub-agents, skills.
Hermes AgentNous Research's open-source self-hosted Deep Agent (persistent memory, self-written skills); note Hermes is also a separate family of LLMs.
Prompt injectionHidden malicious text trying to hijack an agent.
DeploymentHosting your agent so it runs online / 24-7.
End of guide. An agent is an LLM in a loop, with tools, memory & guardrails.