LangGraphLangGraph 1.2 · Python 3.10+
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
37 small wins to finish your pathNext lesson

The short way

You have built the agent loop by hand. Now here is the one function that builds it for you, and the reason it was worth doing the long way first.

Open almost any tutorial and the first thing you see is a one line agent. It can make the twenty eight lessons behind you look like a waste. They were not, and this lesson is where that becomes clear.

The same tool as before

python
from langchain_core.tools import tool

@tool
def lookup_order(order_id: str) -> str:
    """Look up the status of an order by its id."""
    return f"Order {order_id} shipped on 3 March."

The whole of lesson 18, in one call

python
from langchain.agents import create_agent
from pretend_model import PretendModel

agent = create_agent(model=PretendModel(), tools=[lookup_order])

That is it. No state class, no nodes, no edges, no conditional branch, no ToolNode. One call, and you have the agent you spent lesson 18 wiring together.

Example
from langchain_core.messages import HumanMessage

for m in agent.invoke({"messages": [HumanMessage("Where is order A17?")]})["messages"]:
    print(f"{m.type:<6} {m.content!r}")

The same four messages, in the same order. It is the same loop, because create_agent builds a LangGraph graph underneath and hands it back compiled.

Look at what you were given

Example
print(list(agent.get_graph().nodes))

A model node and a tools node, with a start and an end. That is your lesson 18 graph, built by somebody else. Everything you learned about it still applies, because it is it.

What it takes

It accepts most of the things you spent this course learning, under the names you already know.

ArgumentWhat it is
modelThe chat model, from lesson 14.
toolsThe list to bind, from lesson 17.
system_promptThe instruction, from lesson 15.
checkpointerMemory across turns, from lesson 20.
response_formatA fixed answer shape, from lesson 19.
middlewareExtra steps around the loop. The one idea here you have not met.
python
agent = create_agent(
    model=PretendModel(),
    tools=[lookup_order],
    system_prompt="You are a support agent. Be brief.",
    checkpointer=InMemorySaver(),
)

Middleware is the one new word. It is a way to hook extra work into the loop, before the model runs or after a tool does, for things like retries or hiding private data. Worth knowing the name. Not worth learning until you want one.

So when do you build it yourself

Use create_agent when your program is a model with tools in a loop, which is a great many of them. It is less code to write and less code to get wrong.

Build the graph yourself the moment the shape stops being that loop. Every one of these is a real reason:

  • Steps that are not the model at all, like a database lookup that must always happen first.
  • Branching on something other than whether a tool was requested.
  • Two or three agents handing work between them, from lesson 27.
  • A step that fans out over a list, from lesson 28.
  • An approval that belongs to the graph rather than to one tool.
The point of everything before this
This is why the long way came first. When create_agent does not fit, you are not stuck waiting for a framework feature. You already know what it was doing, so you can write the graph and move on.
Try it yourself
  • Give it a system_prompt and confirm the messages come back the same.
  • Give it a checkpointer and a thread id, and hold a two turn conversation.
  • Print the agent's edges and compare them with your lesson 18 graph.

This is what real progress feels like.