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

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsConfigurationTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsBackends

Backends

Backends control how deep agents store files and manage state. Choose a backend based on your persistence and isolation requirements.

Learn more: For detailed guidance on choosing and configuring backends, see the Backends documentation.

Backend Types

Backend Persistence Use Case
StateBackend Ephemeral (in-memory) Default; files lost when agent ends
StoreBackend Persistent Files persist across agent runs using LangGraph Store
FilesystemBackend Persistent Real filesystem access for file-based workflows
CompositeBackend Mixed Layer multiple backends for complex strategies

Quick Examples

StateBackend (Default)

In-memory, ephemeral storage. Files are stored in the agent's state and lost when the agent ends.

import { createDeepAgent, StateBackend } from "deepagents";

const agent = createDeepAgent({
  backend: new StateBackend(),
});

StoreBackend

Persistent storage using LangGraph Store. Files persist across agent runs.

import { createDeepAgent, StoreBackend } from "deepagents";
import { InMemoryStore } from "@langchain/langgraph";

const store = new InMemoryStore();
const agent = createDeepAgent({
  backend: new StoreBackend({ store }),
});

FilesystemBackend

Store files on the actual filesystem. Useful for agents that need to interact with real files.

import { createDeepAgent, FilesystemBackend } from "deepagents";

const agent = createDeepAgent({
  backend: new FilesystemBackend({
    rootDir: "/path/to/workspace",
  }),
});

CompositeBackend

Combine multiple backends for layered storage strategies. Reads check backends in order; writes go to the primary backend.

import { createDeepAgent, CompositeBackend, StateBackend, FilesystemBackend } from "deepagents";

// State backend for scratch files, filesystem for persistent output
const agent = createDeepAgent({
  backend: new CompositeBackend({
    primary: new StateBackend(),
    fallbacks: [new FilesystemBackend({ rootDir: "/workspace" })],
  }),
});

Sandbox Backends

For agents that need to run shell commands in isolated environments, extend BaseSandbox to implement your own sandbox integration.

API Reference

Classes

Class

StateBackend

Backend that stores files in agent state (ephemeral).

Class

StoreBackend

Backend that stores files in LangGraph's BaseStore (persistent).

Class

FilesystemBackend

Backend that reads and writes files directly from the filesystem.

Class

CompositeBackend

Backend that routes file operations to different backends based on path prefix.

Class

BaseSandbox

Base sandbox implementation with execute() as the only abstract method.

Interfaces

Interface

SandboxBackendProtocol

Protocol for sandboxed backends with isolated runtime.

Interface

BackendProtocol

Protocol for pluggable memory backends (single, unified).

Interface

ExecuteResponse

Result of code execution.

Interface

FileUploadResponse

Result of a single file upload operation.

Interface

FileDownloadResponse

Result of a single file download operation.

Types

Type

BackendFactory

Factory function type for creating backend instances.