Skip to content

This repository provides the companion Jupyter Notebooks for the book Context-Engineering for Multi-Agent Systems. It technically details the progressive construction of a Context Engine moving from simple prompts to foundational concepts to a production-ready system semantic blueprint. The code is a guide to building Multi-Agent Systems (MAS)

License

Notifications You must be signed in to change notification settings

Denis2054/Context-Engineering-for-Multi-Agent-Systems

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Context Engineering for Multi-Agent Systems, First Edition

This is the code repository for Context Engineering for Multi-Agent Systems, First Edition, published by Packt.

Last updated: November 18, 2025.

See the Changelog for updates, fixes, and upgrades.

LLM API update: Specific notebooks have been upgraded to leverage GPT-5.1 and the latest OpenAI library standards for improved performance and reasoning latency when necessary. This update also includes fixes for the Moderation API to handle structured agent outputs robustly. For specific details on the affected notebooks and a full list of changes, please consult the Changelog.

Move beyond prompting to build a Context Engine, a transparent architecture of context and reasoning

Denis Rothman

      Free PDF       Graphic Bundle       Amazon      

About the book

Context Engineering  for Multi-Agent Systems, First Edition

Generative AI is powerful, yet often unpredictable. This guide shows you how to turn that unpredictability into reliability by thinking beyond prompts and approaching AI like an architect. At its core is the Context Engine, a glass-box, multi-agent system you’ll learn to design, strengthen, and apply across real-world scenarios. Written by an AI guru and author of various cutting-edge AI books, this book takes you on a hands-on journey from the foundations of context design to building a fully operational Context Engine. Instead of relying on brittle prompts that give only simple instructions, you’ll begin with semantic blueprints that map goals and roles with precision, then orchestrate specialized agents using the Model Context Protocol (MCP). As the engine evolves, you’ll integrate memory and high-fidelity retrieval with citations, implement safeguards against data poisoning and prompt injection, and enforce moderation to keep outputs aligned with policy. You’ll also harden the system into a resilient architecture, then see it pivot seamlessly across domains, from legal compliance to strategic marketing, proving its domain independence. By the end of this book, you’ll be equipped with the skills needed to engineer an adaptable, verifiable architecture you can repurpose across domains and deploy with confidence.

Key Learnings

  • Develop memory models to retain short-term and cross-session context
  • Craft semantic blueprints and drive multi-agent orchestration with MCP
  • Implement high-fidelity RAG pipelines with verifiable citations
  • Apply safeguards against prompt injection and data poisoning
  • Enforce moderation and policy-driven control in AI workflows
  • Repurpose the Context Engine across legal, marketing, and beyond
  • Deploy a scalable, observable Context Engine in production

Chapters

Chapters Colab Kaggle Studio Lab
Chapter 1: From Prompts to Context: Building the Semantic Blueprint
  • SLR.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
  • Use_Case.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 2: Building a Multi-Agent System with MCP
  • MAS_MCP.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
  • MAS_MCP_control.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 3: Building the Context-Aware Multi-Agent System
  • RAG_Pipeline.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
  • Context_Aware_MAS.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 4: Assembling the Context Engine
  • Context_Engine.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 5: Hardening the Context Engine
  • Context_Engine_MAS_MCP.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
  • Context_Engine_Pre_Production.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 6: Building the Summarizer Agent for Context Reduction
  • Context_Engine_Content_Reduction.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 7: High-Fidelity RAG and Defense: The NASA-Inspired Research Assistant
  • High_Fidelity_Data_Ingestion.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
  • NASA_Research_Assistant_and_Retrocompatibility.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 8: Architecting for Reality: Moderation, Latency, and Policy-Driven AI
  • Data_Ingestion.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
  • Legal_assistant_Explorer.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 9: Architecting for Brand and Agility: The Strategic Marketing Engine
  • Data_Ingestion_Marketing.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
  • Marketing_Assistant.ipynb
Open In Colab
Open In Kaggle
Open In Studio Lab
Chapter 10: The Blueprint for Production-Ready AI
Context Engineering Production Blueprint

Requirements for this book

Before running the code, ensure your development environment is properly set up. All hands-on chapters use reproducible Python-based environments, tested in Google Colab and VS Code.

A Note on Latency: The Context Engine built in this book and repository performs complex, multi-step reasoning, not simple, single-shot answers. The delay you observe in Colab is the "thinking" time, as the engine dynamically plans and executes a sequence of API calls (e.g., planning, then RAG, then generation). This is the same reason advanced platforms like Gemini or ChatGPT require a moment to "think" for complex requests, even though they benefit from significantly more powerful environments.

βœ… Prerequisites

  • Python: Version 3.10+
  • Environment Options:
    • Google Colab or
    • Local Python environment with:
      • openai
      • pinecone-client
      • tiktoken
      • tenacity
      • fastapi

πŸš€ Quick Start

Get up and running using cloud-based virtual machines using the Google Colab links provided for each notebook.
No local installation is required.

1. Get Your API Keys

Before running the notebooks, you will need valid API keys for the underlying services:

2. Run the Notebooks

Click the badges below to launch the notebooks directly in a pre-configured Google Colab VM. You will be asked to add your API keys to the Colab Secrets Manager upon launch.

Chapter Notebook Launch
Chapter 4 Context Engine Open In Colab
Chapter X Another Notebook Open In Colab

βœ… Project Structure

Create a GitHub or local workspace containing at least:

  • helpers.py
  • agents.py
  • registry.py
  • engine.py
  • Notebook files for each chapter

βœ… Required API Keys

  • OpenAI – model access and moderation
  • Pinecone – vector database storage and retrieval
  • (Optional) Google Cloud or AWS – for deployment sections in Chapter 10

βœ… System Requirements

Requirement Minimum Recommended
CPU Dual-core Any modern multi-core
RAM 8 GB 16 GB or Google Colab Pro
GPU Optional, but helpful for embeddings and token-heavy operations

Note: From Chapter 5 onward, modular components depend on earlier notebooks. Ensure your environment is configured correctly, as setup steps may not be repeated in later chapters.

βœ… Additional Notes

  • Local execution may incur token and API costs with large contexts.
  • The Summarizer Agent (Chapter 6) helps reduce token usage.
  • Familiarity with RAG workflows and MCP-based agent orchestration is recommended.
  • Refer to Appendix: Context Engine Reference Guide for quick lookup of component structures and explanations.

About the Author

βœ… Get to know Author

Denis Rothman graduated from Sorbonne University and Paris-Diderot University, designing one of the very first word2matrix patented embedding and patented AI conversational agents. He began his career authoring one of the first AI cognitive Natural Language Processing (NLP) chatbots applied as an automated language teacher for Moet et Chandon and other companies. He authored an AI resource optimizer for IBM and apparel producers. He then authored an Advanced Planning and Scheduling (APS) solution used worldwide.

LinkedIn

βœ… Other Related Books

About

This repository provides the companion Jupyter Notebooks for the book Context-Engineering for Multi-Agent Systems. It technically details the progressive construction of a Context Engine moving from simple prompts to foundational concepts to a production-ready system semantic blueprint. The code is a guide to building Multi-Agent Systems (MAS)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published