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

create_agent: the short way

create_agent builds the whole model-and-tools loop for you in one call. It is the current, recommended way and replaces the older create_react_agent.

Last updated: 27 Sep, 2026 · LangChain 1.4

You built the agent loop by hand to understand it. In real code you reach for create_agent, which wires the same loop and lets you customize it.

The create_agent call

python
from langchain.agents import create_agent

agent = create_agent(
    model="openai:gpt-4.1",
    tools=[lookup_order],
    system_prompt="You are a support assistant.",
)
result = agent.invoke({"messages": [{"role": "user", "content": "Where is order A17?"}]})

You need a model key to call the agent, but you can build it and read its structure without one. It is the same call-model then run-tools loop you wired by hand:

python
from langchain.agents import create_agent
from langchain.tools import tool

@tool
def lookup_order(order_id: str) -> str:
    """Look up an order by id."""
    return f"Order {order_id}: shipped."

agent = create_agent(
    model="openai:gpt-4.1",
    tools=[lookup_order],
    system_prompt="You are a support assistant.",
)
print(list(agent.get_graph().nodes))

That prints ['__start__', 'model', 'tools', '__end__']: the model node, the tools node, and the start and end LangGraph adds.

With a real key, result["messages"][-1].content holds the answer, for example Order A17 was shipped on 3 March.

The whole model-and-tools loop fits in one call. Read it one piece at a time, then see it together. It needs a model key to run, so the pieces below are shown as code to read.

The import

Import create_agent from langchain.agents. This is the current builder and replaces the older create_react_agent.

python
from langchain.agents import create_agent   # the current, recommended builder

Building the agent

Call it with three things: the model name, the list of tools, and a system prompt that tells the agent its job. It returns a compiled graph with the same call-model then run-tools loop you wired by hand.

python
agent = create_agent(
    model="openai:gpt-4.1",                        # which model to call
    tools=[lookup_order],                          # the tools it may use
    system_prompt="You are a support assistant.",  # its standing instruction
)

Invoking the agent

Invoke the agent like any graph. Pass a list of messages, here one user message. The agent calls the model, runs any tool it asks for, and returns the final messages.

python
result = agent.invoke({"messages": [{"role": "user", "content": "Where is order A17?"}]})

The whole agent in one block

The three pieces together. Swap in your own model string to run it.

python
from langchain.agents import create_agent

agent = create_agent(
    model="openai:gpt-4.1",
    tools=[lookup_order],
    system_prompt="You are a support assistant.",
)
result = agent.invoke({"messages": [{"role": "user", "content": "Where is order A17?"}]})

What create_agent builds

  • create_agent takes a model, a list of tools, and an optional system prompt, and returns a compiled graph.
  • It builds the same call-model then run-tools loop from the last lesson; the graph typically has nodes named model and tools.
  • Deeper customization is done through middleware, and structured output through response_format.

Hand-built loop vs create_agent

Hand-built loopcreate_agent
Lines of codeA dozen or soOne call
Control over the flowFullVia middleware and options
Reach for it whenYou need custom nodes or edgesA standard model-and-tools agent

Where create_agent fits

  • The fastest way to a working tool-using agent.
  • When your flow is only a model with tools in a loop, not a custom graph.
Watch out. create_agent lives in langchain.agents and replaces langgraph.prebuilt.create_react_agent. Its prompt= argument is now system_prompt=.
Try it yourself
  • Build a create_agent with two tools and print agent.get_graph().nodes.
  • Compare the code length with the hand-built loop from the last lesson.

Little by little, you're building something great.