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
JavaScriptdeepagentsevalscreateDeepAgent
Function●Since v1.8

createDeepAgent

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
Copy
createDeepAgent<
  TResponse extends SupportedResponseFormat = SupportedResponseFormat,
  ContextSchema extends InteropZodObject = InteropZodObject,
  TMiddleware extends readonly AgentMiddleware<any, any, any, readonly ClientTool | ServerTool[]>[] = readonly [],
  TSubagents extends readonly SubAgent | CompiledSubAgent<ReactAgent<any> | Runnable<any, any, RunnableConfig<Record<string, any>>>>[] = 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>, "write_todos">]>, AgentMiddleware<StateSchema<__type>, undefined, unknown, DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string, "ls"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string, "read_file"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, "write_file"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, "edit_file"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string, "glob"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string, "grep"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string, "execute">[]>, AgentMiddleware<undefined, undefined, unknown, readonly [DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string | Command<unknown, Record<string, unknown>, string>, "task">]>, AgentMiddleware<ZodObject<__type, strip>, undefined, unknown, readonly ClientTool | ServerTool[]>, AgentMiddleware<undefined, ZodObject<__type, "strip", ZodTypeAny, __type, __type>, __type, readonly ClientTool | ServerTool[]>, AgentMiddleware<undefined, undefined, unknown, readonly ClientTool | ServerTool[]>, TMiddleware, FlattenSubAgentMiddleware<TSubagents>], TTools, TSubagents>>

Used in Docs

  • Backends
  • Customize Deep Agents
  • Deep Agents overview
  • Human-in-the-loop
  • Long-term memory

Parameters

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

Configuration parameters for the agent

Example

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
View source on GitHub