Member-only story

Simplest Graphs using LangGraph Framework

Pankaj Kumar
3 min readDec 31, 2024

Photo by GuerrillaBuzz on Unsplash

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()

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Pankaj Kumar
Pankaj Kumar

Written by Pankaj Kumar

MS Data Science SMU TX, MSc Financial Engg WQU. Interest in Algos, Discovering Trends in data. Worked 4 Hedge Funds n Inv banks https://vitvinyas.onrender.com/

Responses (1)

Write a response

Thank you so much for sharing this vital information regarding using langgraph framework.