AI / LangGraph LangChain Interview questions
How do nodes and edges work in LangGraph?
In LangGraph, nodes are Python functions that contain the logic of your application, and edges are the connections that define execution flow between nodes.
Nodes receive the current state dict and return a partial state update (a dict containing only the keys they want to change). LangGraph merges this update into the full state using the defined reducers:
def tool_node(state: AgentState) -> dict:
# Execute the tool called by the last message
last_message = state["messages"][-1]
tool_result = tools_by_name[last_message.tool_calls[0]["name"]].invoke(
last_message.tool_calls[0]["args"]
)
return {"messages": [ToolMessage(content=str(tool_result), ...)]}
Edges come in two flavours:
- Normal edges — always go from node A to node B:
graph.add_edge("node_a", "node_b") - Conditional edges — a router function decides the next node:
graph.add_conditional_edges("node_a", router_fn, {"tool": "tool_node", "end": END})
Two special node names mark the graph boundaries: START is the entry point (no logic, just the first edge target), and END is the terminal node that signals the graph has finished. A node can have multiple outgoing edges but only one edge can be triggered per invocation (conditional edges are mutually exclusive).
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
