@@ -24,9 +24,10 @@ import (
2424 "github.com/bytedance/sonic"
2525
2626 "github.com/cloudwego/eino/adk"
27+ "github.com/cloudwego/eino/adk/filesystem"
2728 "github.com/cloudwego/eino/adk/internal"
29+ filesystem2 "github.com/cloudwego/eino/adk/middlewares/filesystem"
2830 "github.com/cloudwego/eino/components/model"
29- "github.com/cloudwego/eino/components/tool"
3031 "github.com/cloudwego/eino/components/tool/utils"
3132 "github.com/cloudwego/eino/schema"
3233)
@@ -58,6 +59,19 @@ type Config struct {
5859 // MaxIteration limits the maximum number of reasoning iterations the agent can perform.
5960 MaxIteration int
6061
62+ // Backend provides filesystem operations used by tools and offloading.
63+ // If set, filesystem tools (read_file, write_file, edit_file, glob, grep) will be registered.
64+ // Optional.
65+ Backend filesystem.Backend
66+ // Shell provides shell command execution capability.
67+ // If set, an execute tool will be registered to support shell command execution.
68+ // Optional. Mutually exclusive with StreamingShell.
69+ Shell filesystem.Shell
70+ // StreamingShell provides streaming shell command execution capability.
71+ // If set, a streaming execute tool will be registered to support streaming shell command execution.
72+ // Optional. Mutually exclusive with Shell.
73+ StreamingShell filesystem.StreamingShell
74+
6175 // WithoutWriteTodos disables the built-in write_todos tool when set to true.
6276 WithoutWriteTodos bool
6377 // WithoutGeneralSubAgent disables the general-purpose subagent when set to true.
@@ -89,7 +103,7 @@ type Config struct {
89103// This function initializes built-in tools, creates a task tool for subagent orchestration,
90104// and returns a fully configured ChatModelAgent ready for execution.
91105func New (ctx context.Context , cfg * Config ) (adk.ResumableAgent , error ) {
92- middlewares , err := buildBuiltinAgentMiddlewares (cfg . WithoutWriteTodos )
106+ handlers , err := buildBuiltinAgentMiddlewares (ctx , cfg )
93107 if err != nil {
94108 return nil , err
95109 }
@@ -116,12 +130,13 @@ func New(ctx context.Context, cfg *Config) (adk.ResumableAgent, error) {
116130 instruction ,
117131 cfg .ToolsConfig ,
118132 cfg .MaxIteration ,
119- append (middlewares , cfg .Middlewares ... ),
133+ cfg .Middlewares ,
134+ append (handlers , cfg .Handlers ... ),
120135 )
121136 if err != nil {
122137 return nil , fmt .Errorf ("failed to new task tool: %w" , err )
123138 }
124- middlewares = append (middlewares , tt )
139+ handlers = append (handlers , tt )
125140 }
126141
127142 return adk .NewChatModelAgent (ctx , & adk.ChatModelAgentConfig {
@@ -131,8 +146,8 @@ func New(ctx context.Context, cfg *Config) (adk.ResumableAgent, error) {
131146 Model : cfg .ChatModel ,
132147 ToolsConfig : cfg .ToolsConfig ,
133148 MaxIterations : cfg .MaxIteration ,
134- Middlewares : append ( middlewares , cfg .Middlewares ... ) ,
135- Handlers : cfg .Handlers ,
149+ Middlewares : cfg .Middlewares ,
150+ Handlers : append ( handlers , cfg .Handlers ... ) ,
136151
137152 GenModelInput : genModelInput ,
138153 ModelRetryConfig : cfg .ModelRetryConfig ,
@@ -152,16 +167,29 @@ func genModelInput(ctx context.Context, instruction string, input *adk.AgentInpu
152167 return msgs , nil
153168}
154169
155- func buildBuiltinAgentMiddlewares (withoutWriteTodos bool ) ([]adk.AgentMiddleware , error ) {
156- var ms []adk.AgentMiddleware
157- if ! withoutWriteTodos {
170+ func buildBuiltinAgentMiddlewares (ctx context. Context , cfg * Config ) ([]adk.ChatModelAgentMiddleware , error ) {
171+ var ms []adk.ChatModelAgentMiddleware
172+ if ! cfg . WithoutWriteTodos {
158173 t , err := newWriteTodos ()
159174 if err != nil {
160175 return nil , err
161176 }
162177 ms = append (ms , t )
163178 }
164179
180+ if cfg .Backend != nil || cfg .Shell != nil || cfg .StreamingShell != nil {
181+ fm , err := filesystem2 .New (ctx , & filesystem2.Config {
182+ Backend : cfg .Backend ,
183+ Shell : cfg .Shell ,
184+ StreamingShell : cfg .StreamingShell ,
185+ WithoutLargeToolResultOffloading : true ,
186+ })
187+ if err != nil {
188+ return nil , err
189+ }
190+ ms = append (ms , fm )
191+ }
192+
165193 return ms , nil
166194}
167195
@@ -175,27 +203,27 @@ type writeTodosArguments struct {
175203 Todos []TODO `json:"todos"`
176204}
177205
178- func newWriteTodos () (adk.AgentMiddleware , error ) {
206+ func newWriteTodos () (adk.ChatModelAgentMiddleware , error ) {
179207 toolDesc , err := internal .SelectPrompt (internal.I18nPrompts {
180208 English : writeTodosToolDescription ,
181209 Chinese : writeTodosToolDescriptionChinese ,
182210 })
183211 if err != nil {
184- return adk. AgentMiddleware {} , err
212+ return nil , err
185213 }
186214 prompt , err := internal .SelectPrompt (internal.I18nPrompts {
187215 English : writeTodosPrompt ,
188216 Chinese : writeTodosPromptChinese ,
189217 })
190218 if err != nil {
191- return adk. AgentMiddleware {} , err
219+ return nil , err
192220 }
193221 resultMsg , err := internal .SelectPrompt (internal.I18nPrompts {
194222 English : "Updated todo list to %s" ,
195223 Chinese : "已更新待办列表为 %s" ,
196224 })
197225 if err != nil {
198- return adk. AgentMiddleware {} , err
226+ return nil , err
199227 }
200228
201229 t , err := utils .InferTool ("write_todos" , toolDesc , func (ctx context.Context , input writeTodosArguments ) (output string , err error ) {
@@ -207,11 +235,8 @@ func newWriteTodos() (adk.AgentMiddleware, error) {
207235 return fmt .Sprintf (resultMsg , todos ), nil
208236 })
209237 if err != nil {
210- return adk. AgentMiddleware {} , err
238+ return nil , err
211239 }
212240
213- return adk.AgentMiddleware {
214- AdditionalInstruction : prompt ,
215- AdditionalTools : []tool.BaseTool {t },
216- }, nil
241+ return buildAppendPromptTool (prompt , t ), nil
217242}
0 commit comments