langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
94.89k stars 15.37k forks source link

conversational/agent has a regex not good for multiline Action Inputs coming from the LLM #1645

Closed Konshus1 closed 1 year ago

Konshus1 commented 1 year ago

The conversational agent at /langchain/agents/conversational/base.py looks to have a regex that isn't good for pulling out multiline Action Inputs, whereas the The mrkl agent at /langchain/agents/mrkl/base.py has a good regex for pulling out multiline Action Inputs When I switched the regex FROM the top one at /langchain/agents/conversational/base.py TO the bottom one at /langchain/agents/mrkl/base.py, it worked for me!

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: (.?)[\n]Action Input: (.)" match = re.search(regex, llm_output)**

def get_action_and_input(llm_output: str) -> Tuple[str, str]: """Parse out the action and input from the LLM output.

Note: if you're specifying a custom prompt for the ZeroShotAgent,
you will need to ensure that it meets the following Regex requirements.
The string starting with "Action:" and the following string starting
with "Action Input:" should be separated by a newline.
"""
if FINAL_ANSWER_ACTION in llm_output:
    return "Final Answer", llm_output.split(FINAL_ANSWER_ACTION)[-1].strip()
**regex = r"Action: (.*?)[\n]*Action Input: (.*)"
match = re.search(regex, llm_output, re.DOTALL)**
Konshus1 commented 1 year ago

This looks like Harrison Chase committed the fix soon after this issue was submitted.

dosubot[bot] commented 1 year ago

Hi, @Konshus1! I'm here to help the LangChain team manage their backlog and I wanted to let you know that we are marking this issue as stale.

From what I understand, you raised an issue regarding the regex used in the conversational agent. You suggested switching to the regex used in the mrkl agent, which seemed to solve the problem. Harrison Chase then committed a fix to switch to the suggested regex, resolving the issue.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your contribution and please let us know if you have any further questions or concerns!

Konshus1 commented 1 year ago

All true. I tried a PR for it, but as you say, hchase committed a fix for it. No need any more. It can be closed


From: dosu-beta[bot] @.> Sent: Sunday, August 20, 2023 12:03:41 PM To: langchain-ai/langchain @.> Cc: Kevin Thomas @.>; Mention @.> Subject: Re: [langchain-ai/langchain] conversational/agent has a regex not good for multiline Action Inputs coming from the LLM (Issue #1645)

Hi, @Konshus1https://github.com/Konshus1! I'm here to help the LangChain team manage their backlog and I wanted to let you know that we are marking this issue as stale.

From what I understand, you raised an issue regarding the regex used in the conversational agent. You suggested switching to the regex used in the mrkl agent, which seemed to solve the problem. Harrison Chase then committed a fix to switch to the suggested regex, resolving the issue.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your contribution and please let us know if you have any further questions or concerns!

— Reply to this email directly, view it on GitHubhttps://github.com/langchain-ai/langchain/issues/1645#issuecomment-1685319701, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEDBP6DXSURHPA5SN4723YDXWIYN3ANCNFSM6AAAAAAVZS5HEE. You are receiving this because you were mentioned.Message ID: @.***>

dosubot[bot] commented 1 year ago

Thank you for your response, @Konshus1! We appreciate your contribution and are glad to hear that the issue has been resolved. We will go ahead and close the issue now. If you have any further questions or concerns, please let us know.