From a15afc102c88149b1055ce1f810682602ec7de6e Mon Sep 17 00:00:00 2001 From: Xiaochao Dong Date: Mon, 26 Jun 2023 17:30:17 +0800 Subject: [PATCH] Relax the action input check for actions that require no input (#6357) When the tool requires no input, the LLM often gives something like this: ```json { "action": "just_do_it" } ``` I have attempted to enhance the prompt, but it doesn't appear to be functioning effectively. Therefore, I believe we should consider easing the check a little bit. Signed-off-by: Xiaochao Dong (@damnever) --- langchain/agents/chat/output_parser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/langchain/agents/chat/output_parser.py b/langchain/agents/chat/output_parser.py index 4da19526db8..c7023426aa0 100644 --- a/langchain/agents/chat/output_parser.py +++ b/langchain/agents/chat/output_parser.py @@ -17,13 +17,15 @@ class ChatOutputParser(AgentOutputParser): try: action = text.split("```")[1] response = json.loads(action.strip()) - includes_action = "action" in response and "action_input" in response + includes_action = "action" in response if includes_answer and includes_action: raise OutputParserException( "Parsing LLM output produced a final answer " f"and a parse-able action: {text}" ) - return AgentAction(response["action"], response["action_input"], text) + return AgentAction( + response["action"], response.get("action_input", {}), text + ) except Exception: if not includes_answer: