LangGraphLangGraph 1.2 · Python 3.10+
Dashboard
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

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.

create_agent and a weather function as a tool · from the Complete Agentic AI Course In 10 Hours · 27:57 to 31:36

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.

Running the weather agent with a messages dictionary · from the Complete Agentic AI Course In 10 Hours · 31:36 to 35:15

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:

ExampleAPI keyFrom the video, run on Groq
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}")

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

python
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.

ExampleAPI key
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))

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.

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

Building 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.

python
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.

python
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.

ExampleAPI key
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)

What create_agent builds

  • create_agent takes a model, a list of tools, and an optional system prompt, and returns a compiled graph.
  • model takes a provider string, as here, or a model object built with init_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 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.
PreviousAgent loop

Little by little, you're building something great.