Which Programming Languages and Frameworks Are Used in the AI Agent Book Project?

The AI Agent Book repository uses Python (with FastAPI and PyTorch) for backend agent logic and JavaScript/TypeScript (with Next.js and React) for frontend demos, supplemented by Bash scripts for automation and Markdown for documentation.

The bojieli/ai-agent-book repository is a comprehensive educational resource that demonstrates modern AI agent development through practical code examples. Understanding which programming languages and frameworks are used in this project helps developers navigate its multi-layered architecture spanning from backend agent logic to interactive web interfaces.

Core Programming Languages in the AI Agent Book

The repository adopts a polyglot approach, leveraging specific languages for distinct architectural layers.

Python for Agent Logic and Machine Learning

Python serves as the primary language for implementing core agent behaviors, training pipelines, and backend services. In chapter1/web-search-agent/agent.py, the repository implements a ReAct-style web-search agent that interacts with LLM backends through the OpenAI SDK. The codebase also uses Python for machine learning workloads, as seen in chapter7/MultilingualReasoning/gpt_oss_20b_sft.py, which utilizes PyTorch for supervised fine-tuning of large language models.

JavaScript and TypeScript for Interactive Frontends

For user-facing components, the project relies heavily on JavaScript and TypeScript. The chapter9/live-audio/frontend/package.json defines a Next.js application built with React and TypeScript, while chapter5/conversational-ui/frontend/package.json demonstrates a lighter Vite + React setup. These frontend implementations enable real-time interaction with the underlying Python agents.

Bash and Shell Scripts for Automation

Bash scripts handle build automation and environment setup tasks. The build_epub.sh script at the repository root orchestrates e-book generation, while various *_demo.sh scripts scattered throughout chapter directories provide quick-start mechanisms for running experiments.

Markdown and Configuration Formats

Markdown files under the book/ directory contain the actual textbook content, while JSON files store package configurations and API schemas. The repository also includes LaTeX files such as book/preamble.tex for PDF rendering and SVG assets for technical diagrams.

Key Frameworks and Libraries

Beyond languages, the AI Agent Book integrates several production-grade frameworks that power its demonstrations.

FastAPI for Backend Services

FastAPI provides the HTTP layer for exposing agent capabilities as web services. In chapter4/agent-with-event-trigger/server_fastapi.py, the codebase implements an asynchronous server that handles event-driven agent execution through lightweight endpoints.

PyTorch for Model Training

The repository includes model-centric experiments that rely on PyTorch for training and inference. The gpt_oss_20b_sft.py script demonstrates fine-tuning workflows, while implicit usage of Transformers and Tiktoken appears in tokenization and model loading routines under chapter8/prompt-distillation/.

Next.js and React for User Interfaces

Modern frontend development in the project centers on Next.js and React, styled with Tailwind CSS. The live-audio demo in Chapter 9 uses Next.js 13.3, while Chapter 5's conversational UI employs Vite as an alternative build tool for React applications.

OpenAI SDK and LLM Integrations

The OpenAI SDK facilitates communication with various LLM providers including Moonshot Kimi and OpenRouter. The agent.py implementation (lines 94-110) includes logic for auto-selecting endpoints based on available API keys, demonstrating multi-provider compatibility.

MCP Protocol and Docker

For advanced tool orchestration, Chapter 8 introduces the MCP (Model Context Protocol) using containerized services. The implementation in chapter8/gaia-experience/AWorld/env/virtualpc-mcp/mcp_server/src/mcp_gateway/main.py shows how Docker-encapsulated tools integrate with the agent ecosystem.

Implementation Examples

The following code snippets illustrate how these languages and frameworks work together in the repository.

ReAct-Style Web Search Agent in Python

The core agent implementation in Chapter 1 demonstrates Python-based agent architecture:

from chapter1.web_search_agent.agent import WebSearchAgent

# Initialise – will automatically pick up MOONSHOT_API_KEY or KIMI_API_KEY

agent = WebSearchAgent(verbose=True)

# Ask a question; the ReAct loop runs automatically.

answer = agent.search_and_answer(
    "What is the purpose of Context Caching in Moonshot AI?"
)

print("📝 Answer:", answer)

This example, located in chapter1/web-search-agent/agent.py, shows the ReAct pattern implementation using the OpenAI SDK.

Event-Driven FastAPI Server

Chapter 4 provides a reference implementation for serving agents via HTTP:


# file: chapter4/agent-with-event-trigger/server_fastapi.py

from fastapi import FastAPI, HTTPException, BackgroundTasks
import logging

app = FastAPI(title="Event‑Triggered Agent Server")

@app.post("/run")
async def run_agent(payload: dict, background: BackgroundTasks):
    """Trigger the agent asynchronously."""
    background.add_task(start_agent, payload)   # `start_agent` is defined elsewhere

    return {"status": "agent started"}

This FastAPI pattern enables asynchronous agent execution suitable for production deployments.

Next.js Frontend for Live Audio

The TypeScript frontend in Chapter 9 demonstrates modern React patterns:

// file: chapter9/live-audio/frontend/pages/index.tsx
import { useState } from 'react';
import { fetchAudio } from '@/lib/utils';

export default function Home() {
  const [text, setText] = useState('');
  const [audioUrl, setAudioUrl] = useState<string | null>(null);

  const handleSubmit = async () => {
    const url = await fetchAudio({ prompt: text });
    setAudioUrl(url);
  };

  return (
    <main className="p-8">
      <textarea
        value={text}
        onChange={e => setText(e.target.value)}
        placeholder="Enter a prompt for TTS..."
        className="w-full p-2 border rounded"
      />
      <button onClick={handleSubmit} className="mt-4 btn-primary">
        Generate Audio
      </button>
      {audioUrl && <audio controls src={audioUrl} className="mt-4" />}
    </main>
  );
}

This component, supported by the configuration in chapter9/live-audio/frontend/package.json, provides a complete TypeScript implementation using Next.js and Tailwind CSS.

Build Automation with Bash

The repository includes automation scripts for documentation generation:


# From the repository root

cd book
bash build_pdf.sh          # Uses pandoc + xelatex + ElegantBook

bash build_epub.sh         # Generates EPUB3 via pandoc

These scripts, including build_epub.sh, manage the complex pipeline for creating distributable book formats from source Markdown and LaTeX.

Summary

  • Python powers the core agent logic, training scripts, and backend services using FastAPI and PyTorch.
  • JavaScript/TypeScript drives interactive frontends through Next.js, React, and Vite, styled with Tailwind CSS.
  • Bash scripts automate build processes and environment setup for the book generation and demos.
  • FastAPI provides production-ready HTTP endpoints for agent deployment in chapter4/agent-with-event-trigger/server_fastapi.py.
  • OpenAI SDK enables multi-provider LLM integration including Moonshot and OpenRouter support.
  • MCP protocol implementations in Chapter 8 demonstrate containerized tool orchestration for advanced agent capabilities.

Frequently Asked Questions

Does the AI Agent Book project use only Python for agent development?

No, while Python handles the core agent logic and machine learning components in files like chapter1/web-search-agent/agent.py, the project uses JavaScript and TypeScript for frontend demonstrations. The repository includes Next.js and React applications in chapter9/live-audio/frontend/ and chapter5/conversational-ui/frontend/ to provide interactive user interfaces for the agents.

Which deep learning framework does the AI Agent Book use for model training?

The repository uses PyTorch for model training and fine-tuning tasks. You can find implementation examples in chapter7/MultilingualReasoning/gpt_oss_20b_sft.py, which demonstrates supervised fine-tuning of a 20B parameter model. The codebase also implicitly utilizes the Transformers library for model loading and Tiktoken for tokenization in various training scripts.

How does the project handle API communication with different LLM providers?

The codebase implements a flexible provider selection mechanism in chapter1/web-search-agent/agent.py (lines 94-110) using the OpenAI SDK. This implementation automatically detects available API keys for services like Moonshot Kimi and OpenRouter, allowing the agent to switch between different LLM backends without code changes. The FastAPI servers in Chapter 4 then expose these capabilities through HTTP endpoints.

What frontend technologies are used for the interactive demos?

The interactive demonstrations employ Next.js (React 18+ with TypeScript) for comprehensive applications like the live-audio interface in Chapter 9, configured in chapter9/live-audio/frontend/package.json. Simpler demos use Vite + React for faster development cycles, as seen in chapter5/conversational-ui/frontend/package.json. Both implementations use Tailwind CSS for styling and modern React hooks for state management.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →