# createDeepAgent

> **Function** in `deepagents`

📖 [View in docs](https://reference.langchain.com/javascript/deepagents/agent/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.

## Signature

```javascript
createDeepAgent<TResponse extends SupportedResponseFormat = SupportedResponseFormat, ContextSchema extends InteropZodObject = InteropZodObject, TMiddleware extends readonly AgentMiddleware<any, any, any, readonly ClientTool | ServerTool[], readonly () => StreamTransformer<any>[]>[] = readonly [], TSubagents extends readonly AnySubAgent[] = readonly [], TTools extends readonly ClientTool | ServerTool[] = readonly [], TStreamTransformers extends readonly () => StreamTransformer<any>[] = readonly [], TStateSchema extends InteropZodObject | AnyStateSchema | undefined = undefined>(params: CreateDeepAgentParams<TResponse, ContextSchema, TMiddleware, TSubagents, TTools, TStreamTransformers, TStateSchema> = ...): DeepAgent<DeepAgentTypeConfig<InferStructuredResponse<TResponse>, TStateSchema, 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">], readonly []>, AgentMiddleware<StateSchema<__type>, undefined, unknown, DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "ls"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, ToolMessage<MessageStructure<MessageToolSet>> | __type[] | __type[], unknown, "read_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "write_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "edit_file"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "glob"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "grep"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string, unknown, "execute">[], readonly []>, AgentMiddleware<undefined, undefined, unknown, readonly [DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | Command<unknown, Record<string, unknown>, string>, unknown, "task">], readonly []>, AgentMiddleware<ZodObject<__type, $strip>, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>, AgentMiddleware<undefined, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>, TMiddleware, FlattenSubAgentMiddleware<TSubagents>], TTools, TSubagents, TStreamTransformers>>
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `params` | `CreateDeepAgentParams<TResponse, ContextSchema, TMiddleware, TSubagents, TTools, TStreamTransformers, TStateSchema>` | No | Configuration parameters for the agent (default: `...`) |

## Returns

`DeepAgent<DeepAgentTypeConfig<InferStructuredResponse<TResponse>, TStateSchema, 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">], readonly []>, AgentMiddleware<StateSchema<__type>, undefined, unknown, DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "ls"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, ToolMessage<MessageStructure<MessageToolSet>> | __type[] | __type[], unknown, "read_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "write_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "edit_file"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "glob"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "grep"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string, unknown, "execute">[], readonly []>, AgentMiddleware<undefined, undefined, unknown, readonly [DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | Command<unknown, Record<string, unknown>, string>, unknown, "task">], readonly []>, AgentMiddleware<ZodObject<__type, $strip>, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>, AgentMiddleware<undefined, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>, TMiddleware, FlattenSubAgentMiddleware<TSubagents>], TTools, TSubagents, TStreamTransformers>>`

Deep Agent instance with inferred state/response types

## Examples

```typescript
// Custom state from middleware and/or the agent stateSchema param — both are merged
const ResearchMiddleware = createMiddleware({
  name: "ResearchMiddleware",
  stateSchema: z.object({ research: z.string().default("") }),
});

const agent = createDeepAgent({
  middleware: [ResearchMiddleware],
  stateSchema: z.object({ author: z.string().default("Me") }),
});

const result = await agent.invoke({ messages: [...] });
// result.research and result.author are properly typed as strings
```

---

[View source on GitHub](https://github.com/langchain-ai/deepagentsjs/blob/60e32118b0ba24ea7ef636476a9a96add9d1a99b/libs/deepagents/src/agent.ts#L190)