StateBackend¶
StateBackend
¶
Bases: BackendProtocol
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 checkpointed after each agent step.
Special handling: Since LangGraph state must be updated via Command objects (not direct mutation), operations return Command objects instead of None. This is indicated by the uses_state=True flag.
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initialize StateBackend with runtime. |
ls_info |
List files and directories in the specified directory (non-recursive). |
read |
Read file content with line numbers. |
write |
Create a new file with content. |
edit |
Edit a file by replacing string occurrences. |
grep_raw |
Search for a literal text pattern in files. |
glob_info |
Get FileInfo for files matching glob pattern. |
upload_files |
Upload multiple files to state. |
download_files |
Download multiple files from state. |
als_info |
Async version of ls_info. |
aread |
Async version of read. |
agrep_raw |
Async version of grep_raw. |
aglob_info |
Async version of glob_info. |
awrite |
Async version of write. |
aedit |
Async version of edit. |
aupload_files |
Async version of upload_files. |
adownload_files |
Async version of download_files. |
ls_info
¶
List files and directories in the specified directory (non-recursive).
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Absolute path to directory.
TYPE:
|
| 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 content with line numbers.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Absolute file path.
TYPE:
|
offset
|
Line offset to start reading from (0-indexed).
TYPE:
|
limit
|
Maximum number of lines to read.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Formatted file content with line numbers, or error message. |
write
¶
Create a new file with content. Returns WriteResult with files_update to update LangGraph state.
edit
¶
Edit a file by replacing string occurrences. Returns EditResult with files_update and occurrences.
grep_raw
¶
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:
|
path
|
Optional directory path to search in. If None, searches in current working directory. Example: "/workspace/src"
TYPE:
|
glob
|
Optional glob pattern to filter which FILES to search.
Filters by filename/path, not content.
Supports standard glob wildcards:
-
TYPE:
|
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
¶
Get FileInfo for files matching glob pattern.
upload_files
¶
download_files
¶
aread
async
¶
Async version of read.
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
¶
Async version of glob_info.
aedit
async
¶
Async version of edit.
aupload_files
async
¶
Async version of upload_files.