Skip to content

The agent engineering platform.

Fixed Regular expression (#2933)

Azam Iftikhar1e655d5ffda7
diff --git a/docs/modules/agents/agents/custom_agent_with_tool_retrieval.ipynb b/docs/modules/agents/agents/custom_agent_with_tool_retrieval.ipynb
index b445ec9568..c81cc19e73 100644
--- a/docs/modules/agents/agents/custom_agent_with_tool_retrieval.ipynb
+++ b/docs/modules/agents/agents/custom_agent_with_tool_retrieval.ipynb
@@ -315,7 +315,7 @@
" log=llm_output,\n",
" )\n",
" # Parse out the action and action input\n",
- " regex = r\"Action: (.*?)[\\n]*Action Input:[\\s]*(.*)\"\n",
+ " regex = r\"Action\\s*\\d*\\s*:(.*?)\\nAction\\s*\\d*\\s*Input\\s*\\d*\\s*:[\\s]*(.*)\"\n",
" match = re.search(regex, llm_output, re.DOTALL)\n",
" if not match:\n",
" raise ValueError(f\"Could not parse LLM output: `{llm_output}`\")\n",
diff --git a/docs/modules/agents/agents/custom_llm_agent.ipynb b/docs/modules/agents/agents/custom_llm_agent.ipynb
index cd2092d783..5b9da883b5 100644
--- a/docs/modules/agents/agents/custom_llm_agent.ipynb
+++ b/docs/modules/agents/agents/custom_llm_agent.ipynb
@@ -204,7 +204,7 @@
" log=llm_output,\n",
" )\n",
" # Parse out the action and action input\n",
- " regex = r\"Action: (.*?)[\\n]*Action Input:[\\s]*(.*)\"\n",
+ " regex = r\"Action\\s*\\d*\\s*:(.*?)\\nAction\\s*\\d*\\s*Input\\s*\\d*\\s*:[\\s]*(.*)\"\n",
" match = re.search(regex, llm_output, re.DOTALL)\n",
" if not match:\n",
" raise ValueError(f\"Could not parse LLM output: `{llm_output}`\")\n",
diff --git a/docs/modules/agents/agents/custom_llm_chat_agent.ipynb b/docs/modules/agents/agents/custom_llm_chat_agent.ipynb
index c4b5e2d6cb..571c928dd0 100644
--- a/docs/modules/agents/agents/custom_llm_chat_agent.ipynb
+++ b/docs/modules/agents/agents/custom_llm_chat_agent.ipynb
@@ -206,7 +206,7 @@
" log=llm_output,\n",
" )\n",
" # Parse out the action and action input\n",
- " regex = r\"Action: (.*?)[\\n]*Action Input:[\\s]*(.*)\"\n",
+ " regex = r\"Action\\s*\\d*\\s*:(.*?)\\nAction\\s*\\d*\\s*Input\\s*\\d*\\s*:[\\s]*(.*)\"\n",
" match = re.search(regex, llm_output, re.DOTALL)\n",
" if not match:\n",
" raise ValueError(f\"Could not parse LLM output: `{llm_output}`\")\n",
diff --git a/docs/use_cases/agents/custom_agent_with_plugin_retrieval.ipynb b/docs/use_cases/agents/custom_agent_with_plugin_retrieval.ipynb
index cba8f69fe7..c40605e06e 100644
--- a/docs/use_cases/agents/custom_agent_with_plugin_retrieval.ipynb
+++ b/docs/use_cases/agents/custom_agent_with_plugin_retrieval.ipynb
@@ -375,7 +375,7 @@
" log=llm_output,\n",
" )\n",
" # Parse out the action and action input\n",
- " regex = r\"Action: (.*?)[\\n]*Action Input:[\\s]*(.*)\"\n",
+ " regex = r\"Action\\s*\\d*\\s*:(.*?)\\nAction\\s*\\d*\\s*Input\\s*\\d*\\s*:[\\s]*(.*)\"\n",
" match = re.search(regex, llm_output, re.DOTALL)\n",
" if not match:\n",
" raise ValueError(f\"Could not parse LLM output: `{llm_output}`\")\n",
diff --git a/langchain/agents/mrkl/base.py b/langchain/agents/mrkl/base.py
index 576c1bd895..c44c477b1d 100644
--- a/langchain/agents/mrkl/base.py
+++ b/langchain/agents/mrkl/base.py
@@ -42,7 +42,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()
# \s matches against tab/newline/whitespace
- regex = r"Action: (.*?)[\n]*Action Input:[\s]*(.*)"
+ regex = r"Action\s*\d*\s*:(.*?)\nAction\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)"
match = re.search(regex, llm_output, re.DOTALL)
if not match:
raise ValueError(f"Could not parse LLM output: `{llm_output}`")