Bugfix/undefined returned by agent for lowercase (#2885)

fix undefined returned by agent for lowercase
This commit is contained in:
Henry Heng 2024-07-26 00:46:54 +01:00 committed by GitHub
parent c6264a24cc
commit 2dadf2e42b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -339,7 +339,7 @@ export class AgentExecutor extends BaseChain<ChainValues, AgentExecutorOutput> {
}
async _call(inputs: ChainValues, runManager?: CallbackManagerForChainRun): Promise<AgentExecutorOutput> {
const toolsByName = Object.fromEntries(this.tools.map((t) => [t.name.toLowerCase(), t]))
const toolsByName = Object.fromEntries(this.tools.map((t) => [t.name?.toLowerCase(), t]))
const steps: AgentStep[] = []
let iterations = 0
@ -608,7 +608,7 @@ export class AgentExecutor extends BaseChain<ChainValues, AgentExecutorOutput> {
async _getToolReturn(nextStepOutput: AgentStep): Promise<AgentFinish | null> {
const { action, observation } = nextStepOutput
const nameToolMap = Object.fromEntries(this.tools.map((t) => [t.name.toLowerCase(), t]))
const nameToolMap = Object.fromEntries(this.tools.map((t) => [t.name?.toLowerCase(), t]))
const [returnValueKey = 'output'] = this.agent.returnValues
// Invalid tools won't be in the map, so we return False.
if (action.tool in nameToolMap) {