Skip to main content

LLM Agents From Scratch

Linting Unit Testing and Upload Coverage codecov DOI GitHub License Ask DeepWiki Open In Studio

The companion library for Build a Multi-Agent System — With MCP and A2A (Manning). Learn how LLM agents work by building one yourself, from first principles, step by step.

Available now through Manning's Early Access Program (MEAP) — buy today and get each chapter as it's completed. Buy the Book →


About

Multi-agent systems and the LLM agents that power them are among the most discussed topics in AI today. There are already many capable frameworks out there — the goal of this book isn't to replace them, but to help you deeply understand how they work by having you build one yourself, from scratch.

All the code lives in the book's own hand-rolled agent framework, primarily designed for educational purposes rather than production deployment. It will give you the foundation to work more confidently with any other LLM agent framework of your choosing, or even to build your own specialised solutions.


From the Book

Each chapter builds on the last, progressively deepening your understanding from core concepts to full multi-agent systems.

Part 1 — Build Your First LLM Agent

Ch Title Notebook
1 What Are LLM Agents and Multi-Agent Systems? —
2 Working with Tools Ch 2
3 Working with LLMs Ch 3
4 The LLM Agent Class Ch 4

Part 2 — Enhance Your LLM Agent

Ch Title Notebook
5 MCP Tools Ch 5
6 Skills Ch 6
7 Memory Ch 7
8 Human in the Loop Ch 8

Part 3 — Building Multi-Agent Systems

Ch Title Notebook
9 Assembling MAS with Subagents Ch 9
10 Assembling Interoperable MAS with A2A Ch 10

Capstone Projects

Capstones are larger, end-to-end projects that pull together what you have built in the book and apply it to something closer to a real-world system.

Capstone Description Notebook
Monte Carlo Estimation of Pi Orchestrate parallel tool calls to estimate π using the Monte Carlo method. Open
Deep Research Agent Coming soon. —
OpenClaw Personal Assistant Coming soon. —

Running the Notebooks

The chapter notebooks use Qwen3:14B as the default model via Ollama. Minimum hardware: ~16 GB RAM with a discrete GPU, or any machine with a dedicated GPU that can comfortably run a 14B model. You can swap in a smaller model (e.g. qwen3:4b), but note that smaller models may not follow tool-use instructions reliably — especially in later chapters.

Option A — Run locally

Install Ollama and pull the model:

ollama pull qwen3:14b

Then launch Jupyter from the project root:

uv run --with jupyter jupyter lab

Lightning AI offers a free tier with ~22 GPU compute hours/month — enough for several sessions on an L4 GPU.

  1. Create a free Lightning AI account if you don't have one
  2. Visit the book template: lightning.ai/nerdai/templates/build-a-multi-agent-system-from-scratch
  3. Click Clone to copy it to your account
  4. Make sure you have the latest version of the template
  5. Launch the Studio with an L4 GPU
  6. Open the chapter notebook you want to run and execute the cells — Ollama and the required model are already set up in the template

Getting Started

Prerequisites

  • Python 3.10+
  • Ollama running locally (used as the default LLM backend)
  • uv for dependency management

Installation

Clone the repository:

# SSH
git clone git@github.com:nerdai/llm-agents-from-scratch.git

# HTTPS
git clone https://github.com/nerdai/llm-agents-from-scratch.git

cd llm-agents-from-scratch

Install dependencies:

uv sync --all-extras --dev

Quick Start

from llm_agents_from_scratch.llms import OllamaLLM
from llm_agents_from_scratch.agent import LLMAgentBuilder
from llm_agents_from_scratch.tools import SimpleFunctionTool

def add(a: int, b: int) -> int:
    return a + b

llm = OllamaLLM(model="llama3.2")
tool = SimpleFunctionTool(fn=add)

agent = (
    LLMAgentBuilder()
    .with_llm(llm)
    .with_tools([tool])
    .build()
)

result = await agent.run("What is 3 + 5?")
print(result)

Development

# Run all tests
make test

# Lint and format
make lint
make format

# Coverage report
make coverage-report

See CLAUDE.md for full development guidance.


Contributing

Bug reports, feature requests, and community project submissions are welcome. See CONTRIBUTING.md for details.


License

Apache 2.0 — see LICENSE for details.

Metadata

Release files for llm-agents-from-scratch 0.0.24

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-agents-from-scratch 0.0.24
File Size Uploaded
llm_agents_from_scratch-0.0.24.tar.gz 2.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-agents-from-scratch 0.0.24
File Interpreter ABI Platform
llm_agents_from_scratch-0.0.24-py3-none-any.whl Python 3 none any Details

Total release size: 2.5 MB

Release files / llm_agents_from_scratch-0.0.24.tar.gz

Download URL llm_agents_from_scratch-0.0.24.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
5cb862f30faa19f6c620480137251ada55f0b70472f3465fd4794127d9cb1b1d
BLAKE2b-256 checksum
How to use checksums
6ecf26bfd24bac2f286ad2d72f8c64ac50d6cee7727b0caaf13015ab7ed18b07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / llm_agents_from_scratch-0.0.24-py3-none-any.whl

Download URL llm_agents_from_scratch-0.0.24-py3-none-any.whl
Size 118.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cc88934d5efd3f7de427b65822620304472d9d08165f468cf71f702774097f5
BLAKE2b-256 checksum
How to use checksums
1a0381f28fa660f7710febfd855fd6a46f4fedc60b6ed2135696b374718a2e11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.0.25

2 release files

This release

0.0.24 This release

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page