CoolFace
Apppublic

genaitiwari/langgraph

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
1likes
App README

πŸš€ LangGraph: Building Stateful AI Agents as Graphs

Official Links


πŸ“Œ Overview

LangGraph is a Python library for creating stateful, multi-step AI workflows using Large Language Models (LLMs). It enables dynamic decision-making through graph-based architectures, allowing developers to design agents that loop, branch, and interact with tools/APIs. Inspired by Pregel and Apache Beam, it’s widely used by companies like LinkedIn, Uber, and Elastic.


πŸ”‘ Key Features

  1. 1.Graph-Based Workflows
  2. 2.Define workflows as nodes (tasks) and edges (connections).
  3. 3.Supports conditional edges (e.g., "If tool call needed, route to tools node").
  1. 1.State Management
  2. 2.Persist conversation history, tool outputs, or custom data across interactions using checkpoints.
  1. 1.Multi-Actor Support
  2. 2.Build collaborative agents (e.g., one agent retrieves data, another generates responses).
  1. 1.Prebuilt Agents
  2. 2.Use templates like create_react_agent for ReAct-style agents or customize workflows.
  1. 1.LangGraph Platform (Commercial)
  2. 2.Deploy agents at scale with streaming, background runs, and monitoring.

πŸ› οΈ Getting Started

Installation

bash
pip install -U langgraph  # Core library 
pip install langchain_groq streamlit  # For Groq models and Streamlit UI

Basic Example: ReAct Agent

python
from langgraph.prebuilt import create_react_agent
from langchain_groq import ChatGroq  # Changed import
import os

# Define a search tool (remains the same)
@tool
def search(query: str):
    if "san francisco" in query.lower():
        return "60Β°F, foggy"
    return "90Β°F, sunny"

# Initialize agent with Groq
model = ChatGroq(
    temperature=0,
    model_name="mixtral-8x7b-32768"  # Groq model name
)
checkpointer = MemorySaver()  # Persists state
app = create_react_agent(model, [search], checkpointer=checkpointer)

# Invoke with thread_id for state retention (same)
response = app.invoke(
    {"messages": [{"role": "user", "content": "Weather in SF?"}]},
    config={"configurable": {"thread_id": 42}}
)
print(response["messages"][-1].content)  # Outputs weather details

Key:

  1. 1.Uses langchain_groq.ChatGroq
  2. 2.Specifies Groq model name (mixtral-8x7b-32768 or llama2-70b-4096)
  3. 3.Requires GROQ_API_KEY environment variable

Set your API key:

python
os.environ["GROQ_API_KEY"] = "your-key-here"

πŸš€ Running the Streamlit App

This project includes a Streamlit-based web interface for interacting with the Groq ReAct Agent. Follow the steps below to set up and run the app.

Prerequisites

  1. 1.Python 3.8+: Ensure Python is installed on your system.
  2. 2.Groq API Key: Obtain your API key from the Groq Cloud Console.

Steps to Run

  1. 1.Clone the repository:
bash
   git clone https://github.com/aitiwari/langgraph.git
   cd langgraph
  1. 1.Install the required dependencies:
bash
   pip install -r requirements.txt
  1. 1.Set your Groq API key as an environment variable:
bash
   export GROQ_API_KEY="your-api-key-here"
  1. 1.Start the Streamlit app:
bash
   streamlit run app.py
  1. 1.Open your browser and navigate to the URL provided in the terminal (usually http://localhost:8501).

Using the App

  • β€”Input Field: Type your question or query in the chat input box at the bottom of the screen.
  • β€”Chat History: The conversation history will be displayed above the input field.
  • β€”API Key: If you didn't set the GROQ_API_KEY environment variable, you'll be prompted to enter it in the app.

Example Queries

  • β€”"What's the weather in San Francisco?"
  • β€”"Tell me about the weather in New York."

Stopping the App

To stop the Streamlit app, press Ctrl+C in the terminal where the app is running.


🌟 Use Cases

1. Basic Chatbot

Prompt: What is generative AI? Reference: [image]

2. Chatbot with Tool

Prompt: Latest news from the India vs Australia match? Reference: [image]

3. Appointment Receptionist

Prompt 1: Book an appointment for priti. Prompt 2: Yes or No. Reference: [image] [image]

4. Customer Support

Reference: [image] [image]


πŸ“š Templates & Community

Explore prebuilt templates for chatbots, retrieval agents, and more:

bash
langgraph new  # CLI to create apps from templates 
TemplateDescriptionLink
ReAct AgentTool-calling agent with memoryGitHub
Retrieval AgentRAG with dynamic context fetchingDocs

πŸ“– References

  1. 1.Official Documentation
  2. 2.GitHub Examples
  3. 3.Agentic RAG Guide
  4. 4.Production Case Studies

For advanced use cases (multi-agent systems, human-in-the-loop), refer to the LangGraph Platform or explore the LangChain Academy.


This version integrates the Streamlit app instructions seamlessly into the existing structure while maintaining the original tone and style.