What is create_agent?
create_agent() is the high-level entry point in LangChain v1 for building tool-calling agents. It replaces the older initialize_agent and AgentExecutor APIs with a single function that wires up a ReAct-style loop for you: the model is called, any tool calls it emits are executed, the results are fed back, and the cycle repeats until the model returns a final answer. Under the hood it builds and compiles a LangGraph graph, so what you get back is a fully-featured Runnable with invoke, ainvoke, stream, and astream.
You pass a chat model and a list of tools; optionally a system prompt to steer behaviour, middleware to hook into each step, a checkpointer to persist conversation state, and a response_format for structured final output. Because the result is a graph, it speaks the messages-based state convention: you invoke it with {"messages": [...]} and read the final answer from the last message in the returned state. Tools are bound automatically — you do not call bind_tools yourself.
create_agent is the recommended starting point for most agents because it removes boilerplate while staying inspectable: you can stream intermediate steps, attach a MemorySaver checkpointer for multi-turn memory, and add human-in-the-loop interrupts through middleware. When you need control it cannot express — custom branching, parallel tool fan-out, or bespoke state — drop down to StateGraph directly and build the loop yourself. The two share the same runtime, so graduating from create_agent to a hand-written graph is incremental, not a rewrite.
When to Use
You're building an agent. Use create_agent() for the recommended v1 approach.
Use Cases
- • Create LLM agents
- • Tool-using AI
- • Agentic workflows
- • Auto task solving
- • Autonomous agents
- • Multi-step reasoning
Key Features
- ✓ Simple creation
- ✓ Auto tool binding
- ✓ Middleware support
- ✓ State management
- ✓ Checkpointing
- ✓ Streaming
When NOT to Use
For custom agent logic—use StateGraph directly.
Notes
It returns a graph, not an AgentExecutor
create_agent compiles a LangGraph graph and returns a Runnable. Invoke it with {"messages": [...]} and read the answer from result["messages"][-1].content. This messages-based state convention replaces the old AgentExecutor.run / initialize_agent flow from pre-v1 LangChain.
Tools are bound automatically
Pass plain @tool-decorated functions in the tools list — do not call bind_tools on the model yourself. create_agent binds them internally. Double-binding can produce duplicate tool schemas and confuse the model about which tools exist.
Memory needs a checkpointer and a thread_id
Agents are stateless across calls unless you pass a checkpointer (e.g. MemorySaver) and a config with configurable.thread_id. The thread_id keys the conversation; reuse it to continue a session and change it to start fresh. Without both, every invoke is a clean slate.
Drop to StateGraph when you outgrow it
create_agent covers the standard ReAct loop. For custom branching, parallel tool fan-out, or bespoke state you need StateGraph directly. They share the same runtime, so moving from create_agent to a hand-written graph is incremental rather than a rewrite.
Import
from langchain import create_agent
Key Parameters
| Parameter | Type | Default | Purpose |
|---|---|---|---|
| model | ChatModel | None | Language model to use |
Code Examples
Create a tool-calling agent
from langchain import create_agent
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model='gpt-4o')
agent = create_agent(model, tools=[search_tool, calculator_tool])
result = agent.invoke({'messages': [HumanMessage(content='What is 23 * 17?')]})
print(result['messages'][-1].content)
System prompt and streamed steps
from langchain import create_agent
from langchain_openai import ChatOpenAI
agent = create_agent(
ChatOpenAI(model='gpt-4o'),
tools=[search_tool],
system_prompt='You are a concise research assistant. Cite sources.',
)
for step in agent.stream({'messages': [HumanMessage(content='Latest on RAG?')]}):
print(step)
Persist memory across turns with a checkpointer
from langchain import create_agent
from langgraph.checkpoint.memory import MemorySaver
from langchain_openai import ChatOpenAI
agent = create_agent(
ChatOpenAI(model='gpt-4o'),
tools=[search_tool],
checkpointer=MemorySaver(),
)
config = {'configurable': {'thread_id': 'user-42'}}
agent.invoke({'messages': [HumanMessage(content='I live in Berlin')]}, config)
agent.invoke({'messages': [HumanMessage(content='What is the weather here?')]}, config)
Common Mistakes
❌ Forget to pass tools
✅ agent = create_agent(model, tools=[...])
Alternatives
| Class | When to Use |
|---|---|
| StateGraph | For complete custom control |
Related LangChain References
Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with create_agent and the wider framework.
create_agent FAQ
What is create_agent in LangChain?
Create agents easily in v1. create_agent() is the high-level entry point in LangChain v1 for building tool-calling agents. It replaces the older initialize_agent and AgentExecutor APIs with a single function that wires up a ReAct-style loop for you: the model is called, any tool calls it emits are executed, the results are fed back, and the cycle repeats until the model returns a final answer. Under the hood it builds and compiles a LangGraph graph, so what you get back is a fully-featured Runnable with…
Which package provides create_agent?
DevShelfHub documents create_agent from the langchain package. Pin your installed LangChain version and match imports to the snippet on this page.
When should I use create_agent?
You're building an agent. Use create_agent() for the recommended v1 approach.
When should I avoid using create_agent?
For custom agent logic—use StateGraph directly.
How do I import create_agent in Python?
from langchain import create_agent
Where can I explore more LangChain API reference pages?
Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.