Clone the repo, install dependencies, and run the LangGraph text analysis pipeline in under ten minutes. No prior setup required beyond Python and pip.
Use this file to discover all available pages before exploring further.
This guide walks you through cloning the repository and running the LangGraph stateful workflow tutorial — a three-step text analysis pipeline that classifies, extracts entities from, and summarizes any text you give it. The same steps apply to every other tutorial in the repo.
The notebook builds a three-node stateful pipeline that processes text through sequential stages. Each stage operates as an independent node in a directed graph.
State definition
Processing nodes
Graph assembly
Running the pipeline
from typing import TypedDict, Listfrom langgraph.graph import StateGraph, ENDfrom langchain_openai import ChatOpenAIclass State(TypedDict): text: str classification: str entities: List[str] summary: str# Use temperature=0 for deterministic outputsllm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
from langchain_core.prompts import PromptTemplatefrom langchain_core.messages import HumanMessagedef classification_node(state: State): prompt = PromptTemplate( input_variables=["text"], template="Classify the following text into one of the categories: " "News, Blog, Research, or Other.\n\nText:{text}\n\nCategory:" ) message = HumanMessage(content=prompt.format(text=state["text"])) classification = llm.invoke([message]).content.strip() return {"classification": classification}def entity_extraction_node(state: State): prompt = PromptTemplate( input_variables=["text"], template="Extract all the entities (Person, Organization, Location) " "from the following text. Provide the result as a " "comma-separated list.\n\nText:{text}\n\nEntities:" ) message = HumanMessage(content=prompt.format(text=state["text"])) entities = llm.invoke([message]).content.strip().split(", ") return {"entities": entities}def summarization_node(state: State): prompt = PromptTemplate( input_variables=["text"], template="Summarize the following text in one short " "sentence.\n\nText:{text}\n\nSummary:" ) message = HumanMessage(content=prompt.format(text=state["text"])) summary = llm.invoke([message]).content.strip() return {"summary": summary}
# Build the workflow graphworkflow = StateGraph(State)workflow.add_node("classification_node", classification_node)workflow.add_node("entity_extraction", entity_extraction_node)workflow.add_node("summarization", summarization_node)# Wire the nodes in sequenceworkflow.set_entry_point("classification_node")workflow.add_edge("classification_node", "entity_extraction")workflow.add_edge("entity_extraction", "summarization")workflow.add_edge("summarization", END)app = workflow.compile()
sample_text = """OpenAI has announced the GPT-4 model, which is a large multimodal modelthat exhibits human-level performance on various professional benchmarks.It is developed to improve the alignment and safety of AI systems.Additionally, the model is designed to be more efficient and scalablethan its predecessor, GPT-3."""result = app.invoke({"text": sample_text})print("Classification:", result["classification"])print("\nEntities:", result["entities"])print("\nSummary:", result["summary"])
Expected output:
Classification: NewsEntities: ['OpenAI', 'GPT-4', 'GPT-3']Summary: OpenAI's upcoming GPT-4 model is a multimodal AI that aims forhuman-level performance and improved safety, efficiency, and scalabilitycompared to GPT-3.
The same steps apply to every tutorial in the repository. Navigate to the tutorial directory, install its requirements.txt, and run its notebook or app.py.
cd tutorials/agent-memory-with-redispip install -r requirements.txtjupyter notebook *.ipynb
Read the README.md inside each tutorial folder first. It explains what the tutorial covers, what credentials you need, and any service-specific setup steps.