LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • 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

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsnodeSubAgent
Interface●Since v1.10

SubAgent

Specification for a subagent that can be dynamically created.

When using createDeepAgent, subagents automatically receive a default middleware stack (todoListMiddleware, filesystemMiddleware, summarizationMiddleware, etc.) before any custom middleware specified in this spec.

Required fields:

  • name: Identifier used to select this subagent in the task tool
  • description: Shown to the model for subagent selection
  • systemPrompt: The system prompt for the subagent

Optional fields:

  • model: Override the default model for this subagent
  • tools: Override the default tools for this subagent
  • middleware: Additional middleware appended after defaults
  • interruptOn: Human-in-the-loop configuration for specific tools
  • skills: Skill source paths for SkillsMiddleware (e.g., ["/skills/user/", "/skills/project/"])
Copy
interface SubAgent

Example

Copy
const researcher: SubAgent = {
  name: "researcher",
  description: "Research assistant for complex topics",
  systemPrompt: "You are a research assistant.",
  tools: [webSearchTool],
  skills: ["/skills/research/"],
};

Properties

property
description: string

What this subagent does. The main agent uses this to decide when to delegate.

property
interruptOn: Record<string, boolean | __type>

Human-in-the-loop configuration for specific tools. Requires a checkpointer.

property
middleware: readonly AgentMiddleware<any, any, any, readonly ClientTool | ServerTool[], readonly () => StreamTransformer<any>[]>[]

Additional middleware to append after default_middleware

property
model: string | LanguageModelLike

The model for the agent. Defaults to defaultModel

property
name: string

Error name for instanceof checks and logging

property
permissions: FilesystemPermission[]

Filesystem permission rules enforced on every tool call.

Rules are evaluated in declaration order; first match wins; permissive default. Applies to ls, read_file, write_file, edit_file, glob, and grep.

Note on execute: permissions are not enforced on execute because shell commands can access any path regardless of path-based rules. Using permissions with an execution-capable backend (one where isSandboxBackend returns true) throws a ConfigurationError unless either:

  • execute is disabled via tools, or
  • the backend is a CompositeBackend and every permission path is scoped to a route prefix.

When omitted or empty, all filesystem operations are permitted.

property
responseFormat: ResponseFormatInput<Record<string, any>>

Structured output response format for the subagent.

When specified, the subagent will produce a structuredResponse conforming to the given schema. The structured response is JSON-serialized and returned as the ToolMessage content to the parent agent, replacing the default last-message extraction.

Accepts any format supported by createAgent: Zod schemas, JSON schema objects, toolStrategy(schema), providerStrategy(schema), etc.

Copy
import { z } from "zod"

const analyzer: SubAgent = {
  name: "analyzer",
  description: "Analyzes data and returns structured findings",
  systemPrompt: "Analyze the data and return your findings.",
  responseFormat: z.object({
    findings: z.string(),
    confidence: z.number(),
  }),
};
property
skills: string[]

Skill source paths for SkillsMiddleware.

List of paths to skill directories (e.g., ["/skills/user/", "/skills/project/"]). When specified, the subagent will have its own SkillsMiddleware that loads skills from these paths. This allows subagents to have different skill sets than the main agent.

Note: Custom subagents do NOT inherit skills from the main agent by default. Only the general-purpose subagent inherits the main agent's skills.

Copy
const researcher: SubAgent = {
  name: "researcher",
  description: "Research assistant",
  systemPrompt: "You are a researcher.",
  skills: ["/skills/research/", "/skills/web-search/"],
};
property
systemPrompt: string

System prompt override. Set to null to disable. Defaults to ASYNC_TASK_SYSTEM_PROMPT.

property
tools: StructuredTool<ToolInputSchemaBase, any, any, any, unknown>[]

Allowlist of built-in filesystem tools to expose to the model.

  • undefined, null, and "all" preserve the default behavior: every filesystem tool is registered, subject to backend capability filtering.
  • Passing an array restricts the middleware to only those tool names.
  • read_file must be included in every explicit array because it is used by normal file-inspection flows and by large-result recovery guidance.
  • Backend capability checks still narrow the final visible tool set. For example, execute is removed when the resolved backend does not support command execution, even if it appears in this allowlist.
  • User-provided non-filesystem tools are not affected by this allowlist.

The generated filesystem system prompt is based on the tools that remain visible after this allowlist and backend capability filtering are applied.

Copy
createFilesystemMiddleware({
  tools: ["read_file", "ls", "glob", "grep"],
});
View source on GitHub