Skip to content

A simple yet effective chatbot built using LangGraph and OpenAI, designed to handle context-aware conversations by leveraging the full message history. This project showcases a structured, modular approach to chatbot development, moving beyond the typical infinite-loop implementations.

License

Notifications You must be signed in to change notification settings

AllwynJesu/langgraph-simple-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

langgraph-simple-chatbot

LangGraph Chatbot Example

Overview

This project demonstrates how to create a context-aware simple chatbot using LangGraph. Unlike many examples found on YouTube, Udemy, and Medium, which often repeat the same code pattern (an infinite while loop for collecting user input and directly invoking graph.invoke or graph.stream), this implementation is a true chatbot. It ensures context-aware responses by maintaining the entire message history throughout the conversation.

The main goal is to demonstrate how to build a basic chatbot that retains context using a structured graph-based approach. While there are many ways to implement chatbots, such as integrating human-in-the-loop workflows or multi-turn conversation branching, this project focuses on showcasing the fundamentals of a simple chatbot design.


Features

  • Stateful Conversations: The bot maintains context across multiple interactions using a message history.
  • Context-Aware Responses: Generates seamless replies based on the entire conversation history, avoiding repetition or missed details.

Prerequisites

To use this project, ensure you have the following:

  1. Python 3.9 or higher.
  2. Poetry for dependency management.
  3. A valid OpenAI API key.

Installation

Follow these steps to set up and run the chatbot:

  1. Clone the repository:

    git clone [email protected]:AllwynJesu/langgraph-simple-chatbot.git
    cd langgraph-simple-chatbot
  2. Install dependencies using Poetry:

    poetry install
  3. Create a .env file in the project root directory and add your OpenAI API key:

    OPENAI_API_KEY=your_openai_api_key
  4. Run the chatbot:

    poetry run python bot.py

Usage

  1. Start the chatbot by running the script.
  2. Enter your messages at the User: prompt.
  3. The chatbot will provide context-aware responses based on the conversation history.
  4. To exit, type quit, exit, or q.

How It Works

The chatbot is designed using LangGraph's StateGraph to manage the conversation flow efficiently. Here's an outline of the workflow:

  1. User Input: The program starts at the USER_INPUT_NODE, where it collects the user's input.
  2. Decision Point: A conditional check determines if the conversation should continue or end.
  3. Bot Response: If continuing, the bot generates a response using OpenAI's GPT model by leveraging the entire message history.
  4. Loop: The response is displayed, and the flow returns to the USER_INPUT_NODE.

License

This project is open-source and licensed under the MIT License. Contributions are welcome!


About

A simple yet effective chatbot built using LangGraph and OpenAI, designed to handle context-aware conversations by leveraging the full message history. This project showcases a structured, modular approach to chatbot development, moving beyond the typical infinite-loop implementations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages