(inputs: ChainValues, runManager?: CallbackManagerForChainRun, config?: RunnableConfig)
| 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 |
nothing calls this directly
no test coverage detected