How to Build a LangGraph Chatbot with Tools

TL;DR
Build a stateful chatbot by defining a LangGraph workflow, connecting an open-source LLM through the Groq API, and registering external tools such as Wikipedia or arXiv. The chatbot receives a user query, decides whether it can answer directly or should invoke a tool, then returns the resulting response while LangGraph manages messages and workflow state.
Transcript
hello all my name is krishn and welcome to my YouTube channel so guys this is the second tutorial on building generative applications using langra if you don't know about langra it is an amazing moduel that is provided by Langan to build multi- aai agents not only you'll be able to create agents but also you'll be able to manage the entire State an... Read More
Key Insights
- LangGraph is a framework for building stateful agent and multi-agent applications with LLMs. It supports complete workflows while managing application state, giving developers control over how chatbot nodes, external tools, and response paths interact during execution.
- The chatbot workflow begins when a user submits a query. The chatbot evaluates the request and decides whether to provide an answer through its connected LLM or route the query to an external tool such as Wikipedia or Google Search.
- External tools can extend the chatbot with information from specialized sources. The tutorial demonstrates Wikipedia for general searches and arXiv for research-paper queries, while noting that additional tools can be registered by adding them to the application’s tool collection.
- The Groq API provides access to the open-source LLM used by the chatbot. The required installation includes the LangChain Groq integration, alongside LangGraph, LangSmith, LangChain, and LangChain Community packages needed to assemble the application and its external-tool connections.
- WikipediaAPIWrapper and ArxivAPIWrapper can restrict returned content. The demonstrated configuration requests one top result and limits document content to 300 characters, producing compact outputs when the tools are invoked with a query.
- The Wikipedia tool is tested with a query about actor Shah Rukh Khan. The arXiv tool is separately tested with the research-paper query “Attention Is All You Need,” confirming that both wrappers can retrieve results before workflow integration.
- The State class stores workflow messages in a list defined with TypedDict and Annotated. LangGraph’s add_messages function updates that message collection after node execution, allowing the application to preserve and manage conversation information across the workflow.
- The StateGraph is initialized with the custom State class. This graph builder forms the structural foundation for defining the chatbot, connecting nodes, managing transitions, and representing the start and end of the tool-assisted response workflow.
Install to Summarize YouTube Videos and Get Transcripts
Explore YouTube Video Summarizer or Get YouTube Transcript Extractor
Questions & Answers
Q: How do you build a LangGraph chatbot with external tools?
Install LangGraph, LangSmith, LangChain, the LangChain Groq integration, LangChain Community, and the packages required by the selected tools. Configure wrappers such as WikipediaAPIWrapper or ArxivAPIWrapper, create runnable query tools, and place them in a tool collection. Then define a message-based State class, initialize StateGraph with it, and design the chatbot’s decision path between direct answers and tool calls.
Q: How does a LangGraph chatbot decide when to use a tool?
The workflow sends the user’s query to the chatbot first. The chatbot then decides whether it should answer through the connected open-source LLM or ask an external service for information. When a third-party tool is selected, that tool processes the query and returns its result. The workflow subsequently delivers the response and reaches its end state.
Q: What external tools are demonstrated in the LangGraph tutorial?
The tutorial demonstrates integrations for Wikipedia and arXiv. Wikipedia is presented as a source for general information searches, while arXiv is used for research-paper queries. Google Search is also mentioned as a possible third-party tool, although the code demonstration focuses on Wikipedia and arXiv. The workflow can accept additional tools by adding them to the registered tool list.
Q: How do you configure WikipediaAPIWrapper for compact results?
Create a WikipediaAPIWrapper and set its top-result count to one. Set the maximum document-content character value to 300 so the returned document is limited in length. Pass that configured wrapper to WikipediaQueryRun to create an invokable tool. The tutorial tests the resulting tool with a query about actor Shah Rukh Khan and receives a Wikipedia response.
Q: How do you use arXiv as an external chatbot tool?
Import ArxivAPIWrapper and ArxivQueryRun from the LangChain Community utilities and tools modules. Configure the wrapper to request one top result and limit document content to 300 characters, then pass it as the API wrapper for ArxivQueryRun. Invoking that tool with “Attention Is All You Need” returns research-paper information, including available author and paper details.
Q: How is chatbot state defined in LangGraph?
The chatbot state is defined as a State class based on TypedDict. Within that class, a messages variable is declared as an annotated list and connected to LangGraph’s add_messages function. This reducer updates the message collection when a node completes execution. The State class is then supplied to StateGraph so the graph can manage information throughout the workflow.
Q: Why does the LangGraph state use add_messages?
The add_messages function is used so the messages field can be updated after a workflow node finishes executing. The field belongs to the TypedDict-based State class and holds a list of message values. By associating the list with this reducer through Annotated, the graph can maintain conversation information as execution moves through the chatbot and its connected workflow components.
Q: What libraries are required for the LangGraph chatbot example?
The tutorial installs LangGraph, LangSmith, LangChain, LangChain Groq, and LangChain Community. The Groq integration allows the chatbot to communicate with the Groq API and access an open-source LLM. Separate Wikipedia and arXiv packages are also installed because their query wrappers cannot run without the corresponding dependencies. TypedDict and Annotated are imported to define the application state.
Summary & Key Takeaways
-
The tutorial introduces a multi-agent generative AI application built with LangGraph. Its chatbot processes each user query, interacts with an open-source LLM through the Groq API, and decides whether to answer directly or call an external information tool. The workflow ends after the selected path produces a response for the user.
-
The implementation begins by installing LangGraph, LangSmith, LangChain, the Groq integration, LangChain Community, Wikipedia, and arXiv packages. WikipediaAPIWrapper and ArxivAPIWrapper are configured to return one result with no more than 300 document-content characters, allowing both external services to be tested independently before they are connected to the workflow.
-
LangGraph manages the application through a State class based on TypedDict. Its messages field uses Annotated, a list, and the add_messages reducer so completed nodes can update the conversation. A StateGraph is then initialized with this state definition, creating the foundation for chatbot nodes, tool interactions, workflow transitions, and eventual completion.
Read in Other Languages (beta)
Share This Summary 📚
Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator
Explore More Summaries from Krish Naik 📚






Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator