Build AI agents from scratch so frameworks finally make sense
A progressive tutorial that forces you to build AI agents by hand so frameworks stop feeling like magic.

What it does
This repository is a curriculum of fifteen runnable JavaScript examples that walk you from loading a local LLM all the way up to ReAct agents, memory systems, and embedding-based tool routing. It uses node-llama-cpp to keep inference on-machine, and every example includes a CODE.md for line-by-line breakdowns and a CONCEPT.md for the architectural idea. A companion website provides the mental-model map while the repo supplies the terrain you actually run.
The interesting bit
Rather than hiding function calling or reasoning loops behind library sugar, each example exposes the raw prompt construction, JSON schema negotiation, and token streaming so you can see the exact moment text generation becomes agency. The progression is deliberately pedagogical: you start with a basic prompt/response cycle and end with beam search over reasoning branches.
Key highlights
- Runs fully offline via
node-llama-cpp; local model weights required (8 GB RAM minimum, 16 GB recommended). - Fifteen progressive examples covering ReAct, AoT, Chain/Tree/Graph of Thought, persistent memory, typed error taxonomies, and embedding-based tool routing.
- Every example ships with line-by-line code explanations (
CODE.md) and high-level pattern guides (CONCEPT.md). - Includes a companion website for learning-path visualization and conceptual explanations, kept separate from the executable code.
- A Python sibling repository exists if you prefer that ecosystem.
Caveats
- Model binaries are not included; you must download and place them in a
./models/directory before anything runs. - One early example can call OpenAI endpoints, but the core learning path is entirely local.
- Local inference demands real hardware: the README lists 8 GB RAM as the floor and 16 GB as the practical minimum.
Verdict
Reach for this if you want to understand agent internals before adopting a framework, or if you are designing curriculum around local LLMs. Look elsewhere if you need a drop-in production framework today.
Frequently asked
- What is pguso/ai-agents-from-scratch?
- A progressive tutorial that forces you to build AI agents by hand so frameworks stop feeling like magic.
- Is ai-agents-from-scratch open source?
- Yes — pguso/ai-agents-from-scratch is open source, released under the MIT license.
- What language is ai-agents-from-scratch written in?
- pguso/ai-agents-from-scratch is primarily written in JavaScript.
- How popular is ai-agents-from-scratch?
- pguso/ai-agents-from-scratch has 4.4k stars on GitHub.
- Where can I find ai-agents-from-scratch?
- pguso/ai-agents-from-scratch is on GitHub at https://github.com/pguso/ai-agents-from-scratch.