Email / tutorial /README.md
lenzcom's picture
Upload folder using huggingface_hub
e706de2 verified

AI Agents Framework Tutorial

Welcome to the step-by-step tutorial for building your own AI agent framework!

This tutorial teaches you to build a lightweight, educational version of LangChain.js - with the same core concepts and API, but simpler implementations designed for learning.

Instead of diving into LangChain's complex codebase, you'll rebuild its key patterns yourself with clear, educational code. By the end, you'll understand what frameworks are actually doing, making you far more effective at using them.

What you'll implement:

  • Runnable interface (LangChain's composability pattern)
  • Message types (structured conversations)
  • LLM wrappers (model integration)
  • Chains (composing operations)
  • Agents (decision-making loops)
  • Graphs (LangGraph state machines)

What makes this different:

  • LangChain-compatible API (what you learn transfers directly)
  • Simpler implementations (much less code, same concepts)
  • Educational focus (understanding over completeness)
  • Real, working code (not pseudocode or toys)

Build it yourself. Understand it deeply. Use LangChain confidently.

Learning Paths

Before You Start: Why This Tutorial Exists

You've just built AI agents with node-llama-cpp. You know how to call LLMs, format prompts, parse responses, and create agent loops. That's awesome—you understand the fundamentals!

But you probably noticed some friction:

  • Copy-pasting prompt formatting everywhere
  • Manually building message arrays each time
  • Hard to test individual components
  • Difficult to swap out models or reuse patterns
  • Agent code that works but feels messy

This tutorial fixes those problems. Instead of jumping straight into LangChain's complex codebase, you'll rebuild its core patterns yourself with clear, educational code. You'll transform the script-style code you wrote into clean, composable abstractions.

The approach:

  1. Start with problems you've already encountered
  2. Build the abstraction that solves each problem
  3. See how it connects to LangChain's API
  4. Understand frameworks deeply, use them confidently

Part 1: From Scripts to Abstractions

Transform the patterns you already use into reusable components.

What you'll solve:

  • Agent code getting messy? → Build the Runnable pattern for composability
  • Message formatting tedious? → Create Message types for structure
  • Model switching hard? → Design LLM wrappers for flexibility
  • Managing conversation state? → Implement Context for memory

Lessons:

Part 2: Composition

Dive deeper into prompt engineering and chain complex operations together.

What you'll solve:

  • Copy-pasting prompts everywhere? → Build reusable PromptTemplates with variables
  • Need structured LLM outputs? → Create OutputParsers for reliable data extraction
  • Repeating prompt + LLM patterns? → Design LLMChain to compose operations
  • Want to chain operations together? → Use piping to connect Runnables
  • LLM forgets conversation history? → Implement Memory for context persistence

Lessons:

  • 01-prompts - Template-based prompt engineering
  • 02-parsers - Structured output extraction
  • 03-llm-chain - Composing prompts with models - Coming soon
  • 04-piping - Building data transformation pipelines - Coming soon
  • 05-memory - Persistent conversation history - Coming soon

Part 3: Agents [Coming Soon]

Agents and tools

Part 4: Graphs [Coming Soon]

State machines and workflows

Capstone Projects

Complete these capstone projects to solidify your learning:

How to Use This Tutorial

  1. Start with Part 1 and work sequentially
  2. Read the markdown lessons
  3. Complete the exercises
  4. Check solutions when stuck
  5. Build the projects

Happy learning! 🚀