AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(agent): Fix `extract_dict_from_response` flakiness
Reinier van der Leerfaf5f9e5a4de
diff --git a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.pyindex 6fe0f4894f..e8c726c180 100644--- a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py+++ b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py@@ -391,7 +391,19 @@ class OneShotAgentPromptStrategy(PromptStrategy):if not response.content:raise InvalidAgentResponseError("Assistant response has no text content")+ self.logger.debug(+ "LLM response content:"+ + (+ f"\n{response.content}"+ if "\n" in response.content+ else f" '{response.content}'"+ )+ )assistant_reply_dict = extract_dict_from_response(response.content)+ self.logger.debug(+ "Validating object extracted from LLM response:\n"+ f"{json.dumps(assistant_reply_dict, indent=4)}"+ )_, errors = self.response_schema.validate_object(object=assistant_reply_dict,diff --git a/autogpts/autogpt/autogpt/json_utils/utilities.py b/autogpts/autogpt/autogpt/json_utils/utilities.pyindex fe203b2905..e5445dcb88 100644--- a/autogpts/autogpt/autogpt/json_utils/utilities.py+++ b/autogpts/autogpt/autogpt/json_utils/utilities.py@@ -18,7 +18,7 @@ def extract_dict_from_response(response_content: str) -> dict[str, Any]:response_content = response_content.lstrip("json")else:# The string may contain JSON.- json_pattern = r"{.*}"+ json_pattern = r"{[\s\S]*}"match = re.search(json_pattern, response_content)if match: