Yesterday, we learned that LangGraph is all about nodes and edges. Today, weβre putting that into practice by building a Stateful Agent that can actually "think," use a tool, and then decide if it needs to do more.
In the old way (Chains), if a tool returned an error, the app crashed. In the LangGraph way, we create a loop where the agent sees the error and tries a different approach.
π§ The Agentic Loop: Thought β Action β Observation
To build this, we need a graph that doesn't just go in a straight line. We need it to circle back.
Agent Node: The LLM decides what to do.
Tools Node: If the LLM wants to use a tool, this node executes it.
The Loop: The result of the tool goes back to the Agent so it can "observe" the result and decide if it's done.
π οΈ Coding the Loop
We'll use the ToolNode βa pre-built helper from LangGraphβto make this easy.
from typing import Annotated , TypedDict from langgraph.graph import StateGraph , START , END from langgraph.graph.message import add_messages fromβ¦