Spaces:
Running
A newer version of the Streamlit SDK is available:
1.46.0
title: Langgraph
emoji: π
colorFrom: yellow
colorTo: red
sdk: streamlit
sdk_version: 1.41.1
app_file: app.py
pinned: false
license: apache-2.0
short_description: Langgraph
π 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
Graph-Based Workflows
- Define workflows as nodes (tasks) and edges (connections).
- Supports conditional edges (e.g., "If tool call needed, route to tools node").
State Management
- Persist conversation history, tool outputs, or custom data across interactions using checkpoints.
Multi-Actor Support
- Build collaborative agents (e.g., one agent retrieves data, another generates responses).
Prebuilt Agents
- Use templates like
create_react_agent
for ReAct-style agents or customize workflows.
- Use templates like
LangGraph Platform (Commercial)
- Deploy agents at scale with streaming, background runs, and monitoring.
π οΈ Getting Started
Installation
pip install -U langgraph # Core library
pip install langchain_groq streamlit # For Groq models and Streamlit UI
Basic Example: ReAct Agent
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:
- Uses
langchain_groq.ChatGroq
- Specifies Groq model name (
mixtral-8x7b-32768
orllama2-70b-4096
) - Requires
GROQ_API_KEY
environment variable
Set your API key:
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
- Python 3.8+: Ensure Python is installed on your system.
- Groq API Key: Obtain your API key from the Groq Cloud Console.
Steps to Run
Clone the repository:
git clone https://github.com/aitiwari/langgraph.git cd langgraph
Install the required dependencies:
pip install -r requirements.txt
Set your Groq API key as an environment variable:
export GROQ_API_KEY="your-api-key-here"
Start the Streamlit app:
streamlit run app.py
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:
2. Chatbot with Tool
Prompt: Latest news from the India vs Australia match?
Reference:
3. Appointment Receptionist
Prompt 1: Book an appointment for priti.
Prompt 2: Yes or No.
Reference:
4. Customer Support
π Templates & Community
Explore prebuilt templates for chatbots, retrieval agents, and more:
langgraph new # CLI to create apps from templates
Template | Description | Link |
---|---|---|
ReAct Agent | Tool-calling agent with memory | GitHub |
Retrieval Agent | RAG with dynamic context fetching | Docs |
π References
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.