create_agent
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: 29 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.
A weather agent in one call
The LangChain section of the video imports create_agent from langchain.agents and gives it a model, a list of tools and the system prompt "You are a helpful assistant.". With an empty tools list the drawn graph has only a start, the model and an end. Adding a plain function, get_weather, connects the model to a tools node: create_agent wraps the function as a tool, and its name, type hints and docstring are what the model reads.
The agent takes a dictionary with a messages key. The video's example runs below on Groq instead of OpenAI's gpt-5, and prints one line per message where the video prints the raw result:
from langchain.agents import create_agent
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"The weather in {city} is sunny."
agent = create_agent(
model="groq:openai/gpt-oss-120b",
tools=[get_weather],
system_prompt="You are a helpful assistant.",
)
response = agent.invoke({"messages": [{"role": "user", "content": "What is the weather like in New York?"}]})
for message in response["messages"]:
print(f"{message.type:<5} {message.text or message.tool_calls}")human What is the weather like in New York?
ai [{'name': 'get_weather', 'args': {'city': 'New York'}, 'id': 'fc_aa4faf42-774c-4030-8205-178cd2a3bdba', 'type': 'tool_call'}]
tool The weather in New York is sunny.
ai The current weather in New York is sunny. Enjoy the clear skies!The four messages are the ReAct loop from the agent-loop lesson: the question, the tool call, the tool's result and the answer. Below, the support agent gets the same one-call build around an order lookup.
The create_agent call
from langchain.agents import create_agent
agent = create_agent(
model="groq:openai/gpt-oss-120b",
tools=[lookup_order],
system_prompt="You are the support assistant for a small online shop. "
"Answer in one short sentence, using only what the tools returned.",
)
result = agent.invoke({"messages": [{"role": "user", "content": "Where is order A17?"}]})create_agent builds the model client as it wires the graph, so the key must be set before you build it. Print the graph to see it is the same call-model, run-tools loop you built 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 on 3 March."
agent = create_agent(
model="groq:openai/gpt-oss-120b", # uses your GROQ_API_KEY
tools=[lookup_order],
system_prompt="You are the support assistant for a small online shop. "
"Answer in one short sentence, using only what the tools returned.",
)
print(list(agent.get_graph().nodes))['__start__', 'model', 'tools', '__end__']
The model node, the tools node, and the start and end nodes LangGraph adds: the same shape as the hand-built loop.
Read the call one piece at a time, then run it whole.
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 string, the list of tools, and a system prompt that tells the agent its job. It returns a compiled graph.
agent = create_agent(
model="groq:openai/gpt-oss-120b", # which model to call
tools=[lookup_order], # the tools it may use
system_prompt="You are the support assistant for a small online shop. "
"Answer in one short sentence, using only what the tools returned.", # 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 pieces together, with the tool, in one file you can run.
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 on 3 March."
agent = create_agent(
model="groq:openai/gpt-oss-120b", # uses your GROQ_API_KEY
tools=[lookup_order],
system_prompt="You are the support assistant for a small online shop. "
"Answer in one short sentence, using only what the tools returned.",
)
result = agent.invoke({"messages": [{"role": "user", "content": "Where is order A17?"}]})
print(result["messages"][-1].content)Order A17 was shipped on 3 March.
What create_agent builds
create_agenttakes a model, a list of tools, and an optional system prompt, and returns a compiled graph.modeltakes a provider string, as here, or a model object built withinit_chat_model, as the multi-agent lesson does.- 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: Agent loop
- Next: Checkpointer
- 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.