Skip to main content

AI Agents From Scratch

Build AI agents from first principles in JavaScript with local LLMs and no frameworks: 15 runnable lessons from a first prompt to tools, memory, ReAct and Tree of Thought, each explained.

Visit website

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:

  1. Intro: load a local model and run a first prompt.
  2. OpenAI intro (optional): the same with a hosted model, plus temperature and token usage.
  3. Translation: system prompts and role-based behaviour.
  4. Think: reasoning tasks, and where pure LLM reasoning falls short.
  5. Batch: parallel requests with context sequences.
  6. Coding: streaming output and token limits.
  7. Simple agent: function calling with JSON Schema tools, where text generation becomes agency.
  8. Agent with memory: facts and preferences that persist across sessions.
  9. ReAct agent: the reason, act, observe loop behind most agent frameworks.
  10. AoT agent: Atom of Thought planning with structured JSON plans.
  11. Error handling: retries with backoff, timeouts, fallbacks and typed errors.
  12. Tree of Thought: beam search over reasoning branches.
  13. Graph of Thought: merging several sources through a DAG.
  14. Chain of Thought: auditable, step-by-step decisions.
  15. 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.

Similar sites

Everything (Puter)

Puter's MIT-licensed monorepo of 50+ open-source web apps rebuilding Excel, Slack, Photoshop, AutoCAD, Salesforce and more, most with a live demo you can try in the browser.

Vercel

Deploy frontends and Next.js apps with previews on every push.

Cloudflare

CDN, DNS, Workers and R2 with an unusually generous free tier.

MDN Web Docs

The most reliable reference for HTML, CSS and JavaScript.