The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
feat: temp fixed Could not parse LLM output on agents folder (#7746)
Ani peter benjamine58b1d7073ac
diff --git a/libs/langchain/langchain/agents/conversational_chat/output_parser.py b/libs/langchain/langchain/agents/conversational_chat/output_parser.pyindex 5fa52f1703..6a200af31c 100644--- a/libs/langchain/langchain/agents/conversational_chat/output_parser.py+++ b/libs/langchain/langchain/agents/conversational_chat/output_parser.py@@ -8,21 +8,45 @@ from langchain.output_parsers.json import parse_json_markdownfrom langchain.schema import AgentAction, AgentFinish, OutputParserException+# Define a class that parses output for conversational agentsclass ConvoOutputParser(AgentOutputParser):"""Output parser for the conversational agent."""def get_format_instructions(self) -> str:+ """Returns formatting instructions for the given output parser."""return FORMAT_INSTRUCTIONSdef parse(self, text: str) -> Union[AgentAction, AgentFinish]:+ """Attempts to parse the given text into an AgentAction or AgentFinish.++ Raises:+ OutputParserException if parsing fails.+ """try:+ # Attempt to parse the text into a structured format (assumed to be JSON+ # stored as markdown)response = parse_json_markdown(text)- action, action_input = response["action"], response["action_input"]- if action == "Final Answer":- return AgentFinish({"output": action_input}, text)++ # If the response contains an 'action' and 'action_input'+ if "action" in response and "action_input" in response:+ action, action_input = response["action"], response["action_input"]++ # If the action indicates a final answer, return an AgentFinish+ if action == "Final Answer":+ return AgentFinish({"output": action_input}, text)+ else:+ # Otherwise, return an AgentAction with the specified action and+ # input+ return AgentAction(action, action_input, text)else:- return AgentAction(action, action_input, text)+ # If the necessary keys aren't present in the response, raise an+ # exception+ raise OutputParserException(+ f"Missing 'action' or 'action_input' in LLM output: {text}"+ )except Exception as e:+ # If any other exception is raised during parsing, also raise an+ # OutputParserExceptionraise OutputParserException(f"Could not parse LLM output: {text}") from e@property