MCPcopy Index your code
hub / github.com/rohitg00/ai-engineering-from-scratch

github.com/rohitg00/ai-engineering-from-scratch @main sqlite

repository ↗ · DeepWiki ↗
9,838 symbols 33,069 edges 753 files 711 documented · 7% 14 cross-repo links
README

AI Engineering from Scratch — reference manual banner

MIT License 503 lessons 20 phases GitHub stars Website

From the creator of Agent Memory - #1 Persistent memory ⭐ GitHub stars which naturally works with any agents or chat assistants.

░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒

84% of students already use AI tools. Only 18% feel prepared to use them professionally. This curriculum closes that gap.

503 lessons. 20 phases. ~320 hours. Python, TypeScript, Rust, Julia. Every lesson ships a reusable artifact: a prompt, a skill, an agent, an MCP server. Free, open source, MIT.

You don't just learn AI. You build it. End-to-end. By hand.

150,639 readers  ·  241,669 page views in the last 30 days  ·  as of 2026-06-07

How this works

Most AI material teaches in scattered pieces. A paper here, a fine-tuning post there, a flashy agent demo somewhere else. The pieces rarely line up. You ship a chatbot but can't explain its loss curve. You hook a function to an agent but can't say what attention does inside the model that's calling it.

This curriculum is the spine. 20 phases, 503 lessons, four languages: Python, TypeScript, Rust, Julia. Linear algebra at one end, autonomous swarms at the other. Every algorithm gets built from raw math first. Backprop. Tokenizer. Attention. Agent loop. By the time PyTorch shows up, you already know what it's doing under the hood.

Each lesson runs the same loop: read the problem, derive the math, write the code, run the test, keep the artifact. No five-minute videos, no copy-paste deploys, no hand-holding. Free, open source, and built to run on your own laptop.

░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒

The shape of the curriculum

Twenty phases stack on top of each other. Math is the floor. Agents and production are the roof. Skip ahead if you already know the lower layers, but don't skip and then wonder why something at the top is breaking.

%%{init: {'theme':'base','themeVariables':{'primaryColor':'#fafaf5','primaryTextColor':'#1a1a1a','primaryBorderColor':'#3553ff','lineColor':'#3553ff','fontFamily':'JetBrains Mono','fontSize':'12px'}}}%%
flowchart TB
  P0["Phase 0 — Setup & Tooling"] --> P1["Phase 1 — Math Foundations"]
  P1 --> P2["Phase 2 — ML Fundamentals"]
  P2 --> P3["Phase 3 — Deep Learning Core"]
  P3 --> P4["Phase 4 — Vision"]
  P3 --> P5["Phase 5 — NLP"]
  P3 --> P6["Phase 6 — Speech & Audio"]
  P3 --> P9["Phase 9 — RL"]
  P5 --> P7["Phase 7 — Transformers"]
  P7 --> P8["Phase 8 — GenAI"]
  P7 --> P10["Phase 10 — LLMs from Scratch"]
  P10 --> P11["Phase 11 — LLM Engineering"]
  P10 --> P12["Phase 12 — Multimodal"]
  P11 --> P13["Phase 13 — Tools & Protocols"]
  P13 --> P14["Phase 14 — Agent Engineering"]
  P14 --> P15["Phase 15 — Autonomous Systems"]
  P15 --> P16["Phase 16 — Multi-Agent & Swarms"]
  P14 --> P17["Phase 17 — Infrastructure & Production"]
  P15 --> P18["Phase 18 — Ethics & Alignment"]
  P16 --> P19["Phase 19 — Capstone Projects"]
  P17 --> P19
  P18 --> P19
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒

The shape of a lesson

Each lesson lives in its own folder, with the same structure across the entire curriculum:

phases/<NN>-<phase-name>/<NN>-<lesson-name>/
├── code/      runnable implementations (Python, TypeScript, Rust, Julia)
├── docs/
│   └── en.md  lesson narrative
└── outputs/   prompts, skills, agents, or MCP servers this lesson produces

Every lesson follows six beats. The Build It / Use It split is the spine — you implement the algorithm from scratch first, then run the same thing through the production library. You understand what the framework is doing because you wrote the smaller version yourself.

