Skip to content

Commit

Permalink
langchain[patch]: Fixes bug in ReAct agent that prevents parsing erro…
Browse files Browse the repository at this point in the history
…r handling (#6624)

Co-authored-by: Jacob Lee <jacoblee93@gmail.com>
  • Loading branch information
obround and jacoblee93 authored Aug 26, 2024
1 parent 1250ca7 commit eff7879
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions langchain/src/agents/react/output_parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AgentAction, AgentFinish } from "@langchain/core/agents";
import { renderTemplate } from "@langchain/core/prompts";
import { OutputParserException } from "@langchain/core/output_parsers";
import { AgentActionOutputParser } from "../types.js";
import { FORMAT_INSTRUCTIONS } from "./prompt.js";

Expand Down Expand Up @@ -69,7 +70,7 @@ export class ReActSingleInputOutputParser extends AgentActionOutputParser {
const actionMatch = text.match(regex);
if (actionMatch) {
if (includesAnswer) {
throw new Error(
throw new OutputParserException(
`${FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE}: ${text}`
);
}
Expand All @@ -95,7 +96,7 @@ export class ReActSingleInputOutputParser extends AgentActionOutputParser {
};
}

throw new Error(`Could not parse LLM output: ${text}`);
throw new OutputParserException(`Could not parse LLM output: ${text}`);
}

/**
Expand Down

0 comments on commit eff7879

Please sign in to comment.