From d03b82a49f2f26c4788a68902f8d19a752ddbb60 Mon Sep 17 00:00:00 2001
From: ValueOn AG
Date: Thu, 24 Jul 2025 07:12:47 +0200
Subject: [PATCH] fixes
---
modules/chat/handling/handlingActions.py | 30 --------------
modules/chat/handling/handlingTasks.py | 51 ++++++++++++++++++------
modules/chat/managerChat.py | 11 ++---
3 files changed, 44 insertions(+), 48 deletions(-)
diff --git a/modules/chat/handling/handlingActions.py b/modules/chat/handling/handlingActions.py
index 7723ae25..f0bdcc1c 100644
--- a/modules/chat/handling/handlingActions.py
+++ b/modules/chat/handling/handlingActions.py
@@ -136,36 +136,6 @@ class HandlingActions:
except Exception as e:
logger.error(f"Error creating action message: {str(e)}")
- def parseActionResponse(self, response: str) -> list:
- try:
- json_start = response.find('{')
- json_end = response.rfind('}') + 1
- if json_start == -1 or json_end == 0:
- raise ValueError("No JSON found in response")
- json_str = response[json_start:json_end]
- action_data = json.loads(json_str)
- if 'actions' not in action_data:
- raise ValueError("Action response missing 'actions' field")
- return action_data['actions']
- except Exception as e:
- logger.error(f"Error parsing action response: {str(e)}")
- return []
-
- def parseReviewResponse(self, response: str) -> dict:
- try:
- json_start = response.find('{')
- json_end = response.rfind('}') + 1
- if json_start == -1 or json_end == 0:
- raise ValueError("No JSON found in response")
- json_str = response[json_start:json_end]
- review = json.loads(json_str)
- if 'status' not in review:
- raise ValueError("Review response missing 'status' field")
- return review
- except Exception as e:
- logger.error(f"Error parsing review response: {str(e)}")
- return {'status': 'failed', 'reason': f'Parse error: {str(e)}'}
-
# Internal helper methods
def _createGenericValidationPrompt(self, action_result, action, context) -> str:
diff --git a/modules/chat/handling/handlingTasks.py b/modules/chat/handling/handlingTasks.py
index bb7443c9..6f4d24d4 100644
--- a/modules/chat/handling/handlingTasks.py
+++ b/modules/chat/handling/handlingTasks.py
@@ -69,7 +69,20 @@ class HandlingTasks:
prompt = await self.service.callAiTextAdvanced(
createActionDefinitionPrompt(self, context)
)
- actions = self.handlingActions.parseActionResponse(prompt)
+ # Inline parseActionResponse logic here
+ json_start = prompt.find('{')
+ json_end = prompt.rfind('}') + 1
+ if json_start == -1 or json_end == 0:
+ raise ValueError("No JSON found in response")
+ json_str = prompt[json_start:json_end]
+ try:
+ action_data = json.loads(json_str)
+ except Exception as e:
+ logger.error(f"Error parsing action response JSON: {str(e)}")
+ action_data = {}
+ if 'actions' not in action_data:
+ raise ValueError("Action response missing 'actions' field")
+ actions = action_data['actions']
if not self._validateActions(actions, context):
logger.error("Generated actions failed validation")
raise Exception("AI-generated actions failed validation - AI is required for action generation")
@@ -166,19 +179,31 @@ class HandlingTasks:
# Use promptFactory for review prompt
prompt = await createResultReviewPrompt(self, review_context)
response = await self.service.callAiTextAdvanced(prompt)
- review_dict = self.handlingActions.parseReviewResponse(response)
- review_dict.setdefault('status', 'unknown')
- review_dict.setdefault('reason', 'No reason provided')
- review_dict.setdefault('quality_score', 5)
+ # Inline parseReviewResponse logic here
+ json_start = response.find('{')
+ json_end = response.rfind('}') + 1
+ if json_start == -1 or json_end == 0:
+ raise ValueError("No JSON found in review response")
+ json_str = response[json_start:json_end]
+ try:
+ review = json.loads(json_str)
+ except Exception as e:
+ logger.error(f"Error parsing review response JSON: {str(e)}")
+ review = {}
+ if 'status' not in review:
+ raise ValueError("Review response missing 'status' field")
+ review.setdefault('status', 'unknown')
+ review.setdefault('reason', 'No reason provided')
+ review.setdefault('quality_score', 5)
return ReviewResult(
- status=review_dict.get('status', 'unknown'),
- reason=review_dict.get('reason', 'No reason provided'),
- improvements=review_dict.get('improvements', []),
- quality_score=review_dict.get('quality_score', 5),
- missing_outputs=review_dict.get('missing_outputs', []),
- met_criteria=review_dict.get('met_criteria', []),
- unmet_criteria=review_dict.get('unmet_criteria', []),
- confidence=review_dict.get('confidence', 0.5)
+ status=review.get('status', 'unknown'),
+ reason=review.get('reason', 'No reason provided'),
+ improvements=review.get('improvements', []),
+ quality_score=review.get('quality_score', 5),
+ missing_outputs=review.get('missing_outputs', []),
+ met_criteria=review.get('met_criteria', []),
+ unmet_criteria=review.get('unmet_criteria', []),
+ confidence=review.get('confidence', 0.5)
)
except Exception as e:
logger.error(f"Error in reviewTaskCompletion: {str(e)}")
diff --git a/modules/chat/managerChat.py b/modules/chat/managerChat.py
index 9765d564..262563da 100644
--- a/modules/chat/managerChat.py
+++ b/modules/chat/managerChat.py
@@ -41,14 +41,15 @@ class ChatManager:
logger.info(f"Processing task {idx+1}/{len(task_plan.tasks)}: {task_step.description}")
# Define actions
previous_results = self.handlingTasks.getPreviousResults(task_step) if hasattr(self.handlingTasks, 'getPreviousResults') else []
- actions = await self.handlingTasks.defineTaskActions(task_step, workflow, previous_results=previous_results)
+ actions = await self.handlingTasks.generateTaskActions(task_step, workflow, previous_results=previous_results)
if not actions:
logger.warning(f"No actions defined for task {task_step.id}, skipping.")
continue
- # Execute actions
- action_results = await self.handlingTasks.executeTaskActions(actions, workflow)
- # Review completion
- review_result = await self.handlingTasks.reviewTaskCompletion(task_step, actions, action_results, workflow)
+ # Execute actions and get results (including review_result)
+ task_result = await self.handlingTasks.executeTaskActions(actions, workflow)
+ # task_result should include action_results and review_result
+ action_results = getattr(task_result, 'action_results', None)
+ review_result = getattr(task_result, 'review_result', None)
# Handover
handover_data = await self.handlingTasks.prepareTaskHandover(task_step, actions, review_result, workflow)
# Collect results