How the AI Engineering From Scratch Curriculum Uses the Build It / Use It Methodology

The AI Engineering From Scratch curriculum employs a strict six-beat lesson structure where students first implement algorithms from raw mathematics without frameworks (Build It) before switching to production libraries like PyTorch or MCP clients (Use It), ensuring deep mechanical understanding.

The rohitg00/ai-engineering-from-scratch repository organizes 503 lessons around a pedagogical spine called the Build It / Use It methodology. This approach mandates that learners implement every component—from linear regression to multimodal agents—using only standard libraries before ever touching high-level frameworks. By enforcing this dual-phase structure across all lessons, the curriculum ensures students can debug library internals and reason about performance rather than merely calling APIs.

The Six-Beat Lesson Architecture

Every lesson follows the pattern MOTTO → PROBLEM → CONCEPT → BUILD IT → USE IT → SHIP IT as defined in the repository's top-level README.md. The third and fourth beats form the core learning process, while the remaining beats provide context and delivery milestones. This structure repeats across all 503 lessons, from early linear-algebra exercises to advanced agent engineering in Phase 14.

Build It: Implementing Algorithms From Scratch

In the Build It phase, learners write algorithms from first principles without NumPy, PyTorch, or other high-level abstractions. For example, in phases/14-agent-engineering/01-the-agent-loop/code/main.py, students construct a deterministic ReAct agent loop using only Python standard library components.


# === Build It – a toy ReAct loop from scratch (stdlib only) ===

# File: phases/14-agent-engineering/01-the-agent-loop/code/main.py

class ToyLLM:
    """Deterministic toy LLM that emits Thought/Action/Observation tokens."""
    def __call__(self, history):
        # Very simple rule-based generator for demonstration

        last = history[-1]
        if "capital of France" in last:
            return "Thought: I need to look that up.\nAction: search('capital of France')"
        if "search" in last:
            return "Observation: Paris is the capital of France.\nThought: The answer is Paris.\nAction: finish('Paris')"
        return "Finish: I have nothing to do."

# Tool registry – maps tool names to Python callables

tools = {
    "search": lambda query: "Paris is the capital of France.",  # stub

    "finish": lambda ans: ans,
}

def run_agent():
    llm = ToyLLM()
    history = ["User: What is the capital of France?"]
    for turn in range(5):          # turn budget → prevents infinite loops

        response = llm(history)
        if "Action:" in response:
            # parse simple "Action: name(args)" format

            name, args = response.split("Action: ")[1].split("(")
            args = args.rstrip(")")
            result = tools[name](args.strip("'\""))
            history.append(f"Tool ({name}): {result}")
        else:
            print("🔚 Final answer:", response)
            break

run_agent()

Running this script yields a full ReAct trace showing the agent's reasoning, tool invocation, and observation handling—implemented entirely without external AI frameworks.

Use It: Integrating Production-Grade Frameworks

The Use It phase requires the exact same logic but swaps the toy implementation for a production-grade library. In phases/14-agent-engineering/01-the-agent-loop/code/main_mcp.py, the ToyLLM class is replaced with a real Model-Context-Protocol (MCP) client, while the tool registry, history management, and turn budget remain identical.


# === Use It – swapping the toy LLM for a real model via the MCP client ===

# File: phases/14-agent-engineering/01-the-agent-loop/code/main_mcp.py

from mcp_client import MCPClient  # a production-grade MCP client (installed via scripts/install_skills.py)

client = MCPClient(endpoint="https://mcp.example.com")
tools = {
    "search": lambda q: client.search(q),   # real remote call

    "finish": lambda ans: client.finish(ans),
}

# The rest of the loop (history handling, turn budget, etc.) stays identical.

The only change between phases is the substitution of ToyLLM with an MCPClient instance. This single-line swap highlights exactly what the library abstracts away—networking, serialization, and token streaming—while proving that the student's core logic (the tool registry and turn budget) remains robust and framework-agnostic.

Why the Build First Discipline Matters

By first building the component, students gain intuition about matrix operations, attention mechanisms, or agent loop mechanics. When they later use the library, they can spot mismatches between expected and actual behavior, debug failures at the library boundary, and safely extend functionality without breaking stability. This discipline is documented in phases/14-agent-engineering/01-the-agent-loop/docs/en.md and enforced through reusable skill artifacts like phases/14-agent-engineering/01-the-agent-loop/outputs/skill-agent-loop.md.

Summary

  • The curriculum follows a strict MOTTO → PROBLEM → CONCEPT → BUILD IT → USE IT → SHIP IT pattern across 503 lessons
  • Build It requires implementing algorithms from scratch using only standard libraries to understand underlying mechanics
  • Use It substitutes production frameworks while preserving the original logic structure, revealing abstraction boundaries
  • This methodology enables debugging of library internals and reasoning about performance, security, and stability characteristics

Frequently Asked Questions

What is the six-beat lesson structure in AI Engineering From Scratch?

The six-beat structure follows the sequence MOTTO → PROBLEM → CONCEPT → BUILD IT → USE IT → SHIP IT. Every lesson in the repository adheres to this pattern, with the Build It and Use It phases forming the core technical implementation. This architecture is visualized in the repository's top-level README.md.

How does the Build It phase differ from the Use It phase?

In Build It, students implement algorithms from raw mathematics without high-level frameworks, such as hand-coding a transformer's attention matrix or a ReAct agent loop using only Python's standard library. In Use It, the same algorithm is executed through production libraries like PyTorch or MCP clients, allowing students to see exactly what abstractions the library provides while keeping their core logic unchanged.

Why implement algorithms from scratch before using libraries?

Building first forces deep understanding of underlying mechanics, enabling students to debug library failures, reason about performance and security implications, and extend functionality safely. Without this foundation, developers risk treating frameworks as opaque black boxes and cannot diagnose issues when abstractions leak or models behave unexpectedly.

Where can I find examples of the Build It / Use It methodology in the repository?

Canonical examples reside in phases/14-agent-engineering/01-the-agent-loop/, specifically in code/main.py (Build It) and code/main_mcp.py (Use It). Documentation explaining the split is available in docs/en.md within that directory, and the output skill artifact demonstrating the reusable pattern is stored in outputs/skill-agent-loop.md.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →