Skip to main content
Back

Patric's Open-Source Repo Teaches AI Agents From Scratch Without Frameworks

A framework-free, local-first tutorial repo teaching AI agent fundamentals from scratch — 4,300 stars and growing

Pro

Repo, Full Access
  • Framework-free agent curriculum: AI Agents From Scratch teaches 14 progressive lessons using local LLMs and raw JavaScript, no LangChain or CrewAI.
  • Runs fully offline: Uses node-llama-cpp with GGUF models (e.g. Qwen 1.7B); no API keys or cloud costs required, 8GB RAM minimum.
  • Covers the full agent stack: Function calling, persistent memory, ReAct loops, Tree/Graph/Chain of Thought, error handling with retries.
  • Strong community traction: 4,300+ GitHub stars and 628 forks; companion site at agentsfromscratch.com adds visual explanations.
  • Python version available: A Python port lives at github.com/pguso/agents-from-scratch for non-Node users.
  • MIT licensed and actively maintained: Each example ships with CODE.md and CONCEPT.md explaining the what and why of every design choice.

Most agent tutorials start with LangChain. They hand you a high-level abstraction, show you a working demo, and call it a day. The problem: when something breaks, you have no idea why. AI Agents From Scratch takes the opposite approach , no frameworks, no API keys, no cloud costs, just local LLMs and raw JavaScript that exposes every moving part.

The repo has crossed 4,300 stars and 628 forks, with a companion website at agentsfromscratch.com that adds visual explanations and a structured learning path on top of the code.

The problem it actually solves

The author, Patric, describes the frustration clearly: he spent three hours debugging an agent that wouldn't call a tool correctly, never figured it out, and switched frameworks hoping for the best. Without the framework abstractions, he had to figure out everything , how the model actually receives function definitions, what format function calling really uses, how memory works at a fundamental level. That process of rebuilding from zero is exactly what the repo teaches.

The code isn't optimized for performance. It's optimized for understanding. Every example is the minimum viable implementation of one concept, heavily commented, with a paired CODE.md and CONCEPT.md explaining the why behind each decision.

14 lessons, one concept at a time

The material progresses from basic language model interaction to sophisticated multi-step reasoning agents. The learning path is deliberately linear , each example builds on the last, and skipping ahead will leave gaps.

Architecture diagram showing agent system components: user input flows through a central Agent with Memory, LLM reasoning, and Tools modules

Here's the full sequence:

  1. Intro , Load a local model, run a basic prompt, understand the inference pipeline
  2. OpenAI Intro (optional) , Compare local vs. hosted models, understand cost/control tradeoffs
  3. Translation , System prompts, role-based behavior, output format control
  4. Think , Reasoning and problem decomposition, and where pure LLM reasoning hits its limits
  5. Batch , Parallel context sequences, GPU batching, throughput optimization
  6. Coding , Streaming token-by-token output, token budget management
  7. Simple Agent , Function calling: how the LLM decides to invoke tools and what that actually looks like as JSON
  8. Simple Agent with Memory , Persisting facts and preferences across sessions
  9. ReAct Agent , The Reason → Act → Observe loop that underpins most modern agent frameworks
  10. AoT Agent , Atom of Thought: breaking a task into atomic, dependency-ordered operations before executing
  11. Error Handling , Typed error taxonomy, retries with backoff, graceful degradation
  12. Tree of Thought , Generating multiple candidate reasoning branches and pruning with beam search
  13. Graph of Thought , Modeling reasoning as a DAG to merge outputs from parallel sources
  14. Chain of Thought , Splitting high-stakes decisions into explicit, auditable reasoning phases

The key insight: function calling is just structured output

The repo's biggest pedagogical win is demystifying function calling , the mechanism that turns a text generator into an agent that can take actions. This is where text generation becomes agency. In practice, you define a JSON Schema describing a tool, the model returns a JSON object matching that schema, and your code parses it and runs the corresponding function. No magic.

Here's the skeleton of what that looks like in node-llama-cpp:

import { getLlama, LlamaChatSession } from "node-llama-cpp";
const llama = await getLlama();
const model = await llama.loadModel({ modelPath: "./models/Qwen3-1.7B-Q8_0.gguf" });
const context = await model.createContext();
const session = new LlamaChatSession({ contextSequence: context.getSequence() });
// Tool definition passed to the model
const tools = [{
  name: "get_weather",
  description: "Get current weather for a city",
  parameters: {
    type: "object",
    properties: { city: { type: "string" } },
    required: ["city"]
  }
}];
const response = await session.prompt("What's the weather in Berlin?", { tools });
// Model returns: { tool_call: { name: "get_weather", arguments: { city: "Berlin" } } }

Once you see this raw exchange, the entire function-calling API surface of LangChain, CrewAI, or any other framework becomes readable. You know exactly what the abstraction is hiding.

ReAct and beyond

The ReAct pattern , short for Reason + Act , is the loop that powers most production agents. It's the foundation of modern agent frameworks. The agent thinks about what to do, calls a tool, observes the result, and loops until it has an answer. The repo implements this from scratch so you can see the loop explicitly, rather than having it buried inside a framework's internals.

Later lessons push further into advanced reasoning strategies:

  • Tree of Thought generates multiple candidate next steps from the same state, scores them, and keeps only the best branches , a form of beam search applied to reasoning.
  • Graph of Thought models the reasoning process as a directed acyclic graph (DAG), letting independent sub-problems run in parallel before merging their outputs.
  • Atom of Thought decomposes a complex task into a structured JSON plan of atomic operations with explicit dependencies, then executes them deterministically.

What you need to run it

You need Node.js and a GGUF model , the author uses Qwen 1.7B, which runs on modest hardware. No API keys. No cloud costs. The repo recommends at least 8GB of RAM, with 16GB preferred. Models are loaded via node-llama-cpp, a Node.js binding for llama.cpp that can enforce a model to generate output in a parseable format like JSON, or force it to follow a specific JSON schema.

git clone https://github.com/pguso/ai-agents-from-scratch
cd ai-agents-from-scratch
npm install
# Download a GGUF model per DOWNLOAD.md, then:
node examples/01_intro/intro.js
node examples/07_simple-agent/simple-agent.js
node examples/09_react-agent/react-agent.js

A Python port of the tutorial is also available at github.com/pguso/agents-from-scratch for those not working in Node.

Who actually benefits from this

This repo is most useful if you're in one of these situations:

  • You've shipped something with LangChain but can't explain what it's doing internally
  • You want to build a custom agent loop that doesn't fit a framework's assumptions
  • You need to run inference locally for privacy or cost reasons
  • You're onboarding a team to agent development and want a shared mental model
  • You're debugging a production agent and need to understand the underlying protocol

Frameworks are amazing , they let you build complex systems quickly. But if you start with frameworks, you're building on a foundation you don't understand. When you build from scratch, even if it's harder and takes longer, you develop intuition. That's the bet this repo makes, and with over 4,300 stars, it's clearly resonating.