53 lines
No EOL
2.3 KiB
Python
53 lines
No EOL
2.3 KiB
Python
# executionState.py
|
|
# Contains all execution state management logic extracted from managerChat.py
|
|
|
|
from typing import List
|
|
from modules.interfaces.interfaceChatModel import TaskStep, ActionExecutionResult
|
|
|
|
class TaskExecutionState:
|
|
"""Manages state during task execution with retry logic"""
|
|
def __init__(self, task_step: TaskStep):
|
|
self.task_step = task_step
|
|
self.successful_actions: List[ActionExecutionResult] = [] # Preserved across retries
|
|
self.failed_actions: List[ActionExecutionResult] = [] # For analysis
|
|
self.current_action_index = 0
|
|
self.retry_count = 0
|
|
self.improvements = []
|
|
self.partial_results = {} # Store intermediate results
|
|
self.max_retries = 3
|
|
|
|
def addSuccessfulAction(self, action_result: ActionExecutionResult):
|
|
self.successful_actions.append(action_result)
|
|
if action_result.data.get('resultLabel'):
|
|
self.partial_results[action_result.data['resultLabel']] = action_result
|
|
|
|
def addFailedAction(self, action_result: ActionExecutionResult):
|
|
self.failed_actions.append(action_result)
|
|
|
|
def getAvailableResults(self) -> list:
|
|
return [result.data.get('resultLabel', '') for result in self.successful_actions if result.data.get('resultLabel')]
|
|
|
|
def shouldRetryTask(self) -> bool:
|
|
return len(self.successful_actions) > 0 and len(self.failed_actions) > 0
|
|
|
|
def canRetry(self) -> bool:
|
|
return self.retry_count < self.max_retries
|
|
|
|
def incrementRetryCount(self):
|
|
self.retry_count += 1
|
|
|
|
def getFailurePatterns(self) -> list:
|
|
patterns = []
|
|
for action in self.failed_actions:
|
|
error = action.error.lower() if action.error else ''
|
|
if "timeout" in error:
|
|
patterns.append("timeout_issues")
|
|
elif "document_not_found" in error or "file not found" in error:
|
|
patterns.append("document_reference_issues")
|
|
elif "empty_result" in error or "no content" in error:
|
|
patterns.append("content_extraction_issues")
|
|
elif "invalid_format" in error or "wrong format" in error:
|
|
patterns.append("format_issues")
|
|
elif "permission" in error or "access denied" in error:
|
|
patterns.append("permission_issues")
|
|
return list(set(patterns)) |