This course aims to equip learners with the skills to build production-ready multi-agent systems and automate workflows using LangChain and LangGraph, covering fundamentals to advanced topics and real-world project deployment.
Bappy: From LLMs to Agentic AI
The evolution from basic Large Language Models (LLMs) to agentic AI signifies a shift towards more autonomous and capable systems that can perform complex tasks by orchestrating multiple agents. This progression is crucial for building sophisticated applications.
Bappy: RAG's Real-Time Data Challenge
Traditional RAG systems struggle with continuously changing real-time data, such as news or weather, because updating the knowledge base is a manual and time-consuming process. This limitation means RAG applications cannot reliably provide the most current information when asked.
Bappy: Automating Job Posting with AI Agents
An AI agent can automate the entire job posting process, from generating a job description to posting it on multiple platforms like LinkedIn and Indeed, and continuously monitoring applications. This involves the agent calling external APIs (tools) to perform these actions.
Bappy on Planning in Agentic AI
Planning is a core characteristic of agentic AI, involving steps like goal decomposition, tool selection, and resource estimation. Agents evaluate different plans based on criteria such as cost, efficiency, and risk, often with human-in-the-loop validation to select the optimal strategy.
Bappy on Asynchronous vs. Synchronous Programming
Synchronous programming executes tasks sequentially, meaning one must complete before the next begins, leading to potential delays. Asynchronous programming, however, allows tasks to run concurrently, significantly reducing overall execution time by not waiting for I/O-bound operations to complete. This is achieved using keywords like `async` and `await` and libraries like `asyncio` in Python.
Bappy: The Necessity of Structured Data
Large language models often produce unstructured output, making data validation and structured responses essential for efficient and relevant AI applications. Pydantic addresses this by enforcing schemas and ensuring data integrity.
Pydantic's Core Functionality
Pydantic is a Python library that simplifies data validation and management by allowing developers to define data schemas using Python type hints. It automatically validates incoming data against these schemas, converting types and raising errors for invalid data, thereby reducing boilerplate code and improving robustness.
Bappy on Pydantic Field Validation
Pydantic's `Field` function allows for detailed configuration of data fields, including descriptions, default values, and constraints like maximum length. The `strict` parameter can be set to `True` to prevent automatic type coercion, ensuring data strictly adheres to the defined type.
Bappy: LLMs vs. Agentic AI
Traditional LLMs process prompts directly and lack external tool integration, relying solely on their training data. In contrast, AI agents use LLMs as a 'brain' for reasoning, enabling them to decide when and how to utilize external tools, APIs, or knowledge sources to fulfill a prompt, thus overcoming the knowledge limitations of static LLMs.
Bappy Explains Agent Creation with REACT
Creating a REACT agent involves defining the LLM, tools, and prompt. The agent object is then returned, which can be executed using an agent executor. The verbose parameter in the executor controls log visibility.
Bappy: Enhancing Agents with Custom Tools
Agents can be enhanced by integrating custom tools, such as a function to fetch real-time weather information for any location, alongside predefined tools like tabular search. This allows agents to perform more specific and complex tasks.
Agentic AI: The Multi-Agent Advantage
Complex AI tasks are best handled by multi-agent systems, analogous to how companies assign specialized roles to teams. A single agent attempting all tasks results in lower quality output, whereas distinct agents for search, reading, writing, and critique ensure specialized expertise and higher quality results. This approach mirrors real-world team dynamics where individual expertise leads to superior project outcomes. The final output is a testament to this collaborative, specialized effort.
Bappy: Structuring the Agentic AI Project
The initial phase of building an agentic AI system involves establishing a modular code structure with dedicated folders for agents, pipelines, and tools. This modular approach, exemplified by creating `__init__.py` files and specific `.py` files for each component, facilitates organized development and maintainability. The project structure is then committed to GitHub for version control.
Bappy: Building the Research Agent Pipeline
The core of the system involves creating a pipeline of specialized agents: a search agent to find relevant URLs, a reader agent to scrape content from those URLs, a writer agent to draft a report based on the scraped content and URLs, and a critic agent to review and provide feedback on the report. This modular approach allows for complex tasks to be broken down and managed efficiently.
Automated README Generation
The speaker demonstrates how AI can be leveraged to automatically generate a comprehensive README file for a project by analyzing the codebase, saving developers significant manual effort. This includes detailing features, architectures, technologies used, installation, and contribution guidelines.
Workflow vs. Agents: Dynamic Control
Workflows follow predefined paths with conditions and loops, whereas agents dynamically control execution, making decisions in real-time. This fundamental difference dictates the choice of framework for complex tasks.
State Management: LangChain vs. LangGraph
LangChain is stateless, requiring manual management of state data through glue code, which is complex and error-prone for intricate workflows. LangGraph, however, is stateful by design, utilizing state objects (defined with Pydantic or TypedDict) that nodes can access and update automatically, simplifying state management significantly.
Bappy: LangGraph vs. LangChain - The Core Distinction
LangGraph is presented as an orchestration framework for building stateful, multi-step, and event-driven workflows using LLMs, ideal for single and multi-agent applications. It functions like a flowchart engine, defining steps as nodes and connections as edges, and handles state management, conditional branching, looping, and fault recovery. LangChain, conversely, provides the fundamental building blocks for individual steps within these workflows, such as LLM calls, prompt templates, and retrievers. LangGraph is built on top of LangChain, leveraging its components while adding advanced orchestration capabilities.
Evaluator-Optimizer Workflow
The evaluator-optimizer workflow involves an LLM generator and an LLM evaluator. The generator produces output, which the evaluator checks for quality. If rejected, feedback is provided to the generator for refinement, creating an iterative loop until the output is accepted.
Bappy: Understanding LangGraph's Execution Strategy
LangGraph employs a 'sprreel' system for large-scale graph execution, ensuring that the graph stops when all nodes are activated and no messages are in transit. This strategy is fundamental to how LangGraph executes its graphs.
Bappy: From LLMs to Agentic AI
The evolution from basic Large Language Models (LLMs) to Agentic AI represents a significant leap, enabling systems to perform complex tasks autonomously by incorporating reasoning, planning, and tool usage.
Parallel vs. Sequential Workflows
Sequential workflows execute nodes one after another, with each node's output feeding into the next, requiring waiting for completion. Parallel workflows, however, allow for the simultaneous and independent execution of multiple nodes, leading to faster task completion. This independence is key for efficiency when tasks do not rely on each other's immediate results. The speaker emphasizes that for parallel execution, nodes should only return the specific state variables they have updated, rather than the entire state, to prevent conflicts and ensure correct operation. This distinction is crucial for optimizing agentic AI systems.
Bappy: Building an Essay Evaluation Workflow
A multi-node workflow is designed to evaluate essays by analyzing language quality, depth of analysis, and clarity of thought, each providing feedback and a score. These individual scores are aggregated to produce a final average score and a summarized feedback report.
Bappy's Parallel Workflow Implementation
The speaker demonstrates the practical implementation of a parallel workflow using LangGraph, compiling the graph and invoking it with sample data to process an essay and generate feedback across multiple nodes simultaneously. The output includes detailed feedback from language, analysis, and clarity nodes, along with an average score.
Bappy Explains Conditional Edges
Conditional workflows in LangGraph are implemented using `add_conditional_edges`, which takes a condition function to dynamically decide the next node in the graph, ensuring only one path is executed based on the outcome. This is demonstrated with a content moderation example where posts are approved, flagged, or rejected based on keywords and user reputation.
Bappy: The Power of Iterative Workflows
Iterative workflows in LangGraph are crucial for tasks requiring continuous improvement, such as content generation. They allow an agent to loop through optimization and evaluation steps until a satisfactory result is achieved, preventing the need for manual intervention.
Iterative Workflows in LangGraph
LangGraph enables iterative workflows where agents can refine their output over multiple steps, with a maximum iteration limit to prevent infinite loops. The system evaluates the output at each step, approving it if satisfactory or feeding back for improvement.
The Problem with Volatile Chat States
When using state within a loop in LangGraph, the state is often erased upon completion of each execution cycle. This means that older conversation history is lost, and the agent cannot recall previous interactions, effectively resetting the memory with each new loop iteration. This is a fundamental issue for maintaining conversational context.
Bappy: Addressing Chatbot Memory with Session State
By default, Streamlit chatbots lose conversation history on each re-execution. To maintain this history, similar to ChatGPT, session state must be implemented. This involves initializing a message history in the session state if it doesn't exist, and then appending both user inputs and AI responses to this history, ensuring the chatbot remembers the conversation context.
Bappy on Persistence and Fault Tolerance
Persistence in LangGraph is vital for fault tolerance, enabling applications to resume from intermediate states rather than restarting from scratch. This is achieved by capturing snapshots of the graph's state after each execution step, ensuring that if the application crashes, it can recover its progress.
Bappy: Navigating Gemini API Key Issues
When integrating with the Gemini API, users may encounter 'model not found' errors. This often requires updating to a newer, supported model version like 'gemini-1.5-flash' as older versions may be deprecated. The presenter demonstrated this by switching from a non-working model to a functional one, ensuring the API call was successful.
Bappy: The Problem with Non-Streaming Responses
Waiting for an entire AI response to generate before displaying it leads to a poor user experience, especially for long outputs or complex agentic tasks. This delay can cause users to lose interest and abandon the application, unlike interactive streaming responses seen in platforms like ChatGPT.
Bappy: Implementing Chat Threading for Separate Conversations
The core of this implementation is enabling separate conversation threads, similar to ChatGPT. This is achieved by generating unique IDs for each chat session and storing messages associated with these IDs. When a user starts a new chat, a new ID is generated, and the conversation history is managed within that specific thread, ensuring that previous conversations remain intact and accessible.
Bappy: The Problem of Volatile Memory
Current agentic chatbots, when using in-memory storage like RAM, lose all conversation history upon refreshing or closing the application. This ephemeral nature prevents users from continuing previous interactions, necessitating a more permanent storage solution. The core issue is that RAM is temporary storage, and any interruption clears the data, leading to a loss of context and user history.
Bappy: From In-Memory to Database Persistence
The presenter demonstrates the critical shift from volatile in-memory lists for chat history to persistent database storage. This ensures that conversations and application states are not lost upon refreshing or restarting the application, mimicking the behavior of robust platforms like ChatGPT. The code refactoring involves creating a `get_all_trades` function to fetch data from the database, ensuring data integrity and continuity.
LangSmith for Monitoring
LangSmith is crucial for monitoring and tracing agentic AI applications, providing insights into execution flows and identifying issues. While it offers automatic tracing, custom configuration is needed to separate individual conversation traces effectively by modifying the trace ID and passing metadata.
Bappy Explains the Agentic Workflow
The agentic workflow begins with a user request, followed by the agent understanding the goal, determining if a tool is needed, selecting the appropriate tool, generating tool arguments, executing the tool, and finally refining the tool's response to produce a readable output for the user.
Bappy: Integrating Custom Tools for Enhanced Agentic Capabilities
Bappy demonstrates how to integrate custom tools, such as a 'get current weather' function, into an agentic AI system. This involves defining the tool's functionality, obtaining necessary API keys (like for OpenWeatherMap), and ensuring the tool is correctly passed to the LLM via a tool-binding operation. This allows the agent to access real-time information and perform actions beyond its core language model capabilities. The process includes setting up environment variables for API keys and ensuring the tool is included in the list of available tools for the agent.
Bappy: Agentic Chatbot Features Showcase
The agentic chatbot developed boasts advanced features including conversational threading, tool integrations, streaming responses, and persistent memory via a database. It also incorporates RAG functionality, allowing users to upload documents and converse on their content, similar to ChatGPT.
Bappy: Document Ingestion and Chunking for RAG
To implement RAG, documents (like PDFs) must first be loaded and then split into smaller, manageable chunks using libraries like `recursive_character_text_splitter`. This process prepares the data for embedding and storage in a vector database. The chunk size and overlap are critical hyperparameters that influence retrieval quality. The final chunking operation resulted in 44 chunks from the sample document.
Bappy: Implementing RAG for Document Chatbots
The speaker demonstrates how to integrate Retrieval-Augmented Generation (RAG) into an agentic chatbot, allowing users to upload documents (like PDFs) and query them. This involves saving the document, creating a knowledge base (vector store), and then performing chat operations on that data, similar to ChatGPT's document upload feature.
Bappy: The Necessity of Human Oversight
Human-in-the-Loop (HITL) is essential for agentic AI systems, especially for sensitive operations like stock purchases. Without it, agents can make costly mistakes due to hallucinations or misinterpretations. HITL ensures that critical actions are only performed after explicit user approval, mitigating risks associated with autonomous decision-making.
Bappy: Implementing Human-in-the-Loop for Critical Tasks
To enhance the safety and accuracy of agentic chatbots for sensitive operations like stock purchases, a human-in-the-loop (HITL) functionality must be integrated. This involves adding a mechanism that prompts user approval before executing critical actions, thereby preventing unintended consequences and ensuring user control.
Bappy: Docker Prerequisites for Deployment
Before deploying agentic AI applications, a solid understanding of Docker is essential. The speaker directs viewers to a comprehensive MLOps course on their channel that covers Docker concepts in detail, emphasizing its role in CI/CD deployment.
Setting Up Self-Hosted Runners
To enable CI/CD for deploying agentic AI applications, a self-hosted runner must be set up on AWS. This involves configuring the runner with specific labels and ensuring it connects to GitHub, allowing automated job execution directly from the cloud environment.
Deployment on Render
The presenter demonstrates deploying the agentic chatbot application on Render, a cloud platform, by creating a Docker file, connecting a GitHub repository, and configuring environment variables. This process makes the application live and accessible.
Project Setup and Environment Configuration
The initial phase of building the Bappy GPT project involves cloning a GitHub repository, creating a Python virtual environment (using Conda), and installing necessary libraries via a requirements.txt file. This structured setup is essential for a stable development environment.
Bappy: Implementing Core Agentic Tools
The foundation of agentic AI systems involves integrating various tools, including web search, calculators, and memory persistence. Bappy demonstrates how to define custom tools using Python functions and decorators, and how to leverage libraries like Tabby for web searches and SQLAlchemy for database operations to manage conversation history and long-term memory.
Backend Setup with FastAPI
The backend is implemented using FastAPI, a modern, fast web framework for building APIs with Python. The speaker sets up the FastAPI application, imports necessary libraries for streaming responses, JSON handling, and template rendering, and initializes the database. Asynchronous programming is utilized to handle requests efficiently, a concept previously covered in the speaker's other content.
Bappy: Setting the Stage for Deployment
Before deploying the agentic AI application, the necessary cloud infrastructure must be prepared. This involves creating an IAM user with specific permissions for EC2 and ECR, setting up an ECR repository to store Docker images, and launching an EC2 instance with sufficient resources (e.g., 8GB RAM, 2 CPU cores) running Ubuntu.
TripMate AI: The Vision
The core problem addressed is the fragmented and time-consuming process of planning a trip, which typically involves juggling multiple websites for flights, hotels, and itineraries. TripMate AI aims to solve this by creating a unified, multi-agent system that generates a comprehensive travel plan from a single natural language request. This system will provide detailed information on flights, hotels, day-to-day itineraries, and estimated budgets, all downloadable as a PDF.
Project Setup & Dependencies
To begin building the agentic AI application, Bappy outlines the necessary Python packages, emphasizing the importance of specifying exact versions to prevent future compatibility issues. Key dependencies include 'airportsdata', 'pi-country', 'fastapi', 'uvicorn', and 'jinja2'. He stresses that version pinning is crucial because package updates can deprecate functionalities, leading to errors later on.
Bappy: Integrating Real-time Data with Tably Search
The Tably search function is implemented to fetch real-time information from various websites, enhancing agent capabilities beyond static knowledge. This function was tested and confirmed to be working correctly, providing relevant search results for queries like 'best hotels in India'.