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

Create a Deep Agent.

This is the main entry point for building a production-style agent with deepagents. It gives you a strong default runtime (filesystem, tasks, subagents, summarization) and lets you opt into skills, memory, human-in-the-loop interrupts, async subagents, and custom middleware.

The runtime is intentionally opinionated: defaults work out of the box, and when you customize behavior, the middleware ordering stays deterministic.

Copy
createDeepAgent<
  TResponse extends SupportedResponseFormat = 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>>

Used in Docs

  • Async subagents
  • Backends
  • Context engineering in Deep Agents
  • Customize Deep Agents
  • Deep Agents overview

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