> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain (Deep Agents)

> Back Deep Agents with a Mirage workspace via LangchainWorkspace.

[Deep Agents](https://github.com/langchain-ai/deepagents) is LangChain's framework for long-horizon coding agents. It accepts a pluggable `backend` for filesystem and shell operations, and Mirage ships one.

> [!NOTE]
>
> Node only. `LangchainWorkspace` uses `@struktoai/mirage-node`, and Deep Agents depends on Node APIs.

## Install

```bash theme={null}
pnpm add @struktoai/mirage-langchain @struktoai/mirage-node deepagents @langchain/anthropic
```

## Usage

```ts theme={null}
import { MountMode, RAMVFS, Workspace } from '@struktoai/mirage-node'
import { ChatAnthropic } from '@langchain/anthropic'
import { createDeepAgent } from 'deepagents'
import {
  LangchainWorkspace,
  buildSystemPrompt,
  extractText,
} from '@struktoai/mirage-langchain'

const ws = new Workspace({ '/': new RAMVFS() }, { mode: MountMode.WRITE })

const agent = createDeepAgent({
  model: new ChatAnthropic({ model: 'claude-sonnet-4-6' }),
  systemPrompt: await buildSystemPrompt({
    mountInfo: { '/': 'In-memory filesystem (read/write)' },
  }),
  backend: new LangchainWorkspace(ws),
})

const result = await agent.invoke({
  messages: [{ role: 'user', content: 'Create /report.md and summarize.' }],
})
for (const text of extractText(result.messages.slice(-1))) {
  console.log(text)
}
```

## Multimodal files

`read_file` can pass images, PDFs, audio, video, PPT, and PPTX files from a Mirage mount to a model as multimodal content. The selected model and provider must support the corresponding input type. Text files continue to use line-based pagination.

## Exports

| Symbol | Purpose |
| - | - |
| `LangchainWorkspace` | A `SandboxBackendProtocolV2` implementation for Deep Agents that runs reads, writes, edits, search and shell commands in a Mirage workspace. |
| `LangchainWorkspaceOptions` | Options for `LangchainWorkspace`: `sandboxId` sets the backend's `id` (default `mirage`), and `sessionId` names the Mirage session it acts as. |
| `extractText` | Returns the non-empty text blocks of an array of LangChain messages, in order, as `string[]`. |
| `MIRAGE_SYSTEM_PROMPT` | The default system prompt: how the Mirage filesystem differs from a plain one. |
| `buildSystemPrompt` | Returns `MIRAGE_SYSTEM_PROMPT` followed by a description of the mounted paths and any extra instructions, ready to use as an agent's system prompt. |
| `BuildSystemPromptOptions` | Options for `buildSystemPrompt`: which mounts to describe and what to append. |

## Examples

* [`examples/typescript/agents/langchain/ram_deepagent.ts`](https://github.com/strukto-ai/mirage/blob/main/examples/typescript/agents/langchain/ram_deepagent.ts), RAM-only sandbox.
* [`examples/typescript/agents/langchain/ram_pdf_deepagent.ts`](https://github.com/strukto-ai/mirage/blob/main/examples/typescript/agents/langchain/ram_pdf_deepagent.ts), RAM-backed PDF reading with no external storage credentials.
* [`examples/typescript/agents/langchain/s3_deepagent.ts`](https://github.com/strukto-ai/mirage/blob/main/examples/typescript/agents/langchain/s3_deepagent.ts), read-only S3 exploration.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.