---
title: LangChain (Deep Agents)
description: Back Deep Agents with a Mirage workspace via LangchainWorkspace.
icon: /images/langchain-logo.svg
---

[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.
</Note>

## Install

```bash
pnpm add @struktoai/mirage-agents @struktoai/mirage-node deepagents @langchain/anthropic
```

## Usage

```ts
import { MountMode, OpsRegistry, RAMResource, Workspace } from '@struktoai/mirage-node'
import { ChatAnthropic } from '@langchain/anthropic'
import { createDeepAgent } from 'deepagents'
import {
  LangchainWorkspace,
  buildSystemPrompt,
  extractText,
} from '@struktoai/mirage-agents/langchain'

const ram = new RAMResource()
const ops = new OpsRegistry()
for (const op of ram.ops()) ops.register(op)
const ws = new Workspace({ '/': ram }, { mode: MountMode.WRITE, ops })

const agent = createDeepAgent({
  model: new ChatAnthropic({ model: 'claude-sonnet-4-6' }),
  systemPrompt: 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` | `SandboxBackendProtocolV2` implementation for Deep Agents, wires reads, writes, edits, search, and shell. |
| `extractText` | Returns `string[]` of text blocks from an array of LangChain messages. |
| `buildSystemPrompt` | Generates a system prompt that describes mounted paths to the model. |

## 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/s3_deepagent.ts`](https://github.com/strukto-ai/mirage/blob/main/examples/typescript/agents/langchain/s3_deepagent.ts), read-only S3 exploration.
