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
JavaScriptdeepagentsnodeForkedSubAgent
Interface●Since v1.13

ForkedSubAgent

Specification for a subagent that inherits the parent's conversation instead of starting from just the task description.

Always forks: it inherits the parent's full message history and its exact system prompt (there's no own prompt to fall back to). Mirrored middleware is only added when its model matches the parent's, since that's the only case with a cache benefit to protect. Deliberately has no systemPrompt of its own: since its system slot always carries the parent's prompt, there's nothing of its own to put there. If you need a subagent with a distinguishing system prompt, use SubAgent without forking instead.

Copy
interface ForkedSubAgent

Bases

SubAgentBase

Example

Copy
const researcher: ForkedSubAgent = {
  name: "researcher",
  description: "Continues the current investigation with full context",
  mode: "fork",
  tools: [webSearchTool],
};

Properties

property
description: string

Description shown to the model for subagent selection

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
mode: "fork"

Always "fork". Required (not defaulted) so this can't structurally collapse into a plain SubAgent — see isForkedSubAgent below.

property
model: string | LanguageModelLike

The model for the agent. Defaults to defaultModel

property
name: string

Identifier used to select this subagent in the task tool

property
permissions: FilesystemPermission[]

Filesystem permission rules for this subagent.

When specified, these rules replace the parent agent's permissions for all tool calls made by this subagent. When omitted, the subagent inherits the parent agent's permissions.

Subagent permissions are a full replacement, not a merge.

Copy
// Parent denies /restricted/**; this subagent can read it.
const reader: SubAgent = {
  name: "reader",
  permissions: [
    { operations: ["read"], paths: ["/restricted/**"] },
  ],
};
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: undefined

A ForkedSubAgent never has its own system prompt — always the parent's.

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

The tools to use for the agent (tool instances, not names). Defaults to defaultTools

View source on GitHub