The create_agent API vs. Building Your Own Graph
Explore the differences between LangChain's create_agent API and custom StateGraphs to understand when to use each approach. Learn how create_agent simplifies tool-calling assistants with a model-driven loop, while custom StateGraphs enable deterministic routing, parallel branches, and complex workflows. Discover how to embed create_agent agents within larger graphs for flexible AI application design.
We have now used two approaches to build similar assistants. In earlier chapters, we built custom StateGraph workflows by defining the nodes, edges, and conditional routes explicitly. The last two lessons introduced create_agent, which constructs a standard model-and-tools loop: the model requests tool calls, the tools execute, and their results return to the model until no further tool calls are requested. Middleware can then inspect, modify, or wrap model and tool execution. This lesson compares the two approaches, explains when each is appropriate, and shows how an agent created with create_agent can be embedded within a larger custom StateGraph.
What create_agent offers
create_agent constructs a standard model-and-tools loop: invoke the model, execute any tool calls ...