22
22
import java .util .Map ;
23
23
import java .util .concurrent .TimeUnit ;
24
24
25
+ import com .alibaba .cloud .ai .example .manus .planning .model .vo .ExecutionContext ;
25
26
import org .apache .hc .client5 .http .classic .HttpClient ;
26
27
import org .apache .hc .client5 .http .config .RequestConfig ;
27
28
import org .apache .hc .client5 .http .impl .classic .HttpClients ;
33
34
import org .springframework .ai .tool .function .FunctionToolCallback ;
34
35
import org .springframework .ai .tool .metadata .ToolMetadata ;
35
36
import org .springframework .beans .factory .annotation .Autowired ;
37
+ import org .springframework .beans .factory .annotation .Value ;
36
38
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
37
39
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
38
40
import org .springframework .context .annotation .Bean ;
@@ -154,6 +156,9 @@ public class PlanningFactory implements IPlanningFactory {
154
156
@ Autowired
155
157
private PptGeneratorOperator pptGeneratorOperator ;
156
158
159
+ @ Value ("${agent.init}" )
160
+ private Boolean agentInit = true ;
161
+
157
162
@ Autowired
158
163
private JsxGeneratorOperator jsxGeneratorOperator ;
159
164
@@ -172,6 +177,24 @@ public PlanningFactory(ChromeDriverService chromeDriverService, PlanExecutionRec
172
177
this .tableProcessingService = tableProcessingService ;
173
178
}
174
179
180
+ public PlanningCoordinator createPlanningCoordinator (ExecutionContext context ) {
181
+ // Add all dynamic agents from the database
182
+ List <DynamicAgentEntity > agentEntities = dynamicAgentLoader .getAgents (context );
183
+
184
+ PlanningToolInterface planningTool = new PlanningTool ();
185
+
186
+ PlanCreator planCreator = new PlanCreator (agentEntities , llmService , planningTool , recorder , promptService ,
187
+ manusProperties , streamingResponseHandler );
188
+
189
+ PlanFinalizer planFinalizer = new PlanFinalizer (llmService , recorder , promptService , manusProperties ,
190
+ streamingResponseHandler );
191
+
192
+ PlanningCoordinator planningCoordinator = new PlanningCoordinator (planCreator , planExecutorFactory ,
193
+ planFinalizer );
194
+
195
+ return planningCoordinator ;
196
+ }
197
+
175
198
// Use the enhanced PlanningCoordinator with dynamic executor selection
176
199
public PlanningCoordinator createPlanningCoordinator (String planId ) {
177
200
@@ -225,29 +248,34 @@ public Map<String, ToolCallBackContext> toolCallbackMap(String planId, String ro
225
248
log .error ("SmartContentSavingService is null, skipping BrowserUseTool registration" );
226
249
return toolCallbackMap ;
227
250
}
228
- // Add all tool definitions
229
- toolDefinitions .add (BrowserUseTool .getInstance (chromeDriverService , innerStorageService , objectMapper ));
230
- toolDefinitions .add (DatabaseUseTool .getInstance (dataSourceService , objectMapper ));
231
- toolDefinitions .add (new TerminateTool (planId , expectedReturnInfo ));
232
- toolDefinitions .add (new Bash (unifiedDirectoryManager , objectMapper ));
233
- toolDefinitions .add (new DocLoaderTool ());
234
- toolDefinitions .add (new TextFileOperator (textFileService , innerStorageService , objectMapper ));
235
- // toolDefinitions.add(new InnerStorageTool(unifiedDirectoryManager));
236
- // toolDefinitions.add(pptGeneratorOperator);
237
- // toolDefinitions.add(jsxGeneratorOperator);
238
- toolDefinitions .add (new InnerStorageContentTool (unifiedDirectoryManager , summaryWorkflow , recorder ));
239
- toolDefinitions .add (new FileMergeTool (unifiedDirectoryManager ));
240
- // toolDefinitions.add(new GoogleSearch());
241
- // toolDefinitions.add(new PythonExecute());
242
- toolDefinitions .add (new FormInputTool (objectMapper ));
243
- toolDefinitions .add (new DataSplitTool (planId , manusProperties , sharedStateManager , unifiedDirectoryManager ,
244
- objectMapper , tableProcessingService ));
245
- toolDefinitions
246
- .add (new MapOutputTool (planId , manusProperties , sharedStateManager , unifiedDirectoryManager , objectMapper ));
247
- toolDefinitions
248
- .add (new ReduceOperationTool (planId , manusProperties , sharedStateManager , unifiedDirectoryManager ));
249
- toolDefinitions .add (new FinalizeTool (planId , manusProperties , sharedStateManager , unifiedDirectoryManager ));
250
- toolDefinitions .add (new CronTool (cronService , objectMapper ));
251
+ if (agentInit ) {
252
+ // Add all tool definitions
253
+ toolDefinitions .add (BrowserUseTool .getInstance (chromeDriverService , innerStorageService , objectMapper ));
254
+ toolDefinitions .add (DatabaseUseTool .getInstance (dataSourceService , objectMapper ));
255
+ toolDefinitions .add (new TerminateTool (planId , expectedReturnInfo ));
256
+ toolDefinitions .add (new Bash (unifiedDirectoryManager , objectMapper ));
257
+ toolDefinitions .add (new DocLoaderTool ());
258
+ toolDefinitions .add (new TextFileOperator (textFileService , innerStorageService , objectMapper ));
259
+ // toolDefinitions.add(new InnerStorageTool(unifiedDirectoryManager));
260
+ // toolDefinitions.add(pptGeneratorOperator);
261
+ // toolDefinitions.add(jsxGeneratorOperator);
262
+ toolDefinitions .add (new InnerStorageContentTool (unifiedDirectoryManager , summaryWorkflow , recorder ));
263
+ toolDefinitions .add (new FileMergeTool (unifiedDirectoryManager ));
264
+ // toolDefinitions.add(new GoogleSearch());
265
+ // toolDefinitions.add(new PythonExecute());
266
+ toolDefinitions .add (new FormInputTool (objectMapper ));
267
+ toolDefinitions .add (new DataSplitTool (planId , manusProperties , sharedStateManager , unifiedDirectoryManager ,
268
+ objectMapper , tableProcessingService ));
269
+ toolDefinitions .add (new MapOutputTool (planId , manusProperties , sharedStateManager , unifiedDirectoryManager ,
270
+ objectMapper ));
271
+ toolDefinitions
272
+ .add (new ReduceOperationTool (planId , manusProperties , sharedStateManager , unifiedDirectoryManager ));
273
+ toolDefinitions .add (new FinalizeTool (planId , manusProperties , sharedStateManager , unifiedDirectoryManager ));
274
+ toolDefinitions .add (new CronTool (cronService , objectMapper ));
275
+ }
276
+ else {
277
+ toolDefinitions .add (new TerminateTool (planId , expectedReturnInfo ));
278
+ }
251
279
252
280
List <McpServiceEntity > functionCallbacks = mcpService .getFunctionCallbacks (planId );
253
281
for (McpServiceEntity toolCallback : functionCallbacks ) {
0 commit comments