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

Method _call

packages/components/src/agents.ts:361–552  ·  view source on GitHub ↗
(inputs: ChainValues, runManager?: CallbackManagerForChainRun, config?: RunnableConfig)

Source from the content-addressed store, hash-verified

359 }
360
361 async _call(inputs: ChainValues, runManager?: CallbackManagerForChainRun, config?: RunnableConfig): Promise<AgentExecutorOutput> {
362 const toolsByName = Object.fromEntries(this.tools.map((t) => [t.name?.toLowerCase(), t]))
363
364 const steps: AgentStep[] = []
365 let iterations = 0
366 let sourceDocuments: Array<Document> = []
367 const usedTools: IUsedTool[] = []
368 let artifacts: any[] = []
369
370 const getOutput = async (finishStep: AgentFinish): Promise<AgentExecutorOutput> => {
371 const { returnValues } = finishStep
372 const additional = await this.agent.prepareForOutput(returnValues, steps)
373 if (sourceDocuments.length) additional.sourceDocuments = flatten(sourceDocuments)
374 if (usedTools.length) additional.usedTools = usedTools
375 if (artifacts.length) additional.artifacts = flatten(artifacts)
376 if (this.returnIntermediateSteps) {
377 return { ...returnValues, intermediateSteps: steps, ...additional }
378 }
379 await runManager?.handleAgentEnd(finishStep)
380 return { ...returnValues, ...additional }
381 }
382
383 while (this.shouldContinue(iterations)) {
384 let output
385 try {
386 output = await this.agent.plan(steps, inputs, runManager?.getChild(), config)
387 } catch (e) {
388 if (e instanceof OutputParserException) {
389 let observation
390 let text = e.message
391 if (this.handleParsingErrors === true) {
392 if (e.sendToLLM) {
393 observation = e.observation
394 text = e.llmOutput ?? ''
395 } else {
396 observation = 'Invalid or incomplete response'
397 }
398 } else if (typeof this.handleParsingErrors === 'string') {
399 observation = this.handleParsingErrors
400 } else if (typeof this.handleParsingErrors === 'function') {
401 observation = this.handleParsingErrors(e)
402 } else {
403 throw e
404 }
405 output = {
406 tool: '_Exception',
407 toolInput: observation,
408 log: text
409 } as AgentAction
410 } else {
411 throw e
412 }
413 }
414 // Check if the agent has finished
415 if ('returnValues' in output) {
416 return getOutput(output)
417 }
418

Callers

nothing calls this directly

Calls 5

shouldContinueMethod · 0.95
getErrorMessageFunction · 0.90
handleAgentActionMethod · 0.80
parseMethod · 0.65
callMethod · 0.45

Tested by

no test coverage detected