diff --git a/src/agents/action/action.py b/src/agents/action/action.py index 5544d60c..23fbfbee 100644 --- a/src/agents/action/action.py +++ b/src/agents/action/action.py @@ -25,11 +25,9 @@ def render( def validate_response(self, response: str): response = response.strip().replace("```json", "```") - - if response.startswith("```") and response.endswith("```"): - response = response[3:-3].strip() try: + response = response.split("```")[1].split("```")[0] response = json.loads(response) except Exception as _: return False diff --git a/src/agents/answer/answer.py b/src/agents/answer/answer.py index 94e2575b..11450d8b 100644 --- a/src/agents/answer/answer.py +++ b/src/agents/answer/answer.py @@ -27,10 +27,8 @@ def render( def validate_response(self, response: str): response = response.strip().replace("```json", "```") - if response.startswith("```") and response.endswith("```"): - response = response[3:-3].strip() - try: + response = response.split("```")[1].split("```")[0] response = json.loads(response) except Exception as _: return False diff --git a/src/agents/decision/decision.py b/src/agents/decision/decision.py index 9e989071..44aac745 100644 --- a/src/agents/decision/decision.py +++ b/src/agents/decision/decision.py @@ -17,11 +17,9 @@ def render(self, prompt: str) -> str: def validate_response(self, response: str): response = response.strip().replace("```json", "```") - - if response.startswith("```") and response.endswith("```"): - response = response[3:-3].strip() try: + response = response.split("```")[1].split("```")[0] response = json.loads(response) except Exception as _: return False diff --git a/src/agents/internal_monologue/internal_monologue.py b/src/agents/internal_monologue/internal_monologue.py index dd6152c2..a4324207 100644 --- a/src/agents/internal_monologue/internal_monologue.py +++ b/src/agents/internal_monologue/internal_monologue.py @@ -17,11 +17,9 @@ def render(self, current_prompt: str) -> str: def validate_response(self, response: str): response = response.strip().replace("```json", "```") - - if response.startswith("```") and response.endswith("```"): - response = response[3:-3].strip() try: + response = response.split("```")[1].split("```")[0] response = json.loads(response) except Exception as _: return False diff --git a/src/agents/researcher/researcher.py b/src/agents/researcher/researcher.py index d4f7a102..3485a3be 100644 --- a/src/agents/researcher/researcher.py +++ b/src/agents/researcher/researcher.py @@ -25,9 +25,8 @@ def render(self, step_by_step_plan: str, contextual_keywords: str) -> str: def validate_response(self, response: str) -> dict | bool: response = response.strip().replace("```json", "```") - if response.startswith("```") and response.endswith("```"): - response = response[3:-3].strip() try: + response = response.split("```")[1].split("```")[0] response = json.loads(response) except Exception as _: return False diff --git a/src/agents/runner/runner.py b/src/agents/runner/runner.py index 0ec84d4f..3bbea791 100644 --- a/src/agents/runner/runner.py +++ b/src/agents/runner/runner.py @@ -53,11 +53,9 @@ def render_rerunner( def validate_response(self, response: str): response = response.strip().replace("```json", "```") - - if response.startswith("```") and response.endswith("```"): - response = response[3:-3].strip() try: + response = response.split("```")[1].split("```")[0] response = json.loads(response) except Exception as _: return False @@ -69,13 +67,11 @@ def validate_response(self, response: str): def validate_rerunner_response(self, response: str): response = response.strip().replace("```json", "```") - - if response.startswith("```") and response.endswith("```"): - response = response[3:-3].strip() print(response) try: + response = response.split("```")[1].split("```")[0] response = json.loads(response) except Exception as _: return False