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
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:
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.
from langchain.agents import create_agent # the current, recommended builderBuilding 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.
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.
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.
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_agenttakes 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
modelandtools. - Deeper customization is done through middleware, and structured output through
response_format.
Hand-built loop vs create_agent
| Hand-built loop | create_agent | |
|---|---|---|
| Lines of code | A dozen or so | One call |
| Control over the flow | Full | Via middleware and options |
| Reach for it when | You need custom nodes or edges | A 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.
create_agent lives in langchain.agents and replaces langgraph.prebuilt.create_react_agent. Its prompt= argument is now system_prompt=.Related
- Previous: The agent loop
- Next: Checkpointer: memory across turns
- Reference: create_agent
- Build a
create_agentwith two tools and printagent.get_graph().nodes. - Compare the code length with the hand-built loop from the last lesson.
Little by little, you're building something great.