Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
> **Read the full interactive version:**
|
| 2 |
-
> 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
|
| 3 |
>
|
| 4 |
-
>
|
| 5 |
>
|
| 6 |
> If you prefer **long-form explanations, diagrams, and conceptual deep dives**, start there - then come back here to explore the code.
|
| 7 |
|
|
@@ -38,7 +47,7 @@ Learn AI product development fundamentals with local LLMs. Covers prompt enginee
|
|
| 38 |
## Next Phase: Build LangChain & LangGraph Concepts From Scratch
|
| 39 |
|
| 40 |
> 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.
|
| 41 |
-
> This is **not** about building a new framework, it
|
| 42 |
|
| 43 |
## Phase 1: Agent Fundamentals - From LLMs to ReAct
|
| 44 |
|
|
@@ -170,7 +179,7 @@ Follow these examples in order to build understanding progressively:
|
|
| 170 |
`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)
|
| 171 |
|
| 172 |
**What you'll learn:**
|
| 173 |
-
- ReAct pattern (Reason
|
| 174 |
- Iterative problem solving
|
| 175 |
- Step-by-step tool use
|
| 176 |
- Self-correction loops
|
|
@@ -216,52 +225,52 @@ Each example folder contains:
|
|
| 216 |
|
| 217 |
```
|
| 218 |
AI Agent = LLM + System Prompt + Tools + Memory + Reasoning Pattern
|
| 219 |
-
|
| 220 |
-
|
| 221 |
Brain Identity Hands State Strategy
|
| 222 |
```
|
| 223 |
|
| 224 |
### Evolution of Capabilities
|
| 225 |
|
| 226 |
```
|
| 227 |
-
1. intro
|
| 228 |
-
2. translation
|
| 229 |
-
3. think
|
| 230 |
-
4. batch
|
| 231 |
-
5. coding
|
| 232 |
-
6. simple-agent
|
| 233 |
-
7. memory-agent
|
| 234 |
-
8. react-agent
|
| 235 |
```
|
| 236 |
|
| 237 |
### Architecture Patterns
|
| 238 |
|
| 239 |
**Simple Agent (Steps 1-5)**
|
| 240 |
```
|
| 241 |
-
User
|
| 242 |
```
|
| 243 |
|
| 244 |
**Tool-Using Agent (Step 6)**
|
| 245 |
```
|
| 246 |
-
User
|
| 247 |
```
|
| 248 |
|
| 249 |
**Memory Agent (Step 7)**
|
| 250 |
```
|
| 251 |
-
User
|
| 252 |
-
|
| 253 |
Memory
|
| 254 |
```
|
| 255 |
|
| 256 |
**ReAct Agent (Step 8)**
|
| 257 |
```
|
| 258 |
-
User
|
| 259 |
-
|
| 260 |
-
|
| 261 |
Iterate until solved
|
| 262 |
```
|
| 263 |
|
| 264 |
-
##
|
| 265 |
|
| 266 |
### PromptDebugger
|
| 267 |
`helper/prompt-debugger.js`
|
|
@@ -274,53 +283,53 @@ Utility for debugging prompts sent to the LLM. Shows exactly what the model sees
|
|
| 274 |
|
| 275 |
Usage example in `simple-agent/simple-agent.js`
|
| 276 |
|
| 277 |
-
##
|
| 278 |
|
| 279 |
```
|
| 280 |
ai-agents/
|
| 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 |
## Phase 2: Building a Production Framework (Tutorial)
|
|
@@ -348,46 +357,46 @@ A lightweight but complete agent framework with:
|
|
| 348 |
|
| 349 |
```
|
| 350 |
tutorial/
|
| 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 |
src/
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
```
|
| 392 |
|
| 393 |
### Why This Matters
|
|
@@ -407,7 +416,7 @@ src/
|
|
| 407 |
|
| 408 |
### Getting Started with Phase 2
|
| 409 |
|
| 410 |
-
After completing the fundamentals (intro
|
| 411 |
|
| 412 |
[Overview](tutorial/README.md)
|
| 413 |
|
|
@@ -497,8 +506,10 @@ Educational resource - use and modify as needed for learning.
|
|
| 497 |
|
| 498 |
---
|
| 499 |
|
| 500 |
-
**Built with
|
| 501 |
|
| 502 |
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.
|
| 503 |
|
| 504 |
Happy learning!
|
|
|
|
|
|
|
|
|
| 1 |
+
ο»Ώ---
|
| 2 |
+
title: Email Classifier Agent
|
| 3 |
+
emoji: π€
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
app_port: 7860
|
| 9 |
+
---
|
| 10 |
> **Read the full interactive version:**
|
| 11 |
+
> 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.
|
| 12 |
>
|
| 13 |
+
> Γ°ΕΈββ° **https://agentsfromscratch.com**
|
| 14 |
>
|
| 15 |
> If you prefer **long-form explanations, diagrams, and conceptual deep dives**, start there - then come back here to explore the code.
|
| 16 |
|
|
|
|
| 47 |
## Next Phase: Build LangChain & LangGraph Concepts From Scratch
|
| 48 |
|
| 49 |
> 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.
|
| 50 |
+
> This is **not** about building a new framework, itΓ’β¬β’s about understanding *how frameworks work*.
|
| 51 |
|
| 52 |
## Phase 1: Agent Fundamentals - From LLMs to ReAct
|
| 53 |
|
|
|
|
| 179 |
`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)
|
| 180 |
|
| 181 |
**What you'll learn:**
|
| 182 |
+
- ReAct pattern (Reason Γ’β β Act Γ’β β Observe)
|
| 183 |
- Iterative problem solving
|
| 184 |
- Step-by-step tool use
|
| 185 |
- Self-correction loops
|
|
|
|
| 225 |
|
| 226 |
```
|
| 227 |
AI Agent = LLM + System Prompt + Tools + Memory + Reasoning Pattern
|
| 228 |
+
Γ’ββ¬Γ’β¬Òββ¬ Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’β¬Òββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬ Γ’ββ¬Γ’ββ¬Γ’β¬Òββ¬Γ’ββ¬ Γ’ββ¬Γ’ββ¬Γ’β¬Òββ¬Γ’ββ¬Γ’ββ¬ Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’β¬Òββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬
|
| 229 |
+
Γ’ββ Γ’ββ Γ’ββ Γ’ββ Γ’ββ
|
| 230 |
Brain Identity Hands State Strategy
|
| 231 |
```
|
| 232 |
|
| 233 |
### Evolution of Capabilities
|
| 234 |
|
| 235 |
```
|
| 236 |
+
1. intro Γ’β β Basic LLM usage
|
| 237 |
+
2. translation Γ’β β Specialized behavior (system prompts)
|
| 238 |
+
3. think Γ’β β Reasoning ability
|
| 239 |
+
4. batch Γ’β β Parallel processing
|
| 240 |
+
5. coding Γ’β β Streaming & control
|
| 241 |
+
6. simple-agent Γ’β β Tool use (function calling)
|
| 242 |
+
7. memory-agent Γ’β β Persistent state
|
| 243 |
+
8. react-agent Γ’β β Strategic reasoning + tool use
|
| 244 |
```
|
| 245 |
|
| 246 |
### Architecture Patterns
|
| 247 |
|
| 248 |
**Simple Agent (Steps 1-5)**
|
| 249 |
```
|
| 250 |
+
User Γ’β β LLM Γ’β β Response
|
| 251 |
```
|
| 252 |
|
| 253 |
**Tool-Using Agent (Step 6)**
|
| 254 |
```
|
| 255 |
+
User Γ’β β LLM Γ’ΕΈΒ· Tools Γ’β β Response
|
| 256 |
```
|
| 257 |
|
| 258 |
**Memory Agent (Step 7)**
|
| 259 |
```
|
| 260 |
+
User Γ’β β LLM Γ’ΕΈΒ· Tools Γ’β β Response
|
| 261 |
+
Γ’β β’
|
| 262 |
Memory
|
| 263 |
```
|
| 264 |
|
| 265 |
**ReAct Agent (Step 8)**
|
| 266 |
```
|
| 267 |
+
User Γ’β β LLM Γ’β β Think Γ’β β Act Γ’β β Observe
|
| 268 |
+
Γ’β β Γ’β β Γ’β β Γ’β β
|
| 269 |
+
Γ’ββΓ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’β´Òββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’β´Òββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’ββ¬Γ’βΛ
|
| 270 |
Iterate until solved
|
| 271 |
```
|
| 272 |
|
| 273 |
+
## Γ―ΒΈΒ Helper Utilities
|
| 274 |
|
| 275 |
### PromptDebugger
|
| 276 |
`helper/prompt-debugger.js`
|
|
|
|
| 283 |
|
| 284 |
Usage example in `simple-agent/simple-agent.js`
|
| 285 |
|
| 286 |
+
## Γ―ΒΈΒ Project Structure - Fundamentals
|
| 287 |
|
| 288 |
```
|
| 289 |
ai-agents/
|
| 290 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ README.md Γ’β Β You are here
|
| 291 |
+
Γ’βΕΓ’ββ¬ examples/
|
| 292 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 01_intro/
|
| 293 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ intro.js
|
| 294 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 295 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 296 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 02_openai-intro/
|
| 297 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ openai-intro.js
|
| 298 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 299 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 300 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 03_translation/
|
| 301 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ translation.js
|
| 302 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 303 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 304 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 04_think/
|
| 305 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ think.js
|
| 306 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 307 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 308 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 05_batch/
|
| 309 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ batch.js
|
| 310 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 311 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 312 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 06_coding/
|
| 313 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ coding.js
|
| 314 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 315 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 316 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 07_simple-agent/
|
| 317 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ simple-agent.js
|
| 318 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 319 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 320 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 08_simple-agent-with-memory/
|
| 321 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ simple-agent-with-memory.js
|
| 322 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ memory-manager.js
|
| 323 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 324 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 325 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 09_react-agent/
|
| 326 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ react-agent.js
|
| 327 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ CODE.md
|
| 328 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ CONCEPT.md
|
| 329 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ helper/
|
| 330 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ prompt-debugger.js
|
| 331 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ models/ Γ’β Β Place your GGUF models here
|
| 332 |
+
Γ’ββΓ’ββ¬Γ’ββ¬ logs/ Γ’β Β Debug outputs
|
| 333 |
```
|
| 334 |
|
| 335 |
## Phase 2: Building a Production Framework (Tutorial)
|
|
|
|
| 357 |
|
| 358 |
```
|
| 359 |
tutorial/
|
| 360 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 01-foundation/ # 1. Core Abstractions
|
| 361 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 01-runnable/
|
| 362 |
+
Γ’ββ Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ lesson.md # Why Runnable matters
|
| 363 |
+
Γ’ββ Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ exercises/ # Hands-on practice
|
| 364 |
+
Γ’ββ Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ solutions/ # Reference implementations
|
| 365 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 02-messages/ # Structuring conversations
|
| 366 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 03-llm-wrapper/ # Wrapping node-llama-cpp
|
| 367 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ 04-context/ # Configuration & callbacks
|
| 368 |
+
Γ’ββ
|
| 369 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 02-composition/ # 2. Building Chains
|
| 370 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 01-prompts/ # Template system
|
| 371 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 02-parsers/ # Structured outputs
|
| 372 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 03-llm-chain/ # Your first chain
|
| 373 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 04-piping/ # Composition patterns
|
| 374 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ 05-memory/ # Conversation state
|
| 375 |
+
Γ’ββ
|
| 376 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 03-agency/ # 3. Tools & Agents
|
| 377 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 01-tools/ # Function definitions
|
| 378 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 02-tool-executor/ # Safe execution
|
| 379 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 03-simple-agent/ # Basic agent loop
|
| 380 |
+
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ 04-react-agent/ # Reasoning + Acting
|
| 381 |
+
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ 05-structured-agent/ # JSON mode
|
| 382 |
+
Γ’ββ
|
| 383 |
+
Γ’ββΓ’ββ¬Γ’ββ¬ 04-graphs/ # 4. State Machines
|
| 384 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 01-state-basics/ # Nodes & edges
|
| 385 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 02-channels/ # State management
|
| 386 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 03-conditional-edges/ # Dynamic routing
|
| 387 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 04-executor/ # Running workflows
|
| 388 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ 05-checkpointing/ # Persistence
|
| 389 |
+
Γ’ββΓ’ββ¬Γ’ββ¬ 06-agent-graph/ # Agents as graphs
|
| 390 |
|
| 391 |
src/
|
| 392 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ core/ # Runnable, Messages, Context
|
| 393 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ llm/ # LlamaCppLLM wrapper
|
| 394 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ prompts/ # Template system
|
| 395 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ chains/ # LLMChain, SequentialChain
|
| 396 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ tools/ # BaseTool, built-in tools
|
| 397 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ agents/ # AgentExecutor, ReActAgent
|
| 398 |
+
Γ’βΕΓ’ββ¬Γ’ββ¬ memory/ # BufferMemory, WindowMemory
|
| 399 |
+
Γ’ββΓ’ββ¬Γ’ββ¬ graph/ # StateGraph, CompiledGraph
|
| 400 |
```
|
| 401 |
|
| 402 |
### Why This Matters
|
|
|
|
| 416 |
|
| 417 |
### Getting Started with Phase 2
|
| 418 |
|
| 419 |
+
After completing the fundamentals (intro Γ’β β react-agent), start the tutorial:
|
| 420 |
|
| 421 |
[Overview](tutorial/README.md)
|
| 422 |
|
|
|
|
| 506 |
|
| 507 |
---
|
| 508 |
|
| 509 |
+
**Built with Γ’Β€ï¸ for people who want to truly understand AI agents**
|
| 510 |
|
| 511 |
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.
|
| 512 |
|
| 513 |
Happy learning!
|
| 514 |
+
|
| 515 |
+
|