@@ -37,10 +37,17 @@ import (
3737// Config is the configuration for the filesystem middleware
3838type Config struct {
3939 // Backend provides filesystem operations used by tools and offloading.
40- // If the Backend also implements ShellBackend, an additional execute tool
41- // will be registered to support shell command execution.
4240 // required
43- Backend Backend
41+ Backend filesystem.Backend
42+
43+ // Shell provides shell command execution capability.
44+ // If set, an execute tool will be registered to support shell command execution.
45+ // optional, mutually exclusive with StreamingShell
46+ Shell filesystem.Shell
47+ // StreamingShell provides streaming shell command execution capability.
48+ // If set, a streaming execute tool will be registered for real-time output.
49+ // optional, mutually exclusive with Shell
50+ StreamingShell filesystem.StreamingShell
4451
4552 // WithoutLargeToolResultOffloading disables automatic offloading of large tool result to Backend
4653 // optional, false(enabled) by default
@@ -86,6 +93,9 @@ func (c *Config) Validate() error {
8693 if c .Backend == nil {
8794 return errors .New ("backend should not be nil" )
8895 }
96+ if c .StreamingShell != nil && c .Shell != nil {
97+ return errors .New ("shell and streaming shell should not be both set" )
98+ }
8999 return nil
90100}
91101
@@ -109,18 +119,16 @@ func NewMiddleware(ctx context.Context, config *Config) (adk.AgentMiddleware, er
109119 if config .CustomSystemPrompt != nil {
110120 systemPrompt = * config .CustomSystemPrompt
111121 } else {
112- var err error
113122 systemPrompt , err = internal .SelectPrompt (internal.I18nPrompts {
114123 English : ToolsSystemPrompt ,
115124 Chinese : ToolsSystemPromptChinese ,
116125 })
117126 if err != nil {
118127 return adk.AgentMiddleware {}, err
119128 }
120- _ , ok1 := config .Backend .(filesystem.StreamingShellBackend )
121- _ , ok2 := config .Backend .(filesystem.ShellBackend )
122- if ok1 || ok2 {
123- executePrompt , err := internal .SelectPrompt (internal.I18nPrompts {
129+ if config .Shell != nil || config .StreamingShell != nil {
130+ var executePrompt string
131+ executePrompt , err = internal .SelectPrompt (internal.I18nPrompts {
124132 English : ExecuteToolsSystemPrompt ,
125133 Chinese : ExecuteToolsSystemPromptChinese ,
126134 })
@@ -187,10 +195,9 @@ func NewChatModelAgentMiddleware(ctx context.Context, config *Config) (adk.ChatM
187195 if err != nil {
188196 return nil , err
189197 }
190- _ , ok1 := config .Backend .(filesystem.StreamingShellBackend )
191- _ , ok2 := config .Backend .(filesystem.ShellBackend )
192- if ok1 || ok2 {
193- executePrompt , err := internal .SelectPrompt (internal.I18nPrompts {
198+ if config .Shell != nil || config .StreamingShell != nil {
199+ var executePrompt string
200+ executePrompt , err = internal .SelectPrompt (internal.I18nPrompts {
194201 English : ExecuteToolsSystemPrompt ,
195202 Chinese : ExecuteToolsSystemPromptChinese ,
196203 })
@@ -324,16 +331,16 @@ func getFilesystemTools(_ context.Context, validatedConfig *Config) ([]tool.Base
324331 }
325332 tools = append (tools , grepTool )
326333
327- if sb , ok := validatedConfig .Backend .(filesystem. StreamingShellBackend ); ok {
334+ if validatedConfig .StreamingShell != nil {
328335 var executeTool tool.BaseTool
329- executeTool , err = newStreamingExecuteTool (sb , validatedConfig .CustomExecuteToolDesc )
336+ executeTool , err = newStreamingExecuteTool (validatedConfig . StreamingShell , validatedConfig .CustomExecuteToolDesc )
330337 if err != nil {
331338 return nil , err
332339 }
333340 tools = append (tools , executeTool )
334- } else if sb , ok := validatedConfig .Backend .(filesystem. ShellBackend ); ok {
341+ } else if validatedConfig .Shell != nil {
335342 var executeTool tool.BaseTool
336- executeTool , err = newExecuteTool (sb , validatedConfig .CustomExecuteToolDesc )
343+ executeTool , err = newExecuteTool (validatedConfig . Shell , validatedConfig .CustomExecuteToolDesc )
337344 if err != nil {
338345 return nil , err
339346 }
@@ -641,7 +648,7 @@ type executeArgs struct {
641648 Command string `json:"command"`
642649}
643650
644- func newExecuteTool (sb filesystem.ShellBackend , desc * string ) (tool.BaseTool , error ) {
651+ func newExecuteTool (sb filesystem.Shell , desc * string ) (tool.BaseTool , error ) {
645652 d , err := selectToolDesc (desc , ExecuteToolDesc , ExecuteToolDescChinese )
646653 if err != nil {
647654 return nil , err
@@ -658,7 +665,7 @@ func newExecuteTool(sb filesystem.ShellBackend, desc *string) (tool.BaseTool, er
658665 })
659666}
660667
661- func newStreamingExecuteTool (sb filesystem.StreamingShellBackend , desc * string ) (tool.BaseTool , error ) {
668+ func newStreamingExecuteTool (sb filesystem.StreamingShell , desc * string ) (tool.BaseTool , error ) {
662669 d , err := selectToolDesc (desc , ExecuteToolDesc , ExecuteToolDescChinese )
663670 if err != nil {
664671 return nil , err
0 commit comments