Skip to content

feat:687 | smart agents - LocalBackend, StateBackend#6339

Open
jchui-wd wants to merge 10 commits intofeature/SmartAgentsfrom
feat/687-LocalBackend
Open

feat:687 | smart agents - LocalBackend, StateBackend#6339
jchui-wd wants to merge 10 commits intofeature/SmartAgentsfrom
feat/687-LocalBackend

Conversation

@jchui-wd
Copy link
Copy Markdown
Contributor

@jchui-wd jchui-wd commented May 4, 2026

Changes

StateBackend

  • updated fs tools with universal edit_file, list_file, glob_files, and grep_file capabilities, add, and write already existed
  • Updated systemPromptBuilder with additional fs tools
  • SmartAgents: synced Statebackend using runTimeState.files to sync mutations and files so data is persisted across execution.

LocalBackend

  • Added SANDBOX_LOCAL_PATH incase users want to edit the path
  • adds MAX_LIST_OBJECTS for glob and grep
  • pinned 20.12.0 < 21.0.0 to support file system calls
  • each File workspace is seperated via orgId/chatflowId/chatId

CompositeBackend

  • routes paths to sub-backends by longest-matching prefix (default + optional mounts like /workspace,
    /scratch)
  • requires slash-boundary matching so /foo/ never matches /foobar/; rejects "/" and "" prefixes
  • translates paths and re-keys FilesUpdate across mount boundaries; ls/glob/grep stay scoped to the
    resolved mount
  • wired SANDBOX_TYPE=composite into the factory (default StateBackend, no mounts yet) and extended
    hasStatefulSmartAgent so executionData still hydrates across messages

Videos

StateBackend Videos Demo

read-write-edit.mp4

read-write-edit.mp4


ls-grep-glob.mp4

ls-grep-glob.mp4

LocalBackend Videos Demo

read-write-gr...b-edit-ls.mp4

read-write-grep-glob-edit-ls.mp4


path-traversal-limits.mp4

path-traversal-limits.mp4


create-read-workspace.mp4

create-read-workspace.mp4

CompositeBackend Videos Demo Composite
CompositeBackend-Demo.mp4

Gaps

  • Allow reading image files
  • We currently can't delete, but is probably intentional as it is saved when we do "execute"

jchui-wd and others added 7 commits April 29, 2026 15:51
…s. Added a basic StateBackend for read and write and connected it with fs and smart agents for basic testing
- Replace filesystemEnabled() with getSandboxType(); default to 'state' there
- createBackend throws on unknown SANDBOX_TYPE instead of silently defaulting
- SmartAgent always creates a backend (filesystem is always on per design)
- getMimeType: explicit no-dot guard before slicing
Rename state.ts -> StateBackend.ts and protocol.ts -> BackendProtocol.ts
to match the packages/components convention (PascalCase for files whose
primary export is a same-named class/interface).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…p capabilities

- updated fs tools with universal edit_file, list_file, glob_files, and grep_file capabilities, add, and write already existed
- Updated systemPromptBuilder with additional fs tools
- SmartAgents: synced Statebackend using runTimeState.files to sync mutations and files so data is persisted across execution.
…th mimeTypes and Uint8Array, made sure edit and grep must have minimum string in it before performing action
- Added SANDBOX_LOCAL_PATH incase users want to edit the path
- adds MAX_LIST_OBJECTS for glob and grep
- pinned 20.12.0 < 21.0.0 to support file system calls
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a LocalBackend implementation for the SmartAgent sandbox, enabling disk-backed file operations with built-in path traversal protections. The changes include a comprehensive test suite, integration into the backend factory, and a narrowing of the supported Node.js engine version. Feedback highlights critical performance and memory concerns in the read and grep methods, where entire files are loaded into memory instead of being processed via streams or chunks. Additionally, an unused helper method toVirtual was identified for removal.

Comment thread packages/components/nodes/agentflow/SmartAgent/sandbox/backends/LocalBackend.ts Outdated
Comment thread packages/components/nodes/agentflow/SmartAgent/sandbox/backends/LocalBackend.ts Outdated
jchui-wd and others added 2 commits May 4, 2026 15:43
- grep uses readline + createReadStream so peak memory is one line per file, not the whole file
- JSDoc no longer claims "Dev-only" — that warning belongs to LocalShellBackend (shell exec), not disk-only access
- drop unused toVirtual helper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Concurrent SmartAgent runs previously shared one global root
(`~/.flowise/sandbox` or `SANDBOX_LOCAL_PATH`), causing cross-chat
file collisions and EEXIST races on `write` (wx flag). Factory now
composes `<base>/<orgSeg>/<flowSeg>/<chatSeg>` via new
`buildScopeSegments` helper, mirroring the orgId/chatflowid/chatId
hierarchy used by `getFileFromStorage`. SmartAgent passes scope at
the call site; StateBackend ignores it (already isolated per
execution). LocalBackend constructor unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread package.json
},
"engines": {
"node": "^20",
"node": ">=20.12.0 <21.0.0",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I purposely bumped this so we can use some fs functionality such as fs.readdir(..., { recursive: true }) using recursive and using Dirent.parentPath.

Let me know if we shouldn't do this and I can create a manual function to manually walk the recursive directories instead

@jchui-wd jchui-wd marked this pull request as ready for review May 5, 2026 00:24
@jchui-wd jchui-wd changed the base branch from feat/686-StateBackend to feature/SmartAgents May 5, 2026 18:37

const runtimeState = options.agentflowRuntime?.state as ICommonObject
if (startPersistState === true && runtimeState && Object.keys(runtimeState).length) {
if (runtimeState && Object.keys(runtimeState).length) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its safe to remove startPersistState here because it was redundant.

runTimeState is NON EMPTY only if startPersisteState is true

so when Object.keys(runtimeState).length) > 0 already implies that startPersistState is true.

@jchui-wd jchui-wd changed the title feat:687 | smart agents - LocalBackend feat:687 | smart agents - LocalBackend, StateBackend May 5, 2026
Routes paths to sub-backends by longest matching prefix and translates
paths/FilesUpdate keys across the boundary. Wires SANDBOX_TYPE=composite
into the factory and includes it under hasStatefulSmartAgent so state
persistence still applies.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant