-
-
Notifications
You must be signed in to change notification settings - Fork 24.5k
feat:687 | smart agents - LocalBackend, StateBackend, CompositeBackend, Ability to Read non Text Files #6339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jchui-wd
wants to merge
14
commits into
feature/SmartAgents
Choose a base branch
from
feat/687-LocalBackend
base: feature/SmartAgents
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b1f314e
added utils and protocol interfaces and types for backends fs command…
jchui-wd 4e65f92
sandbox: simplify factory, always wire fs tools, harden mime parse
jchui-wd 871a42f
sandbox: rename class-anchored files to PascalCase
jchui-wd 2478107
- implemented StateBackend with read, write, edit, ls, glob, and gre…
jchui-wd 46ec327
added normalize content to fix potential read grep and glob issues wi…
jchui-wd 60203ff
edit incorrect error message and added todo for Uint8Array for later …
jchui-wd a718f7f
added LocalBackend support for disk sandbox.
jchui-wd 781ac84
sandbox: stream LocalBackend.grep, clarify doc
jchui-wd 5cba802
sandbox: scope LocalBackend root by orgId/chatflowid/chatId
jchui-wd 68e88d8
sandbox: add CompositeBackend with prefix-based routing
jchui-wd 5d11668
Added support for reading non text files
jchui-wd e0fb1a7
sandbox: rewrite only image tool results, let non-image binaries pass…
jchui-wd 2463ca4
sandbox: extract shared BackendProtocol conformance suite
jchui-wd 9b10726
sandbox: implement LocalShellBackend with capability-gated execute tool
jchui-wd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/components/nodes/agentflow/SmartAgent/context/SystemPromptBuilder.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { buildSystemPrompt } from './SystemPromptBuilder' | ||
|
|
||
| describe('buildSystemPrompt — executeEnabled gate', () => { | ||
| const baseOpts = { | ||
| todoListPrompt: '## TODOS_PLACEHOLDER', | ||
| filesystemEnabled: true | ||
| } | ||
|
|
||
| it('omits the Execute Tool block when executeEnabled is false', () => { | ||
| const prompt = buildSystemPrompt({ ...baseOpts, executeEnabled: false }) | ||
| expect(prompt).not.toContain('## Execute Tool') | ||
| }) | ||
|
|
||
| it('omits the Execute Tool block when executeEnabled is undefined', () => { | ||
| const prompt = buildSystemPrompt({ ...baseOpts }) | ||
| expect(prompt).not.toContain('## Execute Tool') | ||
| }) | ||
|
|
||
| it('includes the Execute Tool block when executeEnabled is true', () => { | ||
| const prompt = buildSystemPrompt({ ...baseOpts, executeEnabled: true }) | ||
| expect(prompt).toContain('## Execute Tool') | ||
| }) | ||
|
|
||
| it('orders Filesystem Tools before Execute Tool when both are enabled', () => { | ||
| const prompt = buildSystemPrompt({ ...baseOpts, executeEnabled: true }) | ||
| const fsIdx = prompt.indexOf('## Filesystem Tools') | ||
| const execIdx = prompt.indexOf('## Execute Tool') | ||
| expect(fsIdx).toBeGreaterThan(-1) | ||
| expect(execIdx).toBeGreaterThan(-1) | ||
| expect(fsIdx).toBeLessThan(execIdx) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/components/nodes/agentflow/SmartAgent/sandbox/BackendProtocol.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| export interface FileInfo { | ||
| name: string | ||
| path: string | ||
| size: number | ||
| isDirectory: boolean | ||
| mimeType?: string | ||
| } | ||
|
|
||
| export interface FileData { | ||
| /** | ||
| * String-encoded file content. Text files use utf-8; binary files use base64. | ||
| * Backends decode base64 to Uint8Array at the read() boundary (see decodeFileContent in utils.ts). | ||
| */ | ||
| content: string | ||
| mimeType: string | ||
| created_at: number | ||
| modified_at: number | ||
| } | ||
|
|
||
| // FilesUpdate: returned by StateBackend's write/edit so the tool layer can splice | ||
| // changes into SmartAgent graph state. `null` means "externally persisted — skip splice." | ||
| export type FilesUpdate = Record<string, FileData | null> | ||
|
|
||
| export interface GrepMatch { | ||
| path: string | ||
| line: number | ||
| content: string | ||
| } | ||
|
|
||
| export type LsResult = { files: FileInfo[] } | { error: string } | ||
| export type ReadResult = | ||
| | { content: string; mimeType: string; truncated: boolean } | ||
| | { content: Uint8Array; mimeType: string } | ||
| | { error: string } | ||
| export type ReadRawResult = { data: FileData } | { error: string } | ||
| export type WriteResult = { path: string; filesUpdate: FilesUpdate | null } | { error: string } | ||
| export type EditResult = { path: string; occurrences: number; filesUpdate: FilesUpdate | null } | { error: string } | ||
| export type GrepResult = { matches: GrepMatch[]; truncated: boolean } | { error: string } | ||
| export type GlobResult = { files: FileInfo[]; truncated: boolean } | { error: string } | ||
|
|
||
| export interface BackendProtocol { | ||
| ls(path: string): Promise<LsResult> | ||
| read(path: string, offset?: number, limit?: number): Promise<ReadResult> | ||
| readRaw(path: string): Promise<ReadRawResult> | ||
| write(path: string, content: string | Uint8Array): Promise<WriteResult> | ||
| edit(path: string, oldStr: string, newStr: string, replaceAll?: boolean): Promise<EditResult> | ||
| grep(pattern: string, path?: string | null, glob?: string | null): Promise<GrepResult> | ||
| glob(pattern: string, path?: string): Promise<GlobResult> | ||
| } | ||
|
|
||
| // Default line cap for read() when the LLM doesn't pass one. Backends use this to | ||
| // paginate large text files so a single read can't blow the model's context window | ||
| // (~500 lines ≈ a few thousand tokens). Matches Claude Code's Read tool default. | ||
| export const DEFAULT_READ_LIMIT = 500 | ||
|
|
||
| // Cap on results returned by listing operations (glob, grep) across all backends. | ||
| export const MAX_LIST_OBJECTS = 1_000 | ||
|
|
||
| export type ExecuteResult = { output: string; exitCode: number; truncated: boolean } | ||
|
|
||
| /** | ||
| * Extends BackendProtocol with shell command execution. | ||
| */ | ||
| export interface ShellBackendProtocol extends BackendProtocol { | ||
| execute(command: string): Promise<ExecuteResult> | ||
| } | ||
|
|
||
| // Cap on combined stdout/stderr bytes returned from execute(). Beyond this, the | ||
| // output is truncated and ExecuteResult.truncated is set. | ||
| export const MAX_OUTPUT_BYTES = 100_000 | ||
|
|
||
| // Default per-command timeout for LocalShellBackend.execute(). Override via the | ||
| // SANDBOX_LOCAL_SHELL_TIMEOUT_MS env var. | ||
| export const LOCAL_SHELL_TIMEOUT_DEFAULT_MS = 30_000 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 usingDirent.parentPath.Let me know if we shouldn't do this and I can create a manual function to manually walk the recursive directories instead