MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / generateSelectedTools

Function generateSelectedTools

packages/components/src/agentflowv2Generator.ts:232–298  ·  view source on GitHub ↗
(nodes: Node[], config: Record<string, any>, question: string, options: ICommonObject)

Source from the content-addressed store, hash-verified

230}
231
232const generateSelectedTools = async (nodes: Node[], config: Record<string, any>, question: string, options: ICommonObject) => {
233 const selectedTools: string[] = []
234
235 for (let i = 0; i < nodes.length; i += 1) {
236 const node = nodes[i]
237 if (!node.data.inputs) {
238 node.data.inputs = {}
239 }
240
241 if (node.data.name === 'agentAgentflow') {
242 const sysPrompt = `You are a workflow orchestrator that is designed to make agent coordination and execution easy. Your goal is to select the tools that are needed to achieve the given task.
243
244Here are the tools to choose from:
245${config.toolNodes}
246
247Here's the selected tools:
248${JSON.stringify(selectedTools, null, 2)}
249
250Output Format should be a list of tool names:
251For example:["googleCustomSearch", "slackMCP"]
252
253Now, select the tools that are needed to achieve the given task. You must only select tools that are in the list of tools above. You must NOT select the tools that are already in the list of selected tools.
254`
255 const tools = await _generateSelectedTools({ ...config, prompt: sysPrompt }, question, options)
256 if (Array.isArray(tools) && tools.length > 0) {
257 selectedTools.push(...tools)
258
259 const existingTools = node.data.inputs.agentTools || []
260 node.data.inputs.agentTools = [
261 ...existingTools,
262 ...tools.map((tool) => ({
263 agentSelectedTool: tool,
264 agentSelectedToolConfig: {
265 agentSelectedTool: tool
266 }
267 }))
268 ]
269 }
270 } else if (node.data.name === 'toolAgentflow') {
271 const sysPrompt = `You are a workflow orchestrator that is designed to make agent coordination and execution easy. Your goal is to select ONE tool that is needed to achieve the given task.
272
273Here are the tools to choose from:
274${config.toolNodes}
275
276Here's the selected tools:
277${JSON.stringify(selectedTools, null, 2)}
278
279Output Format should ONLY one tool name inside of a list:
280For example:["googleCustomSearch"]
281
282Now, select the ONLY tool that is needed to achieve the given task. You must only select tool that is in the list of tools above. You must NOT select the tool that is already in the list of selected tools.
283`
284 const tools = await _generateSelectedTools({ ...config, prompt: sysPrompt }, question, options)
285 if (Array.isArray(tools) && tools.length > 0) {
286 selectedTools.push(...tools)
287
288 node.data.inputs.toolAgentflowSelectedTool = tools[0]
289 node.data.inputs.toolInputArgs = []

Callers 1

generateAgentflowv2Function · 0.85

Calls 2

_generateSelectedToolsFunction · 0.85
stringifyMethod · 0.80

Tested by

no test coverage detected