Skip to main content

Build an LLM agent, equipped with MCP, from scratch.

Project description

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 Multi-Agent Systems with Agent2Agent

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

Option B — Lightning AI (recommended if you don't have a GPU)

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_agents_from_scratch-0.0.20.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_agents_from_scratch-0.0.20-py3-none-any.whl (76.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_agents_from_scratch-0.0.20.tar.gz.

File metadata

  • Download URL: llm_agents_from_scratch-0.0.20.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for llm_agents_from_scratch-0.0.20.tar.gz
Algorithm Hash digest
SHA256 a1aae0f1bcc2d8c6537d33c7df428e5795789d4be1ac878edb291f421bbfaacd
MD5 f6f5d697f48cae4af07e97a1b5688b4a
BLAKE2b-256 cb69df68a2c05ab348a9f129964f5e98e68c5309efb2639721ca7eececfd6da5

See more details on using hashes here.

File details

Details for the file llm_agents_from_scratch-0.0.20-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_agents_from_scratch-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 cdac16d2c43534f9a1a92fe5d9e6fed298361edf419721edd4bfae7362d09c35
MD5 0012f853f7e9da7f01989b3c41cc2de0
BLAKE2b-256 4554140550aab2ff2d4763b4ed73da826983ea101596be52277786a9757b8e34

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page