# What AI Frameworks and Libraries Are Used in the AI Agent Book?

> Explore AI frameworks and libraries used in the AI Agent Book from bojieli GitHub. Learn about OpenAI API, LangChain, Azure OpenAI, Pydantic, and more for powerful AI agent development.

- Repository: [Bojie Li/ai-agent-book](https://github.com/bojieli/ai-agent-book)
- Tags: deep-dive
- Published: 2026-07-27

---

**The *bojieli/ai-agent-book* demonstrates production AI agents built with OpenAI API, LangChain (core, OpenAI, and experimental modules), Azure OpenAI, and utility libraries like Pydantic to handle orchestration, tool use, and asynchronous execution.**

The repository provides runnable code examples showing how specific **AI frameworks and libraries** integrate to create autonomous systems. Throughout the chapters, the book balances native OpenAI implementations with higher-level LangChain abstractions, giving readers flexibility in how they architect their agents.

## Core LLM Providers: OpenAI and Azure OpenAI

The book positions **OpenAI API** as its primary LLM provider, demonstrating both synchronous and asynchronous patterns for chat completions, embeddings, and image generation. In [`chapter1/learning-from-experience/llm_agent.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter1/learning-from-experience/llm_agent.py), the authors implement a simple wrapper around the native `openai.OpenAI` client, while [`chapter5/coding-agent/agent.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter5/coding-agent/agent.py) extends this into a full-featured coding assistant.

For enterprise deployments, the book includes **Azure OpenAI** integration through a provider abstraction layer. The file [`chapter8/gaia-experience/AWorld/aworld/models/openai_provider.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/gaia-experience/AWorld/aworld/models/openai_provider.py) shows how to swap endpoints and authentication methods without changing the underlying agent logic, demonstrating cloud-provider flexibility.

## LangChain Ecosystem for Agent Orchestration

The book extensively uses the **LangChain** ecosystem—specifically `langchain-core`, `langchain-openai`, and `langchain-experimental`—to handle message serialization, tool integration, and memory management. In [`chapter8/gaia-experience/AWorld/examples/phone_use/agent.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/gaia-experience/AWorld/examples/phone_use/agent.py), the authors implement a chat agent using `ChatOpenAI` from LangChain-OpenAI, wrapping LLM calls in structured message objects like `HumanMessage` and `AIMessage`.

LangChain's utility modules provide the infrastructure for **agent memory** and **conversation buffering**, while the experimental packages enable advanced features like autonomous planning loops.

## Tool Integration and Code Execution

A significant portion of the book focuses on **tool-calling agents** that can execute code and interact with external systems. The **Python REPL tool** from `langchain_experimental.utilities.python.PythonREPL` features prominently in [`chapter8/gaia-experience/AWorld/examples/common/tools/interpreters/python_tool.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/gaia-experience/AWorld/examples/common/tools/interpreters/python_tool.py), offering a sandboxed environment for arbitrary Python execution.

Agents use the `@tool` decorator from `langchain_core.tools` to register custom capabilities, allowing the LLM to invoke Python code, browser automation, or RPA functions through a standardized interface.

## Asynchronous Processing with AsyncOpenAI

For high-throughput applications, the book demonstrates **asynchronous LLM calls** using `openai.AsyncOpenAI`. Chapter 4 ([`chapter4/async-agent/demo.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter4/async-agent/demo.py)) provides complete examples of non-blocking completion requests, enabling parallel agent execution and improved performance in I/O-bound scenarios.

The `AsyncOpenAI` client integrates seamlessly with Python's `asyncio` patterns, allowing agents to manage multiple concurrent conversations or tool executions without blocking the main thread.

## Migration Patterns and OpenAI-Native Types

The book includes migration strategies for teams moving away from framework-specific abstractions toward native OpenAI schemas. In [`chapter8/browser-use-rpa/browser-use/browser_use/llm/base.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/browser-use-rpa/browser-use/browser_use/llm/base.py), the authors utilize `openai.types.chat.ChatCompletionMessageParam` to handle message formatting directly, reducing dependency on LangChain-specific objects while maintaining compatibility with the broader ecosystem.

This approach provides a clear path for production systems that require strict type adherence or wish to minimize abstraction overhead.

## Supporting Infrastructure and Configuration

Beyond the core AI libraries, the book employs **Pydantic** for robust configuration management and data validation, as seen in [`chapter2/system-hint/config.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter2/system-hint/config.py). This supports integration with **FastAPI** and **uvicorn** for deploying agents as web services, handling environment variables, API keys, and structured output validation through Python type hints.

