pguso/ai-agents-from-scratch
Build local JavaScript agents from GGUF inference to tools, memory, and ReAct
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
This is a set of runnable JavaScript examples, not a shared agent runtime. The main path starts with node-llama-cpp loading a local GGUF model and progresses from prompt and response to application-owned function handlers. Tool parameters are declared with JSON Schema. The memory example brings retrieved facts and preferences from earlier sessions back into context; ReAct adds a loop that feeds tool observations into the next step.
The manifest contains three dependencies: node-llama-cpp, openai, and dotenv. The OpenAI SDK is used in a separate, optional hosted inference example, not presented as a drop-in backend for every workflow. The integration points are the example scripts and their tool definitions. In particular, helper/prompt-debugger.js lets you inspect what actually reaches the model, including system prompts, function definitions, history, and context state.
Key Capabilities & Differentiators
The examples cover system-prompt specialization, streaming with token limits, and batching across context sequences. At the orchestration layer, Atom of Thought produces structured plans with atomic operations and dependencies for validation and deterministic execution. Tree of Thought uses code-defined scoring to rank and prune branches in a beam search. Graph of Thought extracts from independent sources in parallel, resolves conflicts before drafting, and checks the result against explicit constraints.
The later examples also show phased evidence extraction and policy decisions with separate internal and customer-facing outputs, plus typed errors, timeouts, retries with backoff and jitter, and deterministic tool fallback. Embedding-based routing compares requests with tool exemplars using cosine similarity and passes only the top-k tools, plus any pinned tools, to session.prompt. That can shrink the tool definitions in context, but a low k can hide a needed tool on a multi-intent request.
Trade-offs & Limitations
Compared with a production-oriented agent framework, these scripts trade reusable orchestration and integrations for visibility into prompts, tool calls, state updates, and control flow. That is useful when those mechanics are what you want to learn or test. It's less useful when you need a service: you'll need to define tool permissions and isolation, govern persistent state, and build operational monitoring. The error-handling example is a reference implementation, not a runtime-wide reliability guarantee.
Local inference avoids per-request hosted inference charges and keeps the prompt on the local inference path, but puts model setup and resource sizing on the operator; it does not guarantee that tools or debug output stay local. Hosted inference moves model execution off the machine in exchange for network latency, token costs, and provider data-handling requirements. The code is MIT-licensed, but downloaded models have separate terms.
Hardware & Deployment Guide
For a local run, use Node.js 18 or newer, run npm install, and place the required GGUF files in ./models/ following DOWNLOAD.md. From the repository root, start with node examples/01_intro/intro.js; the ReAct entry point is node examples/09_react-agent/react-agent.js. The project lists at least 8 GB of system RAM and recommends 16 GB. Actual memory demand depends on the model, quantization, context length, concurrent sequences, and CPU/GPU placement; no fixed VRAM requirement is given.
Once the required files and dependencies are installed, the local inference path does not need a hosted inference endpoint. The optional OpenAI example requires API access and connectivity. The delivery path is a local Node process, not a packaged service or container deployment. No GitHub release is listed; the later numbered examples show the curriculum extending into recovery, structured planning and search, and embedding-based routing, not a tagged release history.
node-llama-cpp, with a separate optional OpenAI SDK example.helper/prompt-debugger.js exposes system prompts, function definitions, conversation history, and context state.examples/08_simple-agent-with-memory/, and a separate ReAct loop make each layer inspectable.examples/11_error-handling/ demonstrates typed errors, timeouts, backoff with jitter, deterministic fallback, and correlation IDs.JavaScript engineers learning agent internals or prototyping a local workflow where they need to inspect prompts, tool choices, and state transitions.
You need a drop-in production runtime with managed integrations, tool isolation, and service operations, or only need a direct hosted model call.
Quick Start & Installation
npm installComparison vs. Top Agents & Frameworks Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| ai-agents-from-scratch ★ | 4.9k | +6 | JavaScript | MIT | Build local JavaScript agents from GGUF inference to tools, memory, and ReAct |
| agentscope | 37.2k | +322 | Python | Apache-2.0 | Python ReAct SDK and FastAPI service for observable, interruptible agent workflo |
| browser-use | 122.7k | +477 | Python | MIT | Python REPL and CDP for adaptive browser automation |
| ag-ui | 22.6k | +611 | TypeScript | MIT | A typed event protocol and SDKs that connect agent backends to interactive apps |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/pguso/ai-agents-from-scratch.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about ai-agents-from-scratch
How do I integrate a custom tool and inspect what the model receives?
examples/07_simple-agent/simple-agent.js for JSON Schema tool parameters and examples/09_react-agent/react-agent.js for an iterative tool loop. Adapt the examples as source code rather than assuming a stable plugin API. Use helper/prompt-debugger.js to inspect the rendered prompt, tool definitions, and conversation context; keep sensitive inputs out of shared debug output.What hardware do I need for local GGUF inference?
Can I use the code commercially or run it in a restricted environment?
When is this a better choice than an agent framework or a direct API call?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy