-
-
Save ma-zah/1e2e2e80f5885ad439a6ae76c2b3e1c5 to your computer and use it in GitHub Desktop.
on type safety in LangChain TS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async safePlanNextStep(previousSteps: AgentStep[]): Promise<AgentAction> { | |
try { | |
// This will return either an AgentAction or AgentFinish through outputParser.parse | |
output = await this.agent.plan(steps, inputs); | |
} catch (e) { | |
if (e instanceof OutputParserException) { | |
let observation; | |
const text = e.message; | |
if (this.handleParsingErrors === true) { | |
observation = "Invalid or incomplete response"; | |
} else if (typeof this.handleParsingErrors === "string") { | |
observation = this.handleParsingErrors; | |
} else if (typeof this.handleParsingErrors === "function") { | |
observation = this.handleParsingErrors(e); | |
} else { | |
throw e; | |
} | |
output = { | |
tool: "_Exception", | |
toolInput: observation, | |
log: text, | |
} as AgentAction; | |
} else { | |
throw e; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment