File size: 20,469 Bytes
709049e
 
 
 
 
 
 
 
 
e706de2
709049e
e706de2
709049e
e706de2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709049e
e706de2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709049e
e706de2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709049e
 
e706de2
 
 
 
 
 
709049e
 
 
 
 
 
 
 
e706de2
 
 
 
 
 
709049e
e706de2
 
 
 
709049e
e706de2
 
 
 
709049e
 
e706de2
 
 
 
 
709049e
 
 
e706de2
 
 
709049e
e706de2
 
 
 
 
 
 
 
 
 
 
 
709049e
e706de2
 
 
709049e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e706de2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709049e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e706de2
 
709049e
 
 
 
 
 
 
 
e706de2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709049e
e706de2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709049e
e706de2
 
 
 
709049e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
ο»Ώ---
title: Email Classifier Agent
emoji: πŸ€–
colorFrom: blue
colorTo: indigo
sdk: docker
pinned: false
app_port: 7860
---
> **Read the full interactive version:**  
> This repository is part of **AI Agents From Scratch** - a hands-on learning series where we build AI agents *step by step*, explain every design decision, and visualize whatÒ€ℒs happening under the hood.  
>  

> Γ°ΕΈβ€˜β€° **https://agentsfromscratch.com**  
>  

> If you prefer **long-form explanations, diagrams, and conceptual deep dives**, start there - then come back here to explore the code.


# AI Agents From Scratch

Learn to build AI agents locally without frameworks. Understand what happens under the hood before using production frameworks.

## Purpose

This repository teaches you to build AI agents from first principles using **local LLMs** and **node-llama-cpp**. By working through these examples, you'll understand:

- How LLMs work at a fundamental level
- What agents really are (LLM + tools + patterns)
- How different agent architectures function
- Why frameworks make certain design choices

**Philosophy**: Learn by building. Understand deeply, then use frameworks wisely.

## Related Projects

### [AI Product from Scratch](https://github.com/pguso/ai-product-from-scratch)

[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
[![React](https://img.shields.io/badge/React-20232A?logo=react&logoColor=61DAFB)](https://reactjs.org/)
[![Node.js](https://img.shields.io/badge/Node.js-339933?logo=node.js&logoColor=white)](https://nodejs.org/)

Learn AI product development fundamentals with local LLMs. Covers prompt engineering, structured output, multi-step reasoning, API design, and frontend integration through 10 comprehensive lessons with visual diagrams.

### [AI Agents from Scratch in Python](https://github.com/pguso/agents-from-scratch) 

![Python](https://img.shields.io/badge/Python-3776AB?logo=python&logoColor=white)

## Next Phase: Build LangChain & LangGraph Concepts From Scratch

> After mastering the fundamentals, the next stage of this project walks you through **re-implementing the core parts of LangChain and LangGraph** in plain JavaScript using local models.
> This is **not** about building a new framework, itÒ€ℒs about understanding *how frameworks work*.  

## Phase 1: Agent Fundamentals - From LLMs to ReAct

### Prerequisites
- Node.js 18+
- At least 8GB RAM (16GB recommended)
- Download models and place in `./models/` folder, details in [DOWNLOAD.md](DOWNLOAD.md)

### Installation
```bash

npm install

```

### Run Examples
```bash

node intro/intro.js

node simple-agent/simple-agent.js

node react-agent/react-agent.js

```

## Learning Path

Follow these examples in order to build understanding progressively:

### 1. **Introduction** - Basic LLM Interaction
`intro/` | [Code](examples/01_intro/intro.js) | [Code Explanation](examples/01_intro/CODE.md) | [Concepts](examples/01_intro/CONCEPT.md)

**What you'll learn:**
- Loading and running a local LLM
- Basic prompt/response cycle

**Key concepts**: Model loading, context, inference pipeline, token generation

---

### 2. (Optional) **OpenAI Intro** - Using Proprietary Models
`openai-intro/` | [Code](examples/02_openai-intro/openai-intro.js) | [Code Explanation](examples/02_openai-intro/CODE.md) | [Concepts](examples/02_openai-intro/CONCEPT.md)

**What you'll learn:**
- How to call hosted LLMs (like GPT-4)
- Temperature Control
- Token Usage

**Key concepts**: Inference endpoints, network latency, cost vs control, data privacy, vendor dependence

---

### 3. **Translation** - System Prompts & Specialization
`translation/` | [Code](examples/03_translation/translation.js) | [Code Explanation](examples/03_translation/CODE.md) | [Concepts](examples/03_translation/CONCEPT.md)

**What you'll learn:**
- Using system prompts to specialize agents
- Output format control
- Role-based behavior
- Chat wrappers for different models

**Key concepts**: System prompts, agent specialization, behavioral constraints, prompt engineering

---

### 4. **Think** - Reasoning & Problem Solving
`think/` | [Code](examples/04_think/think.js) | [Code Explanation](examples/04_think/CODE.md) | [Concepts](examples/04_think/CONCEPT.md)

**What you'll learn:**
- Configuring LLMs for logical reasoning
- Complex quantitative problems
- Limitations of pure LLM reasoning
- When to use external tools

**Key concepts**: Reasoning agents, problem decomposition, cognitive tasks, reasoning limitations

---

### 5. **Batch** - Parallel Processing
`batch/` | [Code](examples/05_batch/batch.js) | [Code Explanation](examples/05_batch/CODE.md) | [Concepts](examples/05_batch/CONCEPT.md)

**What you'll learn:**
- Processing multiple requests concurrently
- Context sequences for parallelism
- GPU batch processing
- Performance optimization

**Key concepts**: Parallel execution, sequences, batch size, throughput optimization

---

### 6. **Coding** - Streaming & Response Control
`coding/` | [Code](examples/06_coding/coding.js) | [Code Explanation](examples/06_coding/CODE.md) | [Concepts](examples/06_coding/CONCEPT.md)

**What you'll learn:**
- Real-time streaming responses
- Token limits and budget management
- Progressive output display
- User experience optimization

**Key concepts**: Streaming, token-by-token generation, response control, real-time feedback

---

### 7. **Simple Agent** - Function Calling (Tools)
`simple-agent/` | [Code](examples/07_simple-agent/simple-agent.js) | [Code Explanation](examples/07_simple-agent/CODE.md) | [Concepts](examples/07_simple-agent/CONCEPT.md)

**What you'll learn:**
- Function calling / tool use fundamentals
- Defining tools the LLM can use
- JSON Schema for parameters
- How LLMs decide when to use tools

**Key concepts**: Function calling, tool definitions, agent decision making, action-taking

**This is where text generation becomes agency!**

---

### 8. **Simple Agent with Memory** - Persistent State
`simple-agent-with-memory/` | [Code](examples/08_simple-agent-with-memory/simple-agent-with-memory.js) | [Code Explanation](examples/08_simple-agent-with-memory/CODE.md) | [Concepts](examples/08_simple-agent-with-memory/CONCEPT.md)

**What you'll learn:**
- Persisting information across sessions
- Long-term memory management
- Facts and preferences storage
- Memory retrieval strategies

**Key concepts**: Persistent memory, state management, memory systems, context augmentation

---

### 9. **ReAct Agent** - Reasoning + Acting
`react-agent/` | [Code](examples/09_react-agent/react-agent.js) | [Code Explanation](examples/09_react-agent/CODE.md) | [Concepts](examples/09_react-agent/CONCEPT.md)

**What you'll learn:**
- ReAct pattern (Reason Ò†’ Act Ò†’ Observe)
- Iterative problem solving
- Step-by-step tool use
- Self-correction loops

**Key concepts**: ReAct pattern, iterative reasoning, observation-action cycles, multi-step agents

**This is the foundation of modern agent frameworks!**

---

### 10. **AoT Agent** - Atom of Thought Planning
`aot-agent/` | [Code](examples/10_aot-agent/aot-agent.js) | [Code Explanation](examples/10_aot-agent/CODE.md) | [Concepts](examples/10_aot-agent/CONCEPT.md)

**What you'll learn:**
- Atom of Thought methodology
- Atomic planning for multi-step computations
- Dependency management between operations
- Structured JSON output for reasoning plans
- Deterministic execution of plans

**Key concepts**: AoT planning, atomic operations, dependency resolution, plan validation, structured reasoning

---

## Documentation Structure

Each example folder contains:

- **`<name>.js`** - The working code example
- **`CODE.md`** - Step-by-step code explanation
- Line-by-line breakdowns
- What each part does
- How it works
- **`CONCEPT.md`** - High-level concepts
- Why it matters for agents
- Architectural patterns
- Real-world applications
- Simple diagrams

## Core Concepts

### What is an AI Agent?

```

AI Agent = LLM + System Prompt + Tools + Memory + Reasoning Pattern

           Ò”€Ò”¬Ò”€   Ò”€Ò”€Ò”€Ò”€Ò”€Ò”€Ò”¬Ò”€Ò”€Ò”€Ò”€Ò”€Ò”€   Ò”€Ò”€Ò”¬Ò”€Ò”€   Ò”€Ò”€Ò”¬Ò”€Ò”€Ò”€   Ò”€Ò”€Ò”€Ò”€Ò”€Ò”€Ò”€Ò”€Ò”¬Ò”€Ò”€Ò”€Ò”€Ò”€Ò”€Ò”€Ò”€

            Γ’β€β€š          Γ’β€β€š           Γ’β€β€š       Γ’β€β€š              Γ’β€β€š

         Brain      Identity    Hands   State         Strategy

```

### Evolution of Capabilities

```

1. intro          Ò†’ Basic LLM usage

2. translation    Ò†’ Specialized behavior (system prompts)

3. think          Ò†’ Reasoning ability

4. batch          Ò†’ Parallel processing

5. coding         Ò†’ Streaming & control

6. simple-agent   Ò†’ Tool use (function calling)

7. memory-agent   Ò†’ Persistent state

8. react-agent    Ò†’ Strategic reasoning + tool use

```

### Architecture Patterns

**Simple Agent (Steps 1-5)**
```

User Ò†’ LLM Ò†’ Response

```

**Tool-Using Agent (Step 6)**
```

User Ò†’ LLM Γ’ΕΈΒ· Tools Ò†’ Response

```

**Memory Agent (Step 7)**
```

User Ò†’ LLM Γ’ΕΈΒ· Tools Ò†’ Response

       Ò†‒

     Memory

```

**ReAct Agent (Step 8)**
```

User Ò†’ LLM Ò†’ Think Ò†’ Act Ò†’ Observe

       Γ’β€ β€˜      Γ’β€ β€œ      Γ’β€ β€œ      Γ’β€ β€œ

       Γ’β€β€Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€Β΄Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€Β΄Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€β‚¬Γ’β€Λœ

           Iterate until solved

```

## ️ Helper Utilities

### PromptDebugger
`helper/prompt-debugger.js`

Utility for debugging prompts sent to the LLM. Shows exactly what the model sees, including:
- System prompts
- Function definitions
- Conversation history
- Context state

Usage example in `simple-agent/simple-agent.js`

## ️ Project Structure - Fundamentals

```

ai-agents/

Ò”œÒ”€Ò”€ README.md                          Ò† You are here

Ò”œÒ”€ examples/

Ò”œÒ”€Ò”€ 01_intro/

Γ’β€β€š   Ò”œÒ”€Ò”€ intro.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ 02_openai-intro/

Γ’β€β€š   Ò”œÒ”€Ò”€ openai-intro.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ 03_translation/

Γ’β€β€š   Ò”œÒ”€Ò”€ translation.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ 04_think/

Γ’β€β€š   Ò”œÒ”€Ò”€ think.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ 05_batch/

Γ’β€β€š   Ò”œÒ”€Ò”€ batch.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ 06_coding/

Γ’β€β€š   Ò”œÒ”€Ò”€ coding.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ 07_simple-agent/

Γ’β€β€š   Ò”œÒ”€Ò”€ simple-agent.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ 08_simple-agent-with-memory/

Γ’β€β€š   Ò”œÒ”€Ò”€ simple-agent-with-memory.js

Γ’β€β€š   Ò”œÒ”€Ò”€ memory-manager.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ 09_react-agent/

Γ’β€β€š   Ò”œÒ”€Ò”€ react-agent.js

Γ’β€β€š   Ò”œÒ”€Ò”€ CODE.md

Γ’β€β€š   Ò””Ò”€Ò”€ CONCEPT.md

Ò”œÒ”€Ò”€ helper/

Γ’β€β€š   Ò””Ò”€Ò”€ prompt-debugger.js

Ò”œÒ”€Ò”€ models/                             Ò† Place your GGUF models here

Ò””Ò”€Ò”€ logs/                               Ò† Debug outputs

```

## Phase 2: Building a Production Framework (Tutorial)

After mastering the fundamentals above, **Phase 2** takes you from scratch examples to production-grade framework design. You'll rebuild core concepts from **LangChain** and **LangGraph** to understand how real frameworks work internally.

### What You'll Build

A lightweight but complete agent framework with:
- **Runnable Interface**, The composability pattern that powers everything
- **Message System**, Typed conversation structures (Human, AI, System, Tool)
- **Chains**, Composing multiple operations into pipelines
- **Memory**, Persistent state across conversations
- **Tools**, Function calling and external integrations
- **Agents**, Decision-making loops (ReAct, Tool-calling)
- **Graphs**, State machines for complex workflows (LangGraph concepts)

### Learning Approach

**Tutorial-first**: Step-by-step lessons with exercises  
**Implementation-driven**: Build each component yourself  
**Framework-compatible**: Learn patterns used in LangChain.js

### Structure Overview

```

tutorial/

Ò”œÒ”€Ò”€ 01-foundation/              # 1. Core Abstractions

Γ’β€β€š   Ò”œÒ”€Ò”€ 01-runnable/

Γ’β€β€š   Γ’β€β€š   Ò”œÒ”€Ò”€ lesson.md           # Why Runnable matters

Γ’β€β€š   Γ’β€β€š   Ò”œÒ”€Ò”€ exercises/          # Hands-on practice

Γ’β€β€š   Γ’β€β€š   Ò””Ò”€Ò”€ solutions/          # Reference implementations

Γ’β€β€š   Ò”œÒ”€Ò”€ 02-messages/            # Structuring conversations

Γ’β€β€š   Ò”œÒ”€Ò”€ 03-llm-wrapper/         # Wrapping node-llama-cpp

Γ’β€β€š   Ò””Ò”€Ò”€ 04-context/             # Configuration & callbacks

Γ’β€β€š

Ò”œÒ”€Ò”€ 02-composition/             # 2. Building Chains

Γ’β€β€š   Ò”œÒ”€Ò”€ 01-prompts/             # Template system

Γ’β€β€š   Ò”œÒ”€Ò”€ 02-parsers/             # Structured outputs

Γ’β€β€š   Ò”œÒ”€Ò”€ 03-llm-chain/           # Your first chain

Γ’β€β€š   Ò”œÒ”€Ò”€ 04-piping/              # Composition patterns

Γ’β€β€š   Ò””Ò”€Ò”€ 05-memory/              # Conversation state

Γ’β€β€š

Ò”œÒ”€Ò”€ 03-agency/                  # 3. Tools & Agents

Γ’β€β€š   Ò”œÒ”€Ò”€ 01-tools/               # Function definitions

Γ’β€β€š   Ò”œÒ”€Ò”€ 02-tool-executor/       # Safe execution

Γ’β€β€š   Ò”œÒ”€Ò”€ 03-simple-agent/        # Basic agent loop

Γ’β€β€š   Ò”œÒ”€Ò”€ 04-react-agent/         # Reasoning + Acting

Γ’β€β€š   Ò””Ò”€Ò”€ 05-structured-agent/    # JSON mode

Γ’β€β€š

Ò””Ò”€Ò”€ 04-graphs/                  # 4. State Machines

    Ò”œÒ”€Ò”€ 01-state-basics/        # Nodes & edges

    Ò”œÒ”€Ò”€ 02-channels/            # State management

    Ò”œÒ”€Ò”€ 03-conditional-edges/   # Dynamic routing

    Ò”œÒ”€Ò”€ 04-executor/            # Running workflows

    Ò”œÒ”€Ò”€ 05-checkpointing/       # Persistence

    Ò””Ò”€Ò”€ 06-agent-graph/         # Agents as graphs



src/

Ò”œÒ”€Ò”€ core/                       # Runnable, Messages, Context

Ò”œÒ”€Ò”€ llm/                        # LlamaCppLLM wrapper

Ò”œÒ”€Ò”€ prompts/                    # Template system

Ò”œÒ”€Ò”€ chains/                     # LLMChain, SequentialChain

Ò”œÒ”€Ò”€ tools/                      # BaseTool, built-in tools

Ò”œÒ”€Ò”€ agents/                     # AgentExecutor, ReActAgent

Ò”œÒ”€Ò”€ memory/                     # BufferMemory, WindowMemory

Ò””Ò”€Ò”€ graph/                      # StateGraph, CompiledGraph

```

### Why This Matters

**Understanding beats using**: When you know how frameworks work internally, you can:
- Debug issues faster
- Customize behavior confidently
- Make architectural decisions wisely
- Build your own extensions
- Read framework source code fluently

**Learn once, use everywhere**: The patterns you'll learn (Runnable, composition, state machines) apply to:
- LangChain.js - You'll understand their abstractions
- LangGraph.js - You'll grasp state management
- Any agent framework - Same core concepts
- Your own projects - Build custom solutions

### Getting Started with Phase 2

After completing the fundamentals (intro Ò†’ react-agent), start the tutorial:

[Overview](tutorial/README.md)

```bash

# Start with the foundation

cd tutorial/01-foundation/01-runnable

lesson.md                    # Read the lesson

node exercises/01-*.js           # Complete exercises

node solutions/01-*-solution.js  # Check your work

```

Each lesson includes:
- **Conceptual explanation**, Why it matters
- **Code walkthrough**, How to build it
- **Exercises**, Practice implementing
- **Solutions**, Reference code
- **Real-world examples**, Practical usage

**Time commitment**: ~8 weeks, 3-5 hours/week

### What You'll Achieve

By the end, you'll have:
1. Built a working agent framework from scratch
2. Understood how LangChain/LangGraph work internally
3. Mastered composability patterns
4. Created reusable components (tools, chains, agents)
5. Implemented state machines for complex workflows
6. Gained confidence to use or extend any framework

**Then**: Use LangChain.js in production, knowing exactly what happens under the hood.

---

## Key Takeaways

### After Phase 1 (Fundamentals), you'll understand:

1. **LLMs are stateless**: Context must be managed explicitly
2. **System prompts shape behavior**: Same model, different roles
3. **Function calling enables agency**: Tools transform text generators into agents
4. **Memory is essential**: Agents need to remember across sessions
5. **Reasoning patterns matter**: ReAct > simple prompting for complex tasks
6. **Performance matters**: Parallel processing, streaming, token limits
7. **Debugging is crucial**: See exactly what the model receives

### After Phase 2 (Framework Tutorial), you'll master:

1. **The Runnable pattern**: Why everything in frameworks uses one interface
2. **Composition over configuration**: Building complex systems from simple parts
3. **Message-driven architecture**: How frameworks structure conversations
4. **Chain abstraction**: Connecting prompts, LLMs, and parsers seamlessly
5. **Tool orchestration**: Safe execution with timeouts and error handling
6. **Agent execution loops**: The mechanics of decision-making agents
7. **State machines**: Managing complex workflows with graphs
8. **Production patterns**: Error handling, retries, streaming, and debugging

### What frameworks give you:

Now that you understand the fundamentals, frameworks like LangChain, CrewAI, or AutoGPT provide:
- Pre-built reasoning patterns and agent templates
- Extensive tool libraries and integrations
- Production-ready error handling and retries
- Multi-agent orchestration
- Observability and monitoring
- Community extensions and plugins

**You'll use them better because you know what they're doing under the hood.**

## Additional Resources

- **node-llama-cpp**: [GitHub](https://github.com/withcatai/node-llama-cpp)
- **Model Hub**: [Hugging Face](https://huggingface.co/models?library=gguf)
- **GGUF Format**: Quantized models for local inference

## Contributing

This is a learning resource. Feel free to:
- Suggest improvements to documentation
- Add more example patterns
- Fix bugs or unclear explanations
- Share what you built!

## License

Educational resource - use and modify as needed for learning.

---

**Built with ҝ€ï¸ for people who want to truly understand AI agents**

Start with `intro/` and work your way through. Each example builds on the previous one. Read both CODE.md and CONCEPT.md for full understanding.

Happy learning!