Building LLM Agents with LangGraph #1: Introduction to LLM Agents & LangGraph
Step-by-Step Guide to Building LLM Agents with LangGraph
LLM agents are a very powerful tool to automate complex workflows. In this first article of the Building LLM Agents with LangGraph series, we lay the foundation for understanding LLM agents and their agentic workflows.
We explore what LLM agents are, the fundamental building blocks that make them work, and the concept of agentic workflows. By diving into key design patterns, such as self-reflection, tool use, planning, and multi-agent collaboration, readers will gain insights into how these patterns enhance agent capabilities.
The article also introduces LangGraph, a framework designed to streamline the creation and management of LLM agents, highlighting its core concepts and advantages. This introduction serves as the gateway to mastering the principles and practicalities of building LLM agents with LangGraph which we will build in the coming articles.
This article is the first article in the ongoing series of Building LLM Agents with LangGraph:
Introduction to Agents & LangGraph (You are here!)
Building Simple ReAct Agent from Scratch (Coming Soon!)
Main Building Units of LangGraph (Coming Soon!)
Agentic Search Tools in LangGraph (Coming Soon!)
Persistence and Streaming in LangGraph (Coming Soon!)
Human in the Loop in LLM Agents (Coming Soon!)
Putting it All Together! Building Essay Writer Agent (Coming Soon!)
This series is designed to take readers from foundational knowledge to advanced practices in building LLM agents with LangGraph.
Each article delves into essential components, such as constructing simple ReAct agents from scratch, leveraging LangGraph’s building units, utilizing agentic search tools, implementing persistence and streaming capabilities, integrating human-in-the-loop interactions, and culminating in the creation of a fully functional essay-writing agent.
By the end of this series, you will have a comprehensive understanding of LangGraph, practical skills to design and deploy LLM agents, and the confidence to build customized AI-driven workflows tailored to diverse applications.
Table of Contents:
Agents & Agentic Workflows
1.1. What are AI & LLM Agents?
1.2. Building Blocks of AI & LLM Agents
1.3. What is Agentic Workflow?
1.4. Steps to Build Agentic Workflows?Design Patterns of Agentic Workflows
2.1. Agentic Self-Reflection Pattern
2.2. Agentic with Tool Use Pattern
2.3. Agentic Planning Pattern
2.4. Multi-Agentic PatternIntroduction to LangGraph
3.1. Core Concept of LangGraph
3.2. Advantages of LangGraph
1. Agents & Agentic Workflows
1.1. What are AI & LLM Agents?
AI agents employ technologies such as large language models (LLMs), machine learning, and natural language processing to understand context, interpret information, and interact with other systems and users.
As they operate within workflows, they can adapt to new inputs and changing circumstances in real-time, continuously learning from their experiences to improve their performance. This allows organizations to handle tasks as dynamic entities, driving new levels of efficiency and enabling agile response to evolving business needs.
Key characteristics of agentic AI include:
Autonomy: Agentic AI is imbued with its own goals, objectives, and motivations, which drive its decision-making and actions. It can autonomously choose the most appropriate steps to pursue its goals without human supervision.
Adaptive learning and Reasoning: Agentic AI can gather information from their interactions with the environment and learn from past experiences. These agents can use reasoning and problem-solving abilities to update their knowledge, revise their strategies, and improve their performance over time.
Language understanding: Agentic AI leverages state-of-the-art NLP models, such as transformers and large language models, to process and comprehend human language at a deep semantic level.
Workflow Optimization: Agentic AI agents combine their language understanding with reasoning, planning, and decision-making abilities to optimize workflows and business processes. This includes optimizing resource allocation, streamlining communication and collaboration, and identifying opportunities for process automation.
Multi-agent and System Conversation: Agentic AI can communicate between different agents to build a complex workflow. It can also connect to other systems or tools, such as email, code executor, or search engine to perform a variety of tasks.
Integrating the above features enables agentic AI to become a powerful tool to enhance productivity and improve the decision-making process. These features also differentiate agentic AI from traditional AI.
1.2. Building Blocks of AI & LLM Agents
Harrison Chase, the founder of LangChain has described that the building blocks of each agentic AI include four main perspectives, Planning, Memory, Tool, and Action.
Planning: The agent will plan a workflow to achieve its goal. The plan includes but is not limited to reflection, self-critics, chain-of-thought, and subgoal decomposition. To allow the agent to make a better plan, prompt engineering is the foundation for the agentic assistants to generate something closer to the expected result. Find more insightful example prompts from the blog post “How to Create an AI Assistant Without Any Coding Skills”. The planning process will be supported by the memory component to review the plan or previous subtasks in the workflow.
Memory: The agent will have a memory component to store the previous actions or subtasks that may be needed in future planning or actions. The memories can be categorized into two types, short-term memory and long-term memory for storing data or previous task results with different dependencies.
Tool: This refers to a set of tools, like a calendar, calculator, or code interpreter, that the agentic assistants acquire to perform specific tasks.
Action: The agent takes action to complete the task assigned by the plan and make use of the tools equipped.
These four perspectives will run in a loop and form a cycle until the given task is completed. The process starts with planning, and equipping tools, followed by action, then memory, and then back to planning to start the next stage in the plan or another task.
For instance, if we have to calculate (1+2)/3 by agentic AI, the agent will start with the planning stage. It plans to compute 1+2 first. The agent is equipped with the tool calculator and takes action to perform addition. After generating the calculation result, it will store the result in the short-term memory for the next step.
Finally, it will go back to the planning stage to reflect on the plan, then decide and perform division with the result stored in the memory to complete the task.
To perform a more complex task or workflow, a multi-agent system can be created with multiple agentic AI with different tools or planning that specify different subtasks.
1.3. What is Agentic Workflow?
Agentic workflows represent sequences of well-defined jobs to be done that are executed dynamically by AI agents and orchestrated as part of a larger end-to-end business process automation. In this way, agentic workflows are the application of AI agents to process automation. They organize tasks, assign work to specialized agents, and facilitate collaboration between agents and humans to improve output.
Sometimes referred to as agentic processes or AI-agent-enabled processes, agentic workflows harness the ability of AI agents to reason, problem solve, choose a course of action, and execute these actions.
Unlike existing applications of AI within automated workflows that are used to analyze data and inform decision-making, AI agents are designed to take action based on their analyses, making decisions and adapting processes to changing circumstances in real-time.
Agentic workflows, or agentic processes, put AI agents to work for task management and automation, bringing flexibility, responsiveness, and a degree of independence to business processes.
1.4. Steps to Build Agentic Workflows?
To set up such impressive Agentic workflows, there are a few major steps.
Step 1: Identify the Workflow and the Structure
Before you start building the agentic assistants or the workflow, you should first identify the structure of the agentic workflow or the role of the individual AI agents such that you will have a clearer idea of what the workflow will look like.
You may want to ask yourselves the following questions to understand the structure of your agentic workflow and the agentic AI assistants:
What tasks or issues will the workflow deal with?
How many agentic AI do you need to divide the complex task into smaller subtasks?
What are the roles or targets of the individual agents?
What are the input and output of each agentic AI?
How do the agents interact or connect in the workflow?
When you have answers to the above questions, you should have a better idea of your workflow structure and you could proceed to the next step.
Step 2: Specify and Create the Agentic Assistants
After you know how many agents and what their roles are, you may start building your agents according to their responsibilities. To create an agentic AI, there are four main building blocks to considerate as mentioned above:
Planning and Action: Determines the input and output of the agent and checks whether there are intermediate steps like using the tool or the planning process outline that the agent has to make such that you can set up the prompt for your agent.
Memory: Determined how many past messages to retrieve and whether you need a long-term memory. This may depend on the model or the framework you use. Some frameworks support memory systems on their own but some are required to set up the memory system by yourself.
Tool: Refer to the role of your agent, and determine the power-ups or extensions that the agent may require. For example, if the agent is a researcher on your sales lead, then it may require a web search tool and web scrapper to gather information about the lead from their webpage or LinkedIn.
When you have determined the requirements of all building blocks, then you can set up your agents smoothly with the chosen LLM model.
Step 3: Utilize Agentic Workflow for Automation
After setting up all agents, this is the time to build the agentic workflow. With consideration in the first step, you can set up the connection between the agents by passing one’s agent output as another input or any other way you want.
You may have to refine your agents’ prompts or add an extra step to reformat the output to fit in another agent’s prompt as input. After setting up your agentic workflow, you should monitor its performance and refine its structure to optimize your system for efficiency, accuracy, and creativity.