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.
Classes
StateBackend
Backend that stores files in agent state (ephemeral).
Uses LangGraph's state management and checkpointing. Files persist within a conversation thread but not across threads. State is automatically ch
StoreBackend
Backend that stores files in LangGraph's BaseStore (persistent).
Uses LangGraph's Store for persistent, cross-conversation storage. Files are organized via namespaces and persist across all threads.
FilesystemBackend
Backend that reads and writes files directly from the filesystem.
Files are accessed using their actual filesystem paths. Relative paths are resolved relative to the current working directory. Conten
CompositeBackend
Routes file operations to different backends by path prefix.
Matches paths against route prefixes (longest first) and delegates to the corresponding backend. Unmatched paths use the default backend.
BaseSandbox
Base sandbox implementation with execute() as the core abstract method.
This class provides default implementations for all protocol methods. File listing, grep, and glob use shell commands via `ex
SandboxBackendProtocol
Extension of BackendProtocol that adds shell command execution.
Designed for backends running in isolated environments (containers, VMs, remote hosts).
Adds execute()/aexecute() for shell comm
BackendProtocol
Protocol for pluggable memory backends (single, unified).
Backends can store files in different locations (state, filesystem, database, etc.) and provide a uniform interface for file operations.
Fil
InvalidGlobPatternError
A glob pattern the shared matcher refuses to compile.
Subclasses ValueError so existing except ValueError handlers keep
working. Callers that catch this specific type can label the failure a
*pat
Functions
compile_grep_include_glob
Compile a grep include-glob into a matcher with ripgrep-like semantics.
Provides one shared include-glob behavior for every backend so the same
grep(..., glob=...) call closely mirrors ripgrep for
sanitize_tool_call_id
Return a bounded, path-safe component for a tool call ID.
format_content_with_line_numbers
Format file content with line numbers.
Chunks lines longer than MAX_LINE_LENGTH with continuation markers
(e.g., 5.1, 5.2). Line markers are separated from source content
with two spaces so sou
check_empty_content
Check if content is empty and return warning message.
file_data_to_string
Convert current or legacy persisted file content to a string.
create_file_data
Create a FileData object with timestamps.
update_file_data
Update FileData with new content, preserving creation timestamp.
normalize_read_bounds
Floor a requested read window at a zero offset and zero lines.
Models occasionally emit degenerate read_file arguments (offset=-1,
limit=0). Clamping offset keeps backends from reporting a li
slice_read_response
Slice file data to the requested line range without formatting.
The returned ReadResult carries the raw (unformatted) window in
file_data; line-number formatting is applied downstream by the
midd
perform_string_replacement
Perform string replacement with occurrence validation.
truncate_if_too_long
Truncate list or string result if it exceeds token limit (rough estimate: 4 chars/token).
to_posix_path
Normalize backslash separators to forward slashes for PurePosixPath use.
Backends running on Windows return OS-native paths using backslashes.
PurePosixPath treats backslashes as literal filename
validate_path
Validate and normalize file path for security.
Ensures paths are safe to use by preventing directory traversal attacks and enforcing consistent formatting. All paths are normalized to use forward sla
grep_matches_from_files
Return structured grep matches from an in-memory files mapping.
Performs literal text search (not regex).
Returns a GrepResult with matches on success. When max_count is set, at
most that many m
build_grep_results_dict
Group structured matches into the legacy dict form used by formatters.
format_grep_matches
Format structured grep matches using existing formatting logic.
regex_literal_hint
Return a hint when a pattern looks like an (unsupported) regex.
grep matches literal text, so regex metacharacters are searched verbatim
and silently miss. Callers gate this on a no-match result; t
Constants
logger
EMPTY_CONTENT_WARNING
EMPTY_OLD_STRING_ERROR
MAX_VIDEO_INPUT_BYTES
Maximum raw video payload size accepted by read_file frame extraction.
TRUNCATION_MARKER_TEMPLATE
Marker standing in for lines dropped from the middle of a head/tail preview.
Shared by _message_eviction._create_content_preview and the capture wrapper
in backends.sandbox so both emit identical
FileType
Classification of a file by extension.
