An open API service indexing awesome lists of open source software.

https://github.com/vipulpathak113/langgraph-chatbot

A Chat bot created using langgrapgh having memory, Human in loop, persistence
https://github.com/vipulpathak113/langgraph-chatbot

ai artificial-intelligence chatbot langchain langgraph memory

Last synced: 3 months ago
JSON representation

A Chat bot created using langgrapgh having memory, Human in loop, persistence

Awesome Lists containing this project

README

          

# πŸ€– LangGraph: Intelligent Workflow Framework

## πŸ“– Table of Contents
- [What is LangGraph?](#what-is-langgraph)
- [Why Use LangGraph?](#why-use-langgraph)
- [Use Cases & Applications](#use-cases--applications)
- [Key Features & Functionality](#key-features--functionality)
- [Our Chatbot Implementation](#our-chatbot-implementation)
- [Setup & Installation](#setup--installation)
- [Examples & Demos](#examples--demos)
- [Resources & Links](#resources--links)

## What is LangGraph?
LangGraph is like a smart conductor orchestrating different parts of an AI system. Imagine you're building a puzzle - each piece needs to fit perfectly with others and work together smoothly. That's what LangGraph does for AI applications

It helps create intelligent workflows by:
- Managing how different parts of the system talk to each other
- Remembering important information
- Knowing when to ask humans for help
- Handling multiple tasks at once

## Why Use LangGraph?

### 🎯 Problem It Solves
Many AI applications face challenges like:
- Losing context during conversations
- Not knowing when to ask for human help
- Difficulty managing complex workflows
- Problems coordinating multiple tasks

LangGraph provides solutions to these challenges through its structured workflow system.

### ✨ Benefits
- **Organized Workflows**: Like having a well-planned recipe for cooking
- **Smart Memory**: Never forgets important details
- **Human Integration**: Knows when to ask for help
- **Flexible Design**: Can be adapted for many different uses

### βš–οΈ Pros and Cons

#### Pros:
- Easy to manage complex workflows
- Built-in memory management
- Seamless human integration
- Highly scalable
- Works with popular AI tools

#### Cons:
- Learning curve for beginners
- Requires some technical setup
- May be complex for simple tasks

## Use Cases & Applications

### πŸ€– Chatbots
- Customer service bots
- Educational assistants
- Healthcare support systems
- Sales assistants

### 🎯 Intelligent Agents
- Task automation agents
- Research assistants
- Data analysis helpers

### 🏒 Business Applications
- Workflow automation
- Decision support systems
- Process management

## Key Features & Functionality

### 1. 🧠 Memory System
#### What is it?
Think of it like a digital notebook that remembers everything important.

#### Why need it?
- Maintains context across conversations
- Remembers user preferences
- Enables personalized interactions

#### How to use it?
```python
# Example of using memory
from langgraph.memory import ConversationMemory

memory = ConversationMemory()
memory.add("user preference", "likes quick responses")
```

### 2. 🀝 Human-in-the-Loop
#### What is it?
System knows when to ask humans for help.

#### Why need it?
- Handles complex situations
- Provides backup for uncertain cases
- Builds user trust

#### How to use it?
```python
# Example of human handoff
if complexity_level > threshold:
notify_human_agent(conversation_context)
```

### 3. πŸ”„ State Management
#### What is it?
Keeps track of where you are in a process.

#### Why need it?
- Maintains order in workflows
- Ensures proper process flow
- Handles transitions smoothly

## Our Chatbot Implementation

### πŸ€– LangGraph Chatbot
This chatbot is built using **LangGraph**, a framework that helps create intelligent chatbots with advanced features like *memory* and *human-in-the-loop* functionality. Let's break down what these features mean, why they are useful, and how they work in this chatbot.

### 1. Memory in the Chatbot
#### What is Memory in a Chatbot?
Imagine talking to a customer service agent who remembers everything you've said during the conversation. You don't have to repeat yourself, and they can refer back to earlier parts of the conversation to provide better answers. That's what "*memory*" in a chatbot doesβ€”it allows the chatbot to remember past interactions during a session or even across multiple sessions.

#### Why is Memory Useful?
* **Personalized Experience**: The chatbot can remember your preferences or past questions, making the interaction feel more personal.
* **Efficiency**: You don't have to repeat information you've already provided, saving time and effort.
* **Context Awareness**: The chatbot can use past messages to provide more accurate and relevant responses.

#### How Does It Work in This Chatbot?
In this chatbot:

* Every message you send is stored in a "*state*" (a kind of memory).
* When you return to the chatbot later, it can load your previous conversation and pick up where you left off.
* This memory is stored in a database (*SQLite* in this case), so it persists even if you close the chatbot and come back later.

**For example**:
> If you ask, "What's the weather today?" and then later ask, "What about tomorrow?", the chatbot remembers that you're talking about the weather and provides a relevant response.

### 2. Human-in-the-Loop Functionality
#### What is Human-in-the-Loop?
Sometimes, chatbots can't handle everything on their own. For example, if you ask a very complex question or need help with something sensitive, the chatbot can involve a human to assist you. This is called "*human-in-the-loop*" functionality.

#### Why is Human-in-the-Loop Useful?
* **Accuracy**: Humans can step in when the chatbot doesn't understand or when the situation requires human judgment.
* **Trust**: Users feel more confident knowing that a human can help if needed.
* **Flexibility**: It allows the chatbot to handle a wider range of scenarios, even those it wasn't specifically trained for.

#### How Does It Work in This Chatbot?
In this chatbot:

* If the chatbot encounters a situation it can't handle, it can *escalate* the conversation to a human agent.
* The chatbot *pauses* its workflow and allows the human to take over, ensuring the user gets the help they need.

**For example**:
> If you're using the chatbot to book a flight and you have a very specific request (like combining multiple discounts), the chatbot might not know how to handle it. Instead of giving a wrong answer, it can notify a human agent to assist you.

### Why Are These Features Good to Have?

#### Memory
* Makes the chatbot feel more **intelligent** and **human-like**.
* Improves user satisfaction by reducing repetitive interactions.
* Enables *long-term conversations*, which are essential for applications like therapy bots, customer support, or personal assistants.

#### Human-in-the-Loop
* Ensures that users **always** get the help they need, even if the chatbot isn't perfect.
* Builds trust by showing that there's always a fallback option.
* Allows businesses to use chatbots for complex tasks without worrying about losing customers due to chatbot errors.

### How to Use These Features in the Chatbot

#### Memory
1. **Start a Conversation**: When you start chatting, the chatbot automatically remembers everything you say.
2. **Continue a Conversation**: If you leave and come back later, the chatbot can load your previous messages and continue the conversation seamlessly.
3. **Switch Between Threads**: You can have multiple conversations (threads) with the chatbot, and it remembers each one separately.

> *In the chatbot UI, you can see a list of all your threads in the sidebar. Click on a thread to load its history.*

#### Human-in-the-Loop
* **Trigger Human Assistance**: If the chatbot doesn't understand your question or can't handle your request, it will notify a human agent.
* **Seamless Transition**: The human agent can see the conversation history and take over without asking you to repeat yourself.
* **Return to the Chatbot**: Once the human agent resolves your issue, the chatbot can resume the conversation.

### Why This Chatbot is Special
This chatbot combines the best of both worlds:

* **Automation**: It uses AI to handle repetitive and straightforward tasks quickly and efficiently.
* **Human Support**: It ensures that users always have access to human help when needed.

This makes it ideal for businesses and applications where:
* Users expect *personalized* and *high-quality* interactions
* Complex or sensitive issues may arise
* Long-term memory and context are important

## Summary
The **LangGraph chatbot** is designed to provide a smart, efficient, and user-friendly experience by combining advanced AI features with human support. Its *memory* ensures that conversations are seamless and personalized, while its *human-in-the-loop* functionality guarantees that users always get the help they need, no matter how complex the situation.

By using **LangGraph**, this chatbot is not just a toolβ€”it's a reliable assistant that adapts to your needs and ensures you're always supported.

## Setup & Installation

### Prerequisites
- Python 3.7+
- pip package manager

### Installation Steps
```bash
# 1. Clone the repository
git clone https://github.com/yourusername/langgraph-chatbot

# 2. Install dependencies
pip install -r requirements.txt

# 3. Set up environment variables
cp .env.example .env
```

### Running the Chatbot
```bash
streamlit run chatbot_ui.py
```

## Examples & Demos

### Basic Conversation
```
User: "What's the weather today?"
Bot: "It's sunny and 75Β°F in New York."
User: "What about tomorrow?"
Bot: "Tomorrow will be partly cloudy, 72Β°F"
```

### Complex Scenario with Human Handoff
```
User: "I need to combine multiple discounts"
Bot: "This is complex. Let me connect you with a specialist..."
[Human Agent]: "I can help you with that..."
```

## Resources & Links

### πŸ“š Documentation
- [LangGraph Documentation](https://python.langchain.com/docs/langgraph)
- [API Reference](https://api.python.langchain.com/en/latest/langgraph)

### πŸ”— Useful Links
- [GitHub Repository](https://github.com/langchain-ai/langgraph)
- [Community Forum](https://github.com/langchain-ai/langgraph/discussions)
- [Tutorial Videos](https://www.youtube.com/results?search_query=langgraph+tutorial)