langchain
langchain copied to clipboard
Issues with leading line breaks in conversational agent - possible solution?
When the LLM returns a leading line break an error is returned Could not parse LLM output from /agents/conversational/base.py I am using the conversational-react-description agent
This can be reliably replicated by asking "Write three lines with line breaks" Note the return does not have a space after the initial AI: This is causing the issue
Thought: Do I need to use a tool? No AI: Line one
Line two
Line three
The problem appears to be line 78 if f"{self.ai_prefix}: " in llm_output:
Where a space after the ai_prefix is expected. With the above example there is no space and consequently it fails. I have tried this solution below which simply adds the space if the prefix is truncated by a new line
def _extract_tool_and_input(self, llm_output: str) -> Optional[Tuple[str, str]]: # New line to add a space after prefix llm_output = llm_output.replace(f"{self.ai_prefix}:\n", f"{self.ai_prefix}: \n")
good catch - will fix
Awesome work BTW @hwchase17
should be fixed now! thanks for flagging