Pyproject.toml Extras in AI-Agent-Book: Modular Dependency Guide
The bojieli/ai-agent-book repository defines 20+ optional dependency groups—such as viz, rag, web, and train—in its pyproject.toml, allowing readers to install only the specific libraries required for individual chapters or experiments.
The project organizes its Python dependencies into logical extras to support dozens of independent experimental chapters without forcing a monolithic installation. By referencing specific line groups in pyproject.toml, contributors can declare exactly which stacks are needed for visualization, document parsing, local LLM inference, or GPU-accelerated fine-tuning.
Data Processing and Visualization Extras
These groups cover plotting, statistical analysis, and document parsing required by evaluation scripts and data processing pipelines.
The viz Extra
Located at pyproject.toml lines 59-70, the viz extra bundles packages for plotting, tables, and progress bars. This is the most commonly used extra across analysis and evaluation scripts, providing essential tools for visualizing agent performance and benchmark results.
The analysis Extra
Defined at pyproject.toml lines 126-133, the analysis extra includes statistical and symbolic mathematics libraries such as scikit-learn, scipy, plotly, sympy, and numba. Install this when running benchmarking scripts that require regression analysis or interactive plotting capabilities.
Document and Media Processing
For parsing PDFs and Office documents, the docs extra (lines 72-85) includes PyPDF2, pypdf, pdfplumber, reportlab, and python-docx. The media extra (lines 87-91) handles image and video processing via Pillow and OpenCV.
Web Automation and Serving Extras
These extras support HTTP fetching, browser automation, and API serving for interactive demonstrations.
The web Extra
The web extra at pyproject.toml lines 94-102 provides HTTP fetching, HTML parsing, and browser automation through aiohttp, beautifulsoup4, httpx, and playwright. This forms the foundation for agents that interact with external websites.
The browser Extra
Defined at lines 104-110, the browser extra depends on the web extra and adds higher-level browser-driving agents. Install both when working with autonomous web navigation experiments that require sophisticated DOM interaction.
The serve Extra
For interactive demos, the serve extra (lines 112-117) installs FastAPI-based HTTP services. This enables the repository's web-based demonstration interfaces to run locally.
Core AI/ML Infrastructure Extras
These groups provide the foundational libraries for tokenization, model inference, and audio processing.
The torch and providers Extras
The torch extra at lines 135-144 installs the core PyTorch and Transformers stack required for local model inference. The providers extra (lines 124-130) adds alternative LLM provider SDKs including Anthropic, Google-GenAI, Mistral, LiteLLM, and Ollama integrations.
The tokens Extra
For precise context window management, the tokens extra (lines 119-124) includes tiktoken for OpenAI model token counting.
# Example: using the `tokens` extra to count tokens with tiktoken
from tiktoken import encoding_for_model
enc = encoding_for_model("gpt-4")
text = "Hello, AI Agent Book!"
print(f"Token count: {len(enc.encode(text))}")
The audio Extra
Located at lines 77-84, the audio extra provides speech and text-to-speech processing libraries for multimodal training experiments.
Retrieval and Memory Extras
These groups support RAG pipelines and persistent agent memory.
The rag Extra
The rag extra at pyproject.toml lines 146-168 bundles the complete retrieval-augmented generation stack, including vector stores, embedding models, and BM25 implementations. This is essential for chapters demonstrating document-grounded question answering.
The mem Extra
For long-term agent memory, the mem extra (lines 108-115) installs backends such as mem0ai and memobase, enabling agents to retain context across multiple sessions.
Training and Inference Optimization Extras
These extras support local fine-tuning and high-throughput serving, with specific platform requirements.
The train Extra
Defined at lines 132-156, the train extra provides the full local fine-tuning stack including datasets, accelerate, PEFT, TRL, and bitsandbytes. This supports parameter-efficient fine-tuning experiments on consumer hardware.
The unsloth Extra
The unsloth extra at lines 158-163 pulls the entire train stack plus Linux-GPU-only Unsloth packages for accelerated fine-tuning. Note that this extra requires a Linux environment with NVIDIA GPUs.
The vllm Extra
For high-throughput inference, the vllm extra (lines 166-174) installs the vLLM inference server, which is also restricted to Linux GPU environments for optimal performance.
The solvers Extra
The solvers extra at lines 200-206 includes constraint-solving libraries such as python-constraint2 for symbolic reasoning experiments.
Integration and Orchestration Extras
These groups manage external data connectors and workflow coordination.
The integrations Extra
At lines 70-84, the integrations extra provides connectors for third-party data sources including Arxiv, Wikipedia, YouTube, Notion, and SendGrid APIs.
The orchestration Extra
The orchestration extra (lines 92-98) installs LangChain core components, OpenAI wrappers, and the Slack SDK for building complex agent workflows.
The mcp Extra
Defined at lines 118-121, the mcp extra installs Model-Context-Protocol client and server packages for standardized agent tool interfaces.
Development and Chapter-Specific Installation
The dev Extra
For contributors working on the repository itself, the dev extra (lines 86-97) includes testing, linting, and formatting tools such as pytest and ruff.
Installing Chapter Aggregates
The repository also defines chapter-specific aggregates (such as ch2) in pyproject.toml that combine multiple extras. For example, ch2 includes the web, tokens, torch, and providers extras for local LLM serving experiments.
# Install only the visualisation stack (useful for any analysis script)
pip install -e ".[viz]"
# Install everything needed for Chapter 2 (local LLM serving)
pip install -e ".[ch2]"
# For a lightweight retrieval-augmented generation demo:
pip install -e ".[rag]"
# Development work (run tests, lint, format):
pip install -e ".[dev]"
Summary
- The
bojieli/ai-agent-bookrepository uses pyproject.toml extras to modularize 20+ optional dependency groups across independent experimental chapters. - Visualization and analysis tasks require the
vizandanalysisextras, while document processing depends ondocsandmedia. - Web automation experiments need the
webextra, often paired withbrowserfor high-level agent control. - Local LLM workflows typically install
torch,providers, andtokens, whereas RAG implementations require the comprehensiveragextra. - GPU-accelerated training uses
trainorunsloth(Linux-only), and high-throughput serving requires thevllmextra (Linux-only). - Development dependencies are isolated in the
devextra to keep production environments lightweight.
Frequently Asked Questions
How do I install multiple extras simultaneously?
You can combine extras using comma-separated values within the bracket syntax. For example, pip install -e ".[viz,rag,web]" installs visualization, retrieval-augmented generation, and web scraping dependencies in a single command. As implemented in bojieli/ai-agent-book, this approach prevents version conflicts while allowing flexible environment configuration.
What is the difference between the train and unsloth extras?
The train extra at pyproject.toml lines 132-156 provides the standard fine-tuning stack (PEFT, TRL, bitsandbytes) compatible with most operating systems. The unsloth extra at lines 158-163 includes all train dependencies plus Linux-GPU-specific packages that accelerate training through optimized kernels. If you are not using Linux with CUDA, install train only.
Which extras are required for browser-based agents?
Browser automation requires the web extra (lines 94-102) for HTTP and HTML parsing capabilities, and often the browser extra (lines 104-110) for higher-level agent abstractions. The browser extra explicitly depends on web, though installing both ensures all playwright-based automation tools are available for complex multi-page interactions.
Can I run inference without installing the full torch extra?
For cloud-based inference using commercial APIs, you may only need the providers extra (lines 124-130) which includes Anthropic, Google-GenAI, and LiteLLM clients without the heavy PyTorch dependencies. However, local model inference requires the torch extra (lines 135-144) for the Transformers and PyTorch runtime, and vllm (lines 166-174) for optimized serving throughput.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →