The plan: from a loop to a graph
What it is
We rebuild the Kirana Kart agent in five steps, each adding one capability the hand-written loop lacked:
- Tool execution: the same tools, declared for the framework.
- A graph workflow: the loop drawn as nodes and edges, with a routing step in front.
- Memory: saved conversation state, and a long-term store for customer facts.
- Human approval: a pause before large refunds.
- Multi-agent: a supervisor that delegates to specialist agents.
Install with pip install langgraph langchain langchain-anthropic and pin the versions.
Why it matters
Building the same agent a second way shows what the framework is actually doing.
- Every node here corresponds to a few lines of the module 10 loop.
- The parts that were hard by hand (resume after a crash, wait a day for approval) become configuration.
- The parts that were easy by hand (seeing the exact request) now need tracing turned on.
In the real world: A team ports its hundred-line agent to a graph in two days; most of the time goes on deciding where the node boundaries should be, not on code.
Visual example
TargetSix nodes. Only two of them call a model.
Porting the hand-written loop line by line into one node. Split it where you would want to observe, retry or interrupt: the model call, the tool run, the approval.