diff --git a/langchain/agents/conversational/base.py b/langchain/agents/conversational/base.py index 16739881970..e47329d2ede 100644 --- a/langchain/agents/conversational/base.py +++ b/langchain/agents/conversational/base.py @@ -78,7 +78,7 @@ class ConversationalAgent(Agent): def _extract_tool_and_input(self, llm_output: str) -> Optional[Tuple[str, str]]: if f"{self.ai_prefix}:" in llm_output: return self.ai_prefix, llm_output.split(f"{self.ai_prefix}:")[-1].strip() - regex = r"Action: (.*?)\nAction Input: (.*)" + regex = r"Action: (.*?)[\n]*Action Input: (.*)" match = re.search(regex, llm_output) if not match: raise ValueError(f"Could not parse LLM output: `{llm_output}`") diff --git a/langchain/agents/mrkl/base.py b/langchain/agents/mrkl/base.py index 2b0e190a7e9..64f0ed71e66 100644 --- a/langchain/agents/mrkl/base.py +++ b/langchain/agents/mrkl/base.py @@ -40,7 +40,7 @@ def get_action_and_input(llm_output: str) -> Tuple[str, str]: """ if FINAL_ANSWER_ACTION in llm_output: return "Final Answer", llm_output.split(FINAL_ANSWER_ACTION)[-1].strip() - regex = r"Action: (.*?)\nAction Input: (.*)" + regex = r"Action: (.*?)[\n]*Action Input: (.*)" match = re.search(regex, llm_output, re.DOTALL) if not match: raise ValueError(f"Could not parse LLM output: `{llm_output}`")