LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Configuration
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsConfigurationTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsagentcreateDeepAgent
Function●Since v1.4

createDeepAgent

Copy
createDeepAgent<
  TResponse extends SupportedResponseFormat

Used in Docs

  • Backends
  • Customize Deep Agents
  • Deep Agents overview
  • Human-in-the-loop
  • Long-term memory
View source on GitHub
=
SupportedResponseFormat
,
ContextSchema
extends
InteropZodObject
=
InteropZodObject
,
TMiddleware
extends
readonly
AgentMiddleware
<
any
,
any
,
any
,
readonly
ClientTool
|
ServerTool
[
]
>
[
]
=
readonly
[
]
,
TSubagents
extends
readonly
AnySubAgent
[
]
=
readonly
[
]
,
TTools
extends
readonly
ClientTool
|
ServerTool
[
]
=
readonly
[
]
>
(
params
:
CreateDeepAgentParams
<
TResponse
,
ContextSchema
,
TMiddleware
,
TSubagents
,
TTools
>
=
.
.
.
)
:
DeepAgent
<
DeepAgentTypeConfig
<
InferStructuredResponse
<
TResponse
>
,
undefined
,
ContextSchema
,
readonly
[
AgentMiddleware
<
ZodObject
<
__type
,
"strip"
,
ZodTypeAny
,
__type
,
__type
>
,
undefined
,
unknown
,
readonly
[
DynamicStructuredTool
<
ZodObject
<
__type
,
"strip"
,
ZodTypeAny
,
__type
,
__type
>
,
__type
,
__type
,
Command
<
unknown
,
__type
,
string
>
,
unknown
,
"write_todos"
>
]
>
,
AgentMiddleware
<
StateSchema
<
__type
>
,
undefined
,
unknown
,
DynamicStructuredTool
<
ZodObject
<
__type
,
strip
>
,
__type
,
__type
,
string
,
unknown
,
"ls"
>
|
DynamicStructuredTool
<
ZodObject
<
__type
,
strip
>
,
__type
,
__type
,
__type
[
]
|
__type
[
]
,
unknown
,
"read_file"
>
|
DynamicStructuredTool
<
ZodObject
<
__type
,
strip
>
,
__type
,
__type
,
string
|
ToolMessage
<
MessageStructure
<
MessageToolSet
>
>
|
Command
<
unknown
,
__type
,
string
>
,
unknown
,
"write_file"
>
|
DynamicStructuredTool
<
ZodObject
<
__type
,
strip
>
,
__type
,
__type
,
string
|
ToolMessage
<
MessageStructure
<
MessageToolSet
>
>
|
Command
<
unknown
,
__type
,
string
>
,
unknown
,
"edit_file"
>
|
DynamicStructuredTool
<
ZodObject
<
__type
,
strip
>
,
__type
,
__type
,
string
,
unknown
,
"glob"
>
|
DynamicStructuredTool
<
ZodObject
<
__type
,
strip
>
,
__type
,
__type
,
string
,
unknown
,
"grep"
>
|
DynamicStructuredTool
<
ZodObject
<
__type
,
strip
>
,
__type
,
__type
,
string
,
unknown
,
"execute"
>
[
]
>
,
AgentMiddleware
<
undefined
,
undefined
,
unknown
,
readonly
[
DynamicStructuredTool
<
ZodObject
<
__type
,
strip
>
,
__type
,
__type
,
string
|
Command
<
unknown
,
Record
<
string
,
unknown
>
,
string
>
,
unknown
,
"task"
>
]
>
,
AgentMiddleware
<
ZodObject
<
__type
,
strip
>
,
undefined
,
unknown
,
readonly
ClientTool
|
ServerTool
[
]
>
,
AgentMiddleware
<
undefined
,
undefined
,
unknown
,
readonly
ClientTool
|
ServerTool
[
]
>
,
TMiddleware
,
FlattenSubAgentMiddleware
<
TSubagents
>
]
,
TTools
,
TSubagents
>
>

Parameters

NameTypeDescription
paramsCreateDeepAgentParams<TResponse, ContextSchema, TMiddleware, TSubagents, TTools>
Default:...

Example

Create a Deep Agent with middleware-based architecture.

Matches Python's create_deep_agent function, using middleware for all features:

  • Todo management (todoListMiddleware)
  • Filesystem tools (createFilesystemMiddleware)
  • Subagent delegation (createSubAgentMiddleware)
  • Conversation summarization (createSummarizationMiddleware) with backend offloading
  • Prompt caching (anthropicPromptCachingMiddleware)
  • Tool call patching (createPatchToolCallsMiddleware)
  • Human-in-the-loop (humanInTheLoopMiddleware) - optional

Configuration parameters for the agent

Copy
// Middleware with custom state
const ResearchMiddleware = createMiddleware({
  name: "ResearchMiddleware",
  stateSchema: z.object({ research: z.string().default("") }),
});

const agent = createDeepAgent({
  middleware: [ResearchMiddleware],
});

const result = await agent.invoke({ messages: [...] });
// result.research is properly typed as string