|
from rp.config import MAX_AUTONOMOUS_ITERATIONS
|
|
from rp.ui import Colors
|
|
|
|
|
|
def is_task_complete(response, iteration):
|
|
if "error" in response:
|
|
return True
|
|
if "choices" not in response or not response["choices"]:
|
|
return True
|
|
message = response["choices"][0]["message"]
|
|
content = message.get("content", "").lower()
|
|
completion_keywords = [
|
|
"task complete",
|
|
"task is complete",
|
|
"finished",
|
|
"done",
|
|
"successfully completed",
|
|
"task accomplished",
|
|
"all done",
|
|
"implementation complete",
|
|
"setup complete",
|
|
"installation complete",
|
|
]
|
|
error_keywords = [
|
|
"cannot proceed",
|
|
"unable to continue",
|
|
"fatal error",
|
|
"cannot complete",
|
|
"impossible to",
|
|
]
|
|
has_tool_calls = "tool_calls" in message and message["tool_calls"]
|
|
mentions_completion = any((keyword in content for keyword in completion_keywords))
|
|
mentions_error = any((keyword in content for keyword in error_keywords))
|
|
if mentions_error:
|
|
return True
|
|
if mentions_completion and (not has_tool_calls):
|
|
return True
|
|
if iteration > 5 and (not has_tool_calls):
|
|
return True
|
|
if iteration >= MAX_AUTONOMOUS_ITERATIONS:
|
|
print(f"{Colors.YELLOW}⚠ Maximum iterations reached{Colors.RESET}")
|
|
return True
|
|
return False
|