(nodes: Node[], config: Record<string, any>, question: string, options: ICommonObject)
| 230 | } |
| 231 | |
| 232 | const 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 | |
| 244 | Here are the tools to choose from: |
| 245 | ${config.toolNodes} |
| 246 | |
| 247 | Here's the selected tools: |
| 248 | ${JSON.stringify(selectedTools, null, 2)} |
| 249 | |
| 250 | Output Format should be a list of tool names: |
| 251 | For example:["googleCustomSearch", "slackMCP"] |
| 252 | |
| 253 | Now, 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 | |
| 273 | Here are the tools to choose from: |
| 274 | ${config.toolNodes} |
| 275 | |
| 276 | Here's the selected tools: |
| 277 | ${JSON.stringify(selectedTools, null, 2)} |
| 278 | |
| 279 | Output Format should ONLY one tool name inside of a list: |
| 280 | For example:["googleCustomSearch"] |
| 281 | |
| 282 | Now, 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 = [] |
no test coverage detected