Member-only story
Simplest Graphs using LangGraph Framework
Basic Graph In LangGraph
To define a graph we need to create nodes and edges. In LangGraph we have 2 pre defined nodes Start and End that can be used in any graph and we need to create intermediate nodes.
These intermediate nodes are functions that are assigned a node name. After defining nodes we can define edges in following ways :
from langgraph.graph import Graph, START, END
g = Graph()
Add Node
In this case I am adding a node which is just a lambda that returns the same values as it accepted as an argument. So its a sort off a pass through function which can also be defined as
def f(x):
return x
g.add_node("do_somthing",lambda x: x)
Add Edges
We are adding two edges one from START node to do_something node and another from this node to end node.
g.add_edge(START , "do_somthing")
g.add_edge("do_somthing" , END)
Compile Graph
Next step is to compile graph which a sort of constructs graph based on nodes and edges above.
graph = g.compile()