> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-bengre-1788126811-6994ab4.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Forked subagents

> Inherit the parent's conversation and system prompt instead of starting a subagent cold

By default, a [subagent](/oss/python/deepagents/subagents) sees only the task description you give it. It starts with no memory of the conversation that led up to the delegation. A **forked subagent** is a separate spec type, [`ForkedSubAgent`](https://reference.langchain.com/python/deepagents/middleware/subagents/ForkedSubAgent), that instead inherits the parent's full effective conversation history and exact system prompt.

Use forking when a subagent is delegated deep into an investigation and shouldn't have to re-derive context the parent already gathered. For example, handing an in-progress incident investigation off to a subagent that drafts the postmortem.

<div className="skills-composition-diagram">
  <img src="https://mintcdn.com/langchain-5e9cc07a-preview-bengre-1788126811-6994ab4/zPRfJiniGIEJIWTR/oss/images/deepagents/forked-subagents-diagram.svg?fit=max&auto=format&n=zPRfJiniGIEJIWTR&q=85&s=b95db5f065c1e130f2d17953df9b5a22" alt="A forked subagent replays the parent's prior exploration steps, then continues working on its own before handing an answer back. It never starts from a blank slate." width="830" height="560" data-path="oss/images/deepagents/forked-subagents-diagram.svg" />
</div>

<Warning>
  Subagent forking is in [**beta**](/oss/python/versioning). APIs and behavior may change between releases.
</Warning>

## Configure a forked subagent

A forked subagent uses a separate spec, [`ForkedSubAgent`](https://reference.langchain.com/python/deepagents/middleware/subagents/ForkedSubAgent), not `SubAgent`. It shares most `SubAgent` fields (`name`, `description`, `tools`, `model`, `middleware`, `interrupt_on`, `permissions`, `response_format`), but two are rejected outright rather than silently ignored:

* **`system_prompt`**: a forked subagent always uses the parent's inherited system prompt.
* **`skills`**: a fork's own skills injection would be immediately overwritten by the inherited system prompt, so it's rejected instead of quietly doing nothing.

```python theme={null}
from deepagents import create_deep_agent


def read_logs(path: str) -> str:
    """Read a log file."""
    return f"logs from {path}"


incident_responder = {
    "name": "incident-responder",
    "description": "Continues an in-progress incident investigation and drafts the postmortem",
    "mode": "fork",
    "tools": [read_logs],
}

agent = create_deep_agent(
    model="claude-sonnet-4-6",
    tools=[read_logs],
    subagents=[incident_responder],
)

# The parent has already been investigating for several turns before
# delegating -- the fork continues with that full history, not a blank slate.
result = agent.invoke(
    {
        "messages": [
            {"role": "user", "content": "Investigate the outage in payment-service"},
            {
                "role": "assistant",
                "content": "Found a spike in 500s starting 14:02 UTC, tied to deploy a1b2c3d.",
            },
            {"role": "user", "content": "Hand this off to incident-responder to draft the postmortem"},
        ]
    }
)
```

## How it works

A forked subagent's system message isn't a static copy of the parent's prompt. It's captured dynamically from whatever the parent's own middleware actually produced on its last call (skills injection, memory, custom prompt mutation), then replayed into the fork verbatim. This is what lets the fork share the parent's prompt cache prefix instead of paying for a cold start; a fork's own tools still work normally, but expect cache misses where they diverge from the parent's.

The inherited history also gets a short preamble marking it as a continuation, not a fresh request.

## Forking a CompiledSubAgent

A [`CompiledSubAgent`](/oss/python/deepagents/subagents#compiledsubagent) can also set `mode: "fork"`. This inherits the parent's message history the same way, but keeps the compiled graph's own system prompt. A `CompiledSubAgent` is already fully built, so there's no system message for it to inherit into.

```python theme={null}
from deepagents import CompiledSubAgent, create_deep_agent
from langchain.agents import create_agent


def read_logs(path: str) -> str:
    """Read a log file."""
    return f"logs from {path}"


# A prebuilt graph with its own system prompt -- forking inherits the
# parent's message history only, not its system prompt.
incident_graph = create_agent(
    model="claude-sonnet-4-6",
    tools=[read_logs],
    system_prompt="You are an incident postmortem writer.",
)

incident_responder = CompiledSubAgent(
    name="incident-responder",
    description="Continues an in-progress incident investigation and drafts the postmortem",
    runnable=incident_graph,
    mode="fork",
)

agent = create_deep_agent(
    model="claude-sonnet-4-6",
    tools=[read_logs],
    subagents=[incident_responder],
)
```

## When to use forking

| Dimension                      | Isolated (default)          | Forked                                                             |
| ------------------------------ | --------------------------- | ------------------------------------------------------------------ |
| **Context**                    | Only the task description   | Full conversation history + exact system prompt                    |
| **Prompt cache**               | Cold start every time       | Shares the parent's cached prefix                                  |
| **`system_prompt` / `skills`** | Own values                  | Not allowed: inherits the parent's                                 |
| **Re-delegation**              | Can call `task` normally    | Refused: must complete the task itself                             |
| **Best for**                   | Focused, context-light work | Continuing an investigation the parent already has deep context on |

## See also

* [Subagents](/oss/python/deepagents/subagents): Configure subagent names, descriptions, and system prompts
* [Dynamic subagents](/oss/python/deepagents/dynamic-subagents): Dispatch subagents from interpreter code
* [Context engineering](/oss/python/deepagents/context-engineering): How conversation history is summarized as it grows

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/deepagents/forked-subagents.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
