Skip to content

StoreBackend

StoreBackend

Bases: BackendProtocol

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.

The namespace can include an optional assistant_id for multi-agent isolation.

METHOD DESCRIPTION
__init__

Initialize StoreBackend with runtime.

ls_info

List files and directories in the specified directory (non-recursive).

read

Read file content with line numbers.

aread

Async version of read using native store async methods.

write

Create a new file with content.

awrite

Async version of write using native store async methods.

edit

Edit a file by replacing string occurrences.

aedit

Async version of edit using native store async methods.

grep_raw

Search for a literal text pattern in files.

glob_info

Find files matching a glob pattern.

upload_files

Upload multiple files to the store.

download_files

Download multiple files from the store.

als_info

Async version of ls_info.

agrep_raw

Async version of grep_raw.

aglob_info

Async version of glob_info.

aupload_files

Async version of upload_files.

adownload_files

Async version of download_files.

__init__

__init__(runtime: ToolRuntime)

Initialize StoreBackend with runtime.

PARAMETER DESCRIPTION
runtime

The ToolRuntime instance providing store access and configuration.

TYPE: ToolRuntime

ls_info

ls_info(path: str) -> list[FileInfo]

List files and directories in the specified directory (non-recursive).

PARAMETER DESCRIPTION
path

Absolute path to directory.

TYPE: str

RETURNS DESCRIPTION
list[FileInfo]

List of FileInfo-like dicts for files and directories directly in the directory.

list[FileInfo]

Directories have a trailing / in their path and is_dir=True.

read

read(file_path: str, offset: int = 0, limit: int = 2000) -> str

Read file content with line numbers.

PARAMETER DESCRIPTION
file_path

Absolute file path.

TYPE: str

offset

Line offset to start reading from (0-indexed).

TYPE: int DEFAULT: 0

limit

Maximum number of lines to read.

TYPE: int DEFAULT: 2000

RETURNS DESCRIPTION
str

Formatted file content with line numbers, or error message.

aread async

aread(file_path: str, offset: int = 0, limit: int = 2000) -> str

Async version of read using native store async methods.

This avoids sync calls in async context by using store.aget directly.

write

write(file_path: str, content: str) -> WriteResult

Create a new file with content. Returns WriteResult. External storage sets files_update=None.

awrite async

awrite(file_path: str, content: str) -> WriteResult

Async version of write using native store async methods.

This avoids sync calls in async context by using store.aget/aput directly.

edit

edit(
    file_path: str, old_string: str, new_string: str, replace_all: bool = False
) -> EditResult

Edit a file by replacing string occurrences. Returns EditResult. External storage sets files_update=None.

aedit async

aedit(
    file_path: str, old_string: str, new_string: str, replace_all: bool = False
) -> EditResult

Async version of edit using native store async methods.

This avoids sync calls in async context by using store.aget/aput directly.

grep_raw

grep_raw(
    pattern: str, path: str = "/", glob: str | None = None
) -> list[GrepMatch] | str

Search for a literal text pattern in files.

PARAMETER DESCRIPTION
pattern

Literal string to search for (NOT regex). Performs exact substring matching within file content. Example: "TODO" matches any line containing "TODO"

TYPE: str

path

Optional directory path to search in. If None, searches in current working directory. Example: "/workspace/src"

TYPE: str | None DEFAULT: None

glob

Optional glob pattern to filter which FILES to search. Filters by filename/path, not content. Supports standard glob wildcards: - * matches any characters in filename - ** matches any directories recursively - ? matches single character - [abc] matches one character from set

TYPE: str | None DEFAULT: None

Examples:

  • "*.py" - only search Python files
  • "**/*.txt" - search all .txt files recursively
  • "src/**/*.js" - search JS files under src/
  • "test[0-9].txt" - search test0.txt, test1.txt, etc.
RETURNS DESCRIPTION
list[GrepMatch] | str

On success: list[GrepMatch] with structured results containing: - path: Absolute file path - line: Line number (1-indexed) - text: Full line content containing the match

list[GrepMatch] | str

On error: str with error message (e.g., invalid path, permission denied)

glob_info

glob_info(pattern: str, path: str = '/') -> list[FileInfo]

Find files matching a glob pattern.

PARAMETER DESCRIPTION
pattern

Glob pattern with wildcards to match file paths. Supports standard glob syntax: - * matches any characters within a filename/directory - ** matches any directories recursively - ? matches a single character - [abc] matches one character from set

TYPE: str

path

Base directory to search from. Default: "/" (root). The pattern is applied relative to this path.

TYPE: str DEFAULT: '/'

RETURNS DESCRIPTION
list[FileInfo]

list of FileInfo

upload_files

upload_files(files: list[tuple[str, bytes]]) -> list[FileUploadResponse]

Upload multiple files to the store.

PARAMETER DESCRIPTION
files

List of (path, content) tuples where content is bytes.

TYPE: list[tuple[str, bytes]]

RETURNS DESCRIPTION
list[FileUploadResponse]

List of FileUploadResponse objects, one per input file.

list[FileUploadResponse]

Response order matches input order.

download_files

download_files(paths: list[str]) -> list[FileDownloadResponse]

Download multiple files from the store.

PARAMETER DESCRIPTION
paths

List of file paths to download.

TYPE: list[str]

RETURNS DESCRIPTION
list[FileDownloadResponse]

List of FileDownloadResponse objects, one per input path.

list[FileDownloadResponse]

Response order matches input order.

als_info async

als_info(path: str) -> list[FileInfo]

Async version of ls_info.

agrep_raw async

agrep_raw(
    pattern: str, path: str | None = None, glob: str | None = None
) -> list[GrepMatch] | str

Async version of grep_raw.

aglob_info async

aglob_info(pattern: str, path: str = '/') -> list[FileInfo]

Async version of glob_info.

aupload_files async

aupload_files(files: list[tuple[str, bytes]]) -> list[FileUploadResponse]

Async version of upload_files.

adownload_files async

adownload_files(paths: list[str]) -> list[FileDownloadResponse]

Async version of download_files.