# Repository Briefing: pguso/ai-agents-from-scratch
> Source: https://repoforai.com/repo/pguso/ai-agents-from-scratch (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/pguso/ai-agents-from-scratch
- **Category**: Agents & Frameworks (智能体与框架)
- **Primary Language**: JavaScript
- **License**: MIT
- **Engineering Health**: B (60/100 · Maintenance 12/35 · Adoption 22/25 · Releases 6/20 · License 20/20)
- **Review Snapshot**: 2026-12-02
- **Deployment / Stack Signals**: Local AI, CLI
- **Momentum**: 4,930 ★ total (+0 24h / +6 7d) · 714 forks
- **Topics**: `ai-agents`, `educational`, `function-calling`, `llm`, `llm-agent`, `node-llama-cpp`, `react-agent`, `tutorial`
- **When to Use**: Best for: JavaScript engineers learning agent internals or prototyping a local workflow where they need to inspect prompts, tool choices, and state transitions. Skip if: You need a drop-in production runtime with managed integrations, tool isolation, and service operations, or only need a direct hosted model call.

## Overview
```text
### Architecture & 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.
```

## Key Capabilities
```text
- Local runtime: JavaScript examples load GGUF models through `node-llama-cpp`, with a separate optional OpenAI SDK example.
- Prompt visibility: `helper/prompt-debugger.js` exposes system prompts, function definitions, conversation history, and context state.
- Agent state: JSON Schema tool definitions, cross-session memory in `examples/08_simple-agent-with-memory/`, and a separate ReAct loop make each layer inspectable.
- Planning and search: AoT validates atomic operations and dependencies; Tree of Thought ranks and prunes a beam; Graph of Thought merges parallel extracts before drafting.
- Resilience: `examples/11_error-handling/` demonstrates typed errors, timeouts, backoff with jitter, deterministic fallback, and correlation IDs.
- Tool routing: Cosine similarity over embedded exemplar phrases selects top-k tools, with optional always-include entries and an explicit multi-intent recall caveat.
```

## Quick Start / Clone
```bash
npm install
```
