|
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", "")
|
|
|
|
if "[TASK_COMPLETE]" in content:
|
|
return True
|
|
|
|
content_lower = 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",
|
|
]
|
|
simple_response_keywords = [
|
|
"hello",
|
|
"hi there",
|
|
"how can i help",
|
|
"how can i assist",
|
|
"what can i do for you",
|
|
]
|
|
has_tool_calls = "tool_calls" in message and message["tool_calls"]
|
|
mentions_completion = any((keyword in content_lower for keyword in completion_keywords))
|
|
mentions_error = any((keyword in content_lower for keyword in error_keywords))
|
|
is_simple_response = any((keyword in content_lower for keyword in simple_response_keywords))
|
|
if mentions_error:
|
|
return True
|
|
if mentions_completion and (not has_tool_calls):
|
|
return True
|
|
if is_simple_response and iteration >= 1:
|
|
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
|