Back to labLearn AIShovon Saha

chapter 00

Start Here

Who the book is for and what you will have built by the end.

Contents

1 / 7

Learn Python, backend systems and agents through worked examples


Who this is for

This book is for readers with some programming experience who want a clearer picture of how an agent works. You do not need to remember every Python feature. Start with these habits:

  • Follow the input, the transformation and the output.
  • Run a small example before adding another concept.
  • Ask what problem a tool solves before adopting it.

The chapters introduce Python, HTTP, model interfaces and tool loops in that order. The browser interpreter supports a limited Python subset. Some package, file and model calls are simulated; they are not evidence of a live integration.

For full Python behavior, compare examples with the Python tutorial and run them locally. For model and deployment examples, check the provider's current documentation before using real credentials or data.


Why "data in, data out" is the whole trick

Every piece of software you will ever touch, from a one-line function to a trillion-parameter language model, can be squashed into the same three-box picture:

   ┌───────────┐        ┌─────────────────┐        ┌───────────┐
   │  INPUT    │──────▶ │  TRANSFORMATION  │──────▶ │  OUTPUT   │
   └───────────┘        └─────────────────┘        └───────────┘

A function is input → return value. An HTTP request is request → response. A chat model is message history → next message. An agent is question → (maybe some tool calls) → answer. Once this picture is burned into your head, nothing in this book is "magic" anymore - it's just bigger and bigger versions of the same box. Every diagram in every chapter is a variant of this same shape, because that repetition is the actual teaching method here, not a stylistic tic.


The destination

By the last chapter you will have built this, from scratch, understanding every line:

┌─────────────────────────────────────────────────────────────────────┐
│                         YOUR AGENT PROJECT                          │
│                                                                       │
│   You type a question                                                │
│        │                                                             │
│        ▼                                                             │
│   ┌─────────┐      ┌───────────────┐      ┌─────────────────────┐    │
│   │  Agent  │─────▶│ Provider layer│─────▶│  LM Studio (local)  │    │
│   │  loop   │      │ (swap engines)│  or  │  OpenAI (cloud)     │    │
│   │         │◀─────│               │◀─────│  Anthropic (cloud)  │    │
│   └─────────┘      └───────────────┘      └─────────────────────┘    │
│        │                                                              │
│        ▼                                                              │
│   Can call tools (calculator, web search, files...)                   │
│        │                                                              │
│        ▼                                                              │
│   Answer, grounded, with memory of the conversation                   │
└─────────────────────────────────────────────────────────────────────┘

You'll start 100% local and free (LM Studio, no API key, no internet needed for the model itself) and only later add cloud providers - because that's the cheapest and safest way to learn the mechanics without burning API credits on your mistakes.

Why local-first? If you make a mistake in an infinite loop that calls an LLM a thousand times, doing it against LM Studio on your own machine costs you a warm laptop. Doing it against a paid API can cost you real money before you notice. We only introduce billing once you understand exactly what triggers a call.


The map (read in this order)

#FileWhat it teachesWhy it exists in this order
0101_python_by_example.mdPython language, via input→output examplesYou can't write an agent in a language you don't have muscle memory in
0202_the_ecosystem_why_project_files_exist.mdpyproject.toml, virtual environments - Python's answer to package.json/pom.xmlEvery real project (including the one you'll build) needs this before line 1 of app code
0303_backend_fundamentals.mdHTTP, JSON, APIs, async - what a "backend" actually isLM Studio and every AI provider is a backend you talk to over HTTP
0404_llm_concepts_for_researchers.mdTokens, context windows, embeddings, chat rolesYou need the mental model before touching an API, or the code is just magic incantation
0505_lm_studio_ground_up.mdInstalling and calling LM Studio from PythonYour first real, working AI call - 100% local
0606_building_your_first_agent.mdThe agent loop, tool calling, memoryTurns "call a model" into "call a model that can act"
0707_multi_provider_architecture.mdAbstracting providers so you can swap LM Studio ↔ OpenAI ↔ AnthropicThe "why" behind config files and interfaces, applied to your own code
0808_capstone_project.mdThe whole project assembled, file tree, next stepsTies everything into one runnable repo

Each chapter can be read alone if you already know some of it, but they build on each other. If you skip ahead and something feels like it came from nowhere, it's almost always defined one or two chapters earlier - the table above tells you where to look back.


One idea that repeats through the whole book

Every single tool you'll meet - pip, pyproject.toml, HTTP, JSON, an LLM's chat API, an agent's tool-calling - is solving the same underlying problem: two things that don't know about each other's internals need to exchange data in a shape they both agree on.

   Thing A                 AGREED SHAPE (contract)                Thing B
┌───────────┐        ┌───────────────────────────────┐        ┌───────────┐
│  your     │──────▶ │ JSON / TOML / HTTP / function  │──────▶ │  someone  │
│  code     │        │ signature / API schema...      │        │  else's   │
│           │◀────── │                                │◀────── │  code     │
└───────────┘        └───────────────────────────────┘        └───────────┘

package.json is that contract for npm. pom.xml is that contract for Maven. pyproject.toml is that contract for Python. An LLM's messages list is that contract for a conversation. A "tool call" JSON blob is that contract between a model and your Python function. Once you see this pattern once, every new tool in this book gets easier, not harder.

Common mistake: treating each new tool as an unrelated thing to memorize. If you instead ask "what is thing A, what is thing B, and what's the agreed shape between them?" every chapter from here on collapses into the same five-minute mental exercise.

A worked mini-example of "the contract" before you've written any code

Even before Chapter 1, you can see the pattern in something you already know: a restaurant order.

   Customer                    THE MENU (the contract)                 Kitchen
┌────────────┐        ┌─────────────────────────────────┐        ┌────────────┐
│ "I'll have │──────▶ │ Item name + size + modifiers,    │──────▶ │ cooks the  │
│  a burger" │        │ written on a ticket the kitchen  │        │ exact item │
│            │◀────── │ already knows how to read        │◀────── │ back out   │
└────────────┘        └─────────────────────────────────┘        └────────────┘

The customer doesn't need to know how the kitchen works internally, and the kitchen doesn't need to know why the customer wants a burger. They only need to agree on the ticket format. That's it - that's every API you'll ever use.


What to install before Chapter 1

  1. Python 3.11+ - python.org (check "Add to PATH" on Windows)
  2. A code editor - VS Code is fine, free
  3. LM Studio - lmstudio.ai (we install and configure it properly in Chapter 5, don't worry about it yet)
  4. A terminal you're not afraid of (Terminal.app, Windows Terminal, or VS Code's built-in one)

Confirm your install worked before moving on:

python3 --version
# Python 3.11.x  (or newer)

If that command fails, fix it now - every later chapter assumes it works. On Windows, the command is often python --version instead of python3 --version; try both.

Common mistake: installing Python but not checking "Add to PATH" on Windows, then wondering why python3 is "not recognized" in every terminal you open. Reinstalling with that box checked fixes it in under a minute.


How to actually use this book

  • Every code block that starts with ```python in this book is meant to be run, not just read. Type it out yourself at least once per chapter, even if you're sure you already know it. Muscle memory beats recognition.
  • When a diagram shows boxes and arrows, pause and say out loud what's in each box before reading the explanation underneath it. That's the actual comprehension check.
  • Each chapter ends with a short "Check yourself" list. If you can't answer one without looking back, that's fine - it just tells you exactly what to re-read.

That's it. Let's start.