Manning · Early Access
Build a Multi-Agent System From Scratch¶
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.
MEAP
About the Book¶
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.
The LLMAgent you build through the book: a backbone LLM, a set of tools, and a single .run() method to kick it all off.
The Learning Path¶
Each chapter builds on the last, progressively deepening your understanding from core concepts to full multi-agent systems. Every chapter from 2 onward has a companion notebook.
The book's learning arc: build the foundations in Part 1, extend your agent in Part 2, and connect agents into a full MAS in Part 3.
Part 1
Build Your First LLM Agent¶
Start from scratch. Understand what LLM agents and MAS really are, build
tools with SimpleFunction and PydanticFunction, integrate a local Ollama
LLM, and assemble the full LLMAgent class.
- 1 What Are LLM Agents and Multi-Agent Systems?
- 2 Working with Tools
- 3 Working with LLMs
- 4 The LLM Agent Class
Part 2
Enhance Your LLM Agent¶
Extend your agent with MCP Tools, composable Skills, short- and long-term Memory, and Human-in-the-Loop patterns, with each chapter adding a new capability on top of what you already built.
- 5 MCP Tools
- 6 Skills
- 7 Memory
- 8 Human in the Loop
Part 3
Build Multi-Agent Systems¶
Connect multiple LLM agents into a collaborative MAS. Start by delegating work to Subagents, then connect independent agents over the Agent2Agent (A2A) protocol so they can communicate, coordinate, and act together.
Running the notebooks
The notebooks are meant to run from a clone of this repository, since
Chapters 6 to 10 read files from their chapter folder, such as the
.agents folder that holds their skills. From the repository root,
launch Jupyter with uv run --with jupyter jupyter lab. Each notebook's
setup section covers choosing an LLM, including Ollama Cloud.
- Windows: clone with symlink support
(
git clone -c core.symlinks=true, with Developer Mode on), or copychapter-notebooks/shared/.agentsinto each chapter folder. - Google Colab: clone the repository in the notebook with
!git clone https://github.com/nerdai/llm-agents-from-scratch,%cdinto the chapter folder, install from PyPI, and setos.environ["OLLAMA_API_KEY"], since Colab has no local Ollama server.
More Examples¶
A selection of additional worked examples showing the framework applied to real integrations. Each explores a different use case you can adapt for your own projects.
GitHub MCP¶
Walk through connecting the agent to the official GitHub MCP server. Discover its available tools and run a simple query — a hands-on look at real-world MCP integration.
GoodNews MCP¶
Connect to the GoodNews MCP server to get good news delivered straight to your LLM agent.
With and Without Skills¶
See exactly what skills buy you: the same word-frequency task run with and without a skill, showing the difference in reusability and caller effort.
Skills Marketplace¶
Discover a third-party skill on the SkillsMP marketplace, install it in one cell, and have the agent generate an animated Slack GIF — no manual prompt engineering required.
Episodic Memory¶
Run three Pokémon lookups, then ask a synthesis question — the agent answers from recalled episodes without calling any tools. A second agent instance points at the same JSONL file and picks up all prior episodes from disk.
HumanInputTool Inside a Skill¶
A meeting-notes-summarizer skill that asks the operator two constrained
questions — format and detail level — before producing its output. Shows
that HITL can be embedded in a skill, not just wired at the agent level.
Supervised Trajectories¶
Step through two SupervisedTaskHandler trajectories: a reject-and-revise
cycle where the human sends feedback and the agent corrects its output, and
an abort that terminates mid-execution with a clean error.
Similarity Memory¶
Look up seven countries across four regions, then run two targeted queries. Each query recalls only the semantically relevant episodes — Southeast Asia for one, Western Europe for the other — showing exactly when vector search beats a simple recency strategy.
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.
Monte Carlo Estimation of Pi¶
Orchestrate parallel tool calls to estimate π using the Monte Carlo method.
A great first capstone that exercises the full LLMAgent class.
Revisiting Monte Carlo Estimation of Pi¶
Estimate the standard error of Capstone I's algorithm by running it 20 times. Chapter 9's subagents each run one estimate in a fresh context, and the capstone measures what that buys over a single agent.
Coming soon
Evaluating MAS and Single-Agent Systems¶
A reusable method for judging when a multi-agent system earns its extra cost over a single agent.
Coming soon
Peer-to-Peer MAS¶
Agents that are both A2A clients and servers, working through a shared task list as a team.
Coming soon
Graph Engineering with Subagents and A2A Agents¶
A workflow graph with branch points that mixes subagents and A2A peers.
Community¶
The framework is open source and built to be extended. Have you built a new tool integration, a custom agent, or an interesting notebook? Share it with other readers. A dedicated community showcase page is in the works.