About AI Agents From Scratch
AI Agents From Scratch is an English, hands-on tutorial by Patric Gutersohn (pguso) that teaches you how AI agents work by building them yourself, before you reach for LangChain or another framework. Everything runs on your own machine with local GGUF models through node-llama-cpp, so there is no API bill and nothing is hidden behind a library.
The core idea is spelled out in the README: an agent is an LLM plus a system prompt, tools, memory and a reasoning pattern. The lessons add those pieces one at a time.
The learning path
As of October 2026 there are 15 numbered examples:
- Intro: load a local model and run a first prompt.
- OpenAI intro (optional): the same with a hosted model, plus temperature and token usage.
- Translation: system prompts and role-based behaviour.
- Think: reasoning tasks, and where pure LLM reasoning falls short.
- Batch: parallel requests with context sequences.
- Coding: streaming output and token limits.
- Simple agent: function calling with JSON Schema tools, where text generation becomes agency.
- Agent with memory: facts and preferences that persist across sessions.
- ReAct agent: the reason, act, observe loop behind most agent frameworks.
- AoT agent: Atom of Thought planning with structured JSON plans.
- Error handling: retries with backoff, timeouts, fallbacks and typed errors.
- Tree of Thought: beam search over reasoning branches.
- Graph of Thought: merging several sources through a DAG.
- Chain of Thought: auditable, step-by-step decisions.
- Tool routing: using embeddings to pass only the relevant tools to the model.
Each folder holds the runnable .js file, a CODE.md that walks through the code line by line, and a CONCEPT.md on the idea behind it. A small prompt debugger shows exactly what the model receives.
Getting started
You need Node.js 18+ and at least 8 GB of RAM (16 GB recommended). Download a model into ./models/ as described in the repo, run npm install, then node any example in order.
Companion site and Python version
- agentsfromscratch.com: an interactive companion that maps the learning path and explains each concept. The author calls the site the map and the repo the terrain.
- agents-from-scratch: a Python version of the tutorial.
Who it's for
Developers who can read JavaScript and want a real mental model of function calling, memory and ReAct, rather than learning a framework's API first.
License and related
MIT, with about 4.9k GitHub stars as of October 2026. If you would rather learn the framework route in Chinese, from LangChain and LangGraph to Dify, RAG and full projects, see AI Agents From Zero.
