Merge pull request #457 from octo-patch/fix/issue-367-make-plan-infinite-loop

fix: add max retry limit to PlannerAgent.make_plan to prevent infinite loop
This commit is contained in:
Martin
2026-04-05 11:58:09 +02:00
committed by GitHub
+8 -1
View File
@@ -147,17 +147,23 @@ class PlannerAgent(Agent):
pretty_print(f"{task['agent']} -> {task['task']}", color="info") pretty_print(f"{task['agent']} -> {task['task']}", color="info")
pretty_print("▔▗ E N D ▖▔", color="status") pretty_print("▔▗ E N D ▖▔", color="status")
async def make_plan(self, prompt: str) -> str: async def make_plan(self, prompt: str, max_retries: int = 4) -> str:
""" """
Asks the LLM to make a plan. Asks the LLM to make a plan.
Args: Args:
prompt (str): The prompt to be sent to the LLM. prompt (str): The prompt to be sent to the LLM.
max_retries (int): Maximum number of retries before giving up.
Returns: Returns:
str: The plan made by the LLM. str: The plan made by the LLM.
""" """
ok = False ok = False
answer = None answer = None
retries = 0
while not ok: while not ok:
if retries >= max_retries:
pretty_print(f"Failed to make a plan after {max_retries} attempts. Giving up.", color="failure")
self.logger.warning(f"make_plan exceeded max retries ({max_retries}).")
return []
animate_thinking("Thinking...", color="status") animate_thinking("Thinking...", color="status")
self.memory.push('user', prompt) self.memory.push('user', prompt)
answer, reasoning = await self.llm_request() answer, reasoning = await self.llm_request()
@@ -168,6 +174,7 @@ class PlannerAgent(Agent):
self.show_plan(agents_tasks, answer) self.show_plan(agents_tasks, answer)
prompt = f"Failed to parse the tasks. Please write down your task followed by a json plan within ```json. Do not ask for clarification.\n" prompt = f"Failed to parse the tasks. Please write down your task followed by a json plan within ```json. Do not ask for clarification.\n"
pretty_print("Failed to make plan. Retrying...", color="warning") pretty_print("Failed to make plan. Retrying...", color="warning")
retries += 1
continue continue
self.show_plan(agents_tasks, answer) self.show_plan(agents_tasks, answer)
ok = True ok = True