## Code Examples

### Basic OpenAI Completion

```python
import openai

def simple_completion(prompt: str) -> str:
    client = openai.OpenAI()
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content

```

*Located in [`chapter1/learning-from-experience/llm_agent.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter1/learning-from-experience/llm_agent.py), this demonstrates direct API usage without orchestration frameworks.*

### LangChain Chat Agent

```python
from langchain_core.messages import HumanMessage, AIMessage
from langchain_openai import ChatOpenAI

# Initialise a LangChain chat model

chat = ChatOpenAI(model="gpt-4o-mini")

def langchain_chat(user_input: str) -> str:
    msgs = [
        HumanMessage(content=user_input)
    ]
    response = chat.invoke(msgs)
    return response.content

```

*Found in [`chapter8/gaia-experience/AWorld/examples/phone_use/agent.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/gaia-experience/AWorld/examples/phone_use/agent.py), showing LangChain's message abstraction layer.*

### Python REPL Tool Implementation

```python
from langchain_experimental.utilities.python import PythonREPL
from langchain_core.tools import tool

@tool
def run_python(code: str) -> str:
    """Execute a snippet of Python code and return the output."""
    repl = PythonREPL()
    return repl.run(code)

```

*From [`chapter8/gaia-experience/AWorld/examples/common/tools/interpreters/python_tool.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/gaia-experience/AWorld/examples/common/tools/interpreters/python_tool.py), enabling code execution capabilities.*

### Asynchronous LLM Calls

```python
import asyncio
from openai import AsyncOpenAI

async def async_completion(prompt: str) -> str:
    client = AsyncOpenAI()
    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content

# Example usage

result = asyncio.run(async_completion("Explain LangChain in one sentence."))
print(result)

```

*Demonstrated in [`chapter4/async-agent/demo.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter4/async-agent/demo.py) for high-concurrency agent architectures.*

## Summary

- **OpenAI API** serves as the foundational LLM provider throughout the book, with explicit support for both standard and Azure-hosted endpoints.
- **LangChain** modules provide the orchestration layer for message handling, tool integration, and memory management in complex agent workflows.
- **Python REPL tools** from LangChain-Experimental enable safe code execution within agent loops, critical for coding assistants and data analysis agents.
- **AsyncOpenAI** patterns in Chapter 4 demonstrate production-ready asynchronous processing for scalable agent systems.
- **Pydantic and FastAPI** support the configuration and deployment infrastructure, ensuring type-safe agent deployment.

## Frequently Asked Questions

### Is LangChain required to follow the book's examples?

No. While the book extensively uses LangChain for orchestration, it also provides native **OpenAI API** implementations in [`chapter1/learning-from-experience/llm_agent.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter1/learning-from-experience/llm_agent.py) and [`chapter5/coding-agent/agent.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter5/coding-agent/agent.py). The authors demonstrate both approaches, allowing readers to choose between framework abstractions and direct API integration based on their specific requirements.

### Does the book cover Azure OpenAI integration?

Yes. The repository includes specific examples for **Azure OpenAI** in [`chapter8/gaia-experience/AWorld/aworld/models/openai_provider.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/gaia-experience/AWorld/aworld/models/openai_provider.py), showing how to configure endpoint URLs, API versions, and authentication headers to work with Azure-hosted models while maintaining code compatibility with standard OpenAI implementations.

### How does the book handle asynchronous agent execution?

Chapter 4 ([`chapter4/async-agent/demo.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter4/async-agent/demo.py)) dedicates examples to **asynchronous processing** using `openai.AsyncOpenAI`. This enables non-blocking LLM calls that improve throughput when agents need to manage multiple concurrent conversations or parallel tool executions.

### Are there examples of agents that can execute code?

Yes. The book implements a **Python REPL tool** using `langchain_experimental.utilities.python.PythonREPL` in [`chapter8/gaia-experience/AWorld/examples/common/tools/interpreters/python_tool.py`](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/gaia-experience/AWorld/examples/common/tools/interpreters/python_tool.py). This tool allows agents to execute arbitrary Python code safely within a sandboxed environment, enabling capabilities like automated data analysis, mathematical computation, and dynamic scripting.