
LANGCHAIN — What Is LangGraph?
The advance of technology is based on making it fit in so that you don’t really even notice it, so it’s part of everyday life. — Bill Gates
LangGraph is a module built on top of LangChain to better enable the creation of cyclical graphs, often needed for agent runtimes. It adds new value primarily through the introduction of an easy way to create cyclical graphs, which is often useful when creating agent runtimes.
Motivation
LangGraph addresses the need for introducing cycles into the LangChain directed acyclic graphs (DAGs). It aims to facilitate the creation of agent runtimes that use the LangChain Language Model (LLM) to reason about the next steps in the cycle.
Functionality
At its core, LangGraph exposes a narrow interface on top of LangChain. The primary class is StateGraph, which represents the graph and can be initialized with a state definition. Nodes and edges can be added to create the graph, and it can be compiled into a runnable for execution.
Examples
StateGraph
from langgraph.graph import StateGraph
from typing import TypedDict, List, Annotated
import Operator
class State(TypedDict):
input: str
all_actions: Annotated[List[str], operator.add]
graph = StateGraph(State)Adding Nodes
graph.add_node("model", model)
graph.add_node("tools", tool_executor)Adding Edges
graph.set_entry_point("model")
graph.add_edge("tools", "model")
graph.add_conditional_edge(
"model",
should_continue,
{
"end": END,
"continue": "tools"
}
)Compile
app = graph.compile()Agent Executor
LangGraph provides a way to recreate the LangChain AgentExecutor. It allows modification of the internals of the AgentExecutor and contains familiar state concepts.
Chat Agent Executor
For models operating on a list of messages, LangGraph provides an agent runtime that works with this state.
Modifications
LangGraph exposes the logic of AgentExecutor in a more natural and modifiable way. Examples include forcing the agent to call a tool first, adding a human-in-the-loop step, and managing agent steps.
Future Work
Future implementations include more advanced agent runtimes from academia, stateful tools, more controlled human-in-the-loop workflows, and multi-agent workflows.
LangGraph offers a powerful way to create custom and powerful agent runtimes, and users are encouraged to explore and contribute examples to the LangGraph repository or reach out at [email protected] for collaboration.
In conclusion, LangGraph opens new possibilities for creating agent runtimes and offers a platform for collaboration and further development.
