跳过主要内容

AI Agents From Scratch

不用框架、用本地大模型从零手写 AI 智能体的英文教程:15 个 JavaScript 示例,从第一次调用模型到函数调用、记忆、ReAct 和思维树,每课都有代码讲解和概念说明。

访问网站

关于 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.

相似网站

Everything (Puter)

Puter 发起的开源项目,用 MIT 许可从零重写 Excel、Slack、Photoshop、AutoCAD 等商业软件,一个仓库收了 50 多个网页应用,多数可以直接在浏览器里试用。

Vercel

一键部署前端和 Next.js,每次推送都有预览。

Cloudflare

CDN、DNS、Workers、R2 一站式,免费额度非常慷慨。

MDN Web Docs

HTML、CSS、JavaScript 最权威的参考文档。