%%{init: {'theme':'base','themeVariables':{'primaryColor':'#fafaf5','primaryTextColor':'#1a1a1a','primaryBorderColor':'#3553ff','lineColor':'#3553ff','fontFamily':'JetBrains Mono','fontSize':'13px'}}}%%
flowchart LR
  M["MOTTO

<sub>one-line core idea</sub>"] --> Pr["PROBLEM

<sub>concrete pain</sub>"]
  Pr --> C["CONCEPT

<sub>diagrams &amp; intuition</sub>"]
  C --> B["BUILD IT

<sub>raw math, no frameworks</sub>"]
  B --> U["USE IT

<sub>same thing in PyTorch / sklearn</sub>"]
  U --> S["SHIP IT

<sub>prompt · skill · agent · MCP</sub>"]

Getting started

Three ways in. Pick one.

Option A — read. Open any completed lesson on aiengineeringfromscratch.com or expand a phase under Contents. No setup, no cloning.

Option B — clone and run.

git clone https://github.com/rohitg00/ai-engineering-from-scratch.git
cd ai-engineering-from-scratch
python phases/01-math-foundations/01-linear-algebra-intuition/code/vectors.py

Option C — find your level (recommended). Skip ahead intelligently. Inside Claude, Cursor, Codex, OpenClaw, Hermes, or any agent with the curriculum skills installed:

/find-your-level

Ten questions. Maps your knowledge to a starting phase, builds a personalized path with hour estimates. After each phase:

/check-understanding 3        # quiz yourself on phase 3
ls phases/03-deep-learning-core/05-loss-functions/outputs/
# ├── prompt-loss-function-selector.md
# └── prompt-loss-debugger.md

Prerequisites

  • You can write code (any language; Python helps).
  • You want to understand how AI actually works, not just call APIs.

Built-in agent skills (Claude, Cursor, Codex, OpenClaw, Hermes)

Skill What it does
/find-your-level Ten-question placement quiz. Maps your knowledge to a starting phase and produces a personalized path with hour estimates.
/check-understanding <phase> Per-phase quiz, eight questions, with feedback and specific lessons to review.
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒

Every lesson ships something

Other curricula end with "congratulations, you learned X." Each lesson here ends with a reusable tool you can install or paste into your daily workflow.

FIG_001.A prompts FIG_001 · A PROMPTS FIG_001.B skills FIG_001 · B SKILLS FIG_001.C agents FIG_001 · C AGENTS FIG_001.D MCP servers FIG_001 · D MCP SERVERS
Paste into any AI assistant for expert-level help on a narrow task. Drop into Claude, Cursor, Codex, OpenClaw, Hermes, or any agent that reads SKILL.md. Deploy as autonomous workers — you wrote the loop yourself in Phase 14. Plug into any MCP-compatible client. Built end-to-end in Phase 13.

Install the lot with python3 scripts/install_skills.py. Real tools, not homework. By the end of the curriculum, you have a portfolio of 503 artifacts you actually understand because you built them.

FIG_002 · A worked sample

Phase 14, lesson 1: the agent loop. ~120 lines of pure Python, no dependencies.

**`code/agent_loop.py`**   build it
def run(query, tools):
    history = [user(query)]
    for step in range(MAX_STEPS):
        msg = llm(history)
        if msg.tool_calls:
            for call in msg.tool_calls:
                result = tools[call.name](**call.args)
                history.append(tool_result(call.id, result))
            continue
        return msg.content
    raise StepLimitExceeded
**`outputs/skill-agent-loop.md`**   ship it
---
name: agent-loop
description: ReAct-style loop for any tool list
phase: 14
lesson: 01
---

Implement a minimal agent loop that...
**`outputs/prompt-debug-agent.md`**
You are an agent debugger. Given the trace
of an agent run, identify the step where
the agent went wrong and explain why...
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒

Contents

Twenty phases. Click any phase to expand its lesson list.

Phase 0: Setup & Tooling 12 lessons

Get your environment ready for everything that follows.

# Lesson Type Lang
01 Dev Environment Build Python
02 Git & Collaboration Learn
03 GPU Setup & Cloud Build Python
04 APIs & Keys Build Python
05 Jupyter Notebooks Build Python
06 Python Environments Build Shell
07 Docker for AI Build Docker
08 Editor Setup Build
09 Data Management Build Python
10 Terminal & Shell Learn
11 Linux for AI Learn
12 Debugging & Profiling Build Python

Phase 1 — Math Foundations  22 lessons  The intuition behind every AI algorithm, through code.

# Lesson Type Lang
01 Linear Algebra Intuition Learn Python, Julia
02 Vectors, Matrices & Operations Build Python, Julia
03 Matrix Transformations & Eigenvalues Build Python, Julia
04 Calculus for ML: Derivatives & Gradients Learn Python
05 Chain Rule & Automatic Differentiation Build Python
06 Probability & Distributions Learn Python
07 Bayes' Theorem & Statistical Thinking Build Python
08 Optimization: Gradient Descent Family Build Python
09 Information Theory: Entropy, KL Divergence Learn Python
10 Dimensionality Reduction: PCA, t-SNE, UMAP Build Python
11 Singular Value Decomposition Build Python, Julia
12 Tensor Operations Build Python
13 Numerical Stability Build Python
14 Norms & Distances Build Python
15 Statistics for ML Build Python
16 Sampling Methods Build Python
17 Linear Systems Build Python
18 Convex Optimization Build Python
19 Complex Numbers for AI Learn Python
20 The Fourier Transform Build Python
21 [Graph Th

Extension points exported contracts — how you extend this code

Schema (Interface)
(no doc) [5 implementers]
phases/11-llm-engineering/03-structured-outputs/code/main.ts

Core symbols most depended-on inside this repo

el
called by 1326
site/figures.js
append
called by 987
phases/13-tools-and-protocols/19-a2a-protocol/code/main.py
append
called by 555
phases/07-transformers-deep-dive/12-kv-cache-flash-attention/code/main.py
svgEl
called by 504
site/lesson-figures.js
log
called by 362
phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py
items
called by 326
phases/14-agent-engineering/23-otel-genai-conventions/code/main.py
get
called by 249
phases/14-agent-engineering/01-the-agent-loop/code/main.py
mean
called by 241
phases/19-capstone-projects/55-critic-loop/code/main.py

Shape

Function 5,161
Method 3,186
Class 1,489
Interface 1
Route 1

Languages

Python89%
TypeScript11%

Modules by API surface

phases/19-capstone-projects/29-end-to-end-coding-task-demo/code/main.py67 symbols
phases/03-deep-learning-core/10-mini-framework/code/main.py65 symbols
phases/02-ml-fundamentals/13-ml-pipelines/code/pipeline.py62 symbols
phases/19-capstone-projects/71-classical-metrics/code/tests/test_metrics.py50 symbols
phases/19-capstone-projects/69-end-to-end-rag-system/code/main.py49 symbols
phases/19-capstone-projects/38-classifier-finetuning/code/main.py49 symbols
phases/02-ml-fundamentals/11-ensemble-methods/code/ensembles.py49 symbols
phases/19-capstone-projects/42-large-corpus-downloader/code/main.py44 symbols
phases/19-capstone-projects/43-hdf5-tokenized-corpus/code/main.py43 symbols
phases/19-capstone-projects/25-verification-gates-observation-budget/code/main.py43 symbols
phases/19-capstone-projects/41-eval-pipeline/code/main.py42 symbols
site/lesson-figures.js41 symbols

Dependencies from manifests, versioned

@hono/node-server1.13.0 · 1×
@types/node20.17.10 · 1×
@types/ws8.5.13 · 1×
hono4.6.0 · 1×
tsx4.19.2 · 1×
typescript5.7.3 · 1×
ws8.18.0 · 1×
zod3.23.8 · 1×
accelerate0.20 · 1×
anthropic0.25 · 1×
datasets2.14 · 1×
jupyter1.0 · 1×

Datastores touched

SELECTDatabase · 1 repos
mydbDatabase · 1 repos

For agents

$ claude mcp add ai-engineering-from-scratch \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact