# promptFactory.py # Contains all prompt creation functions extracted from managerChat.py import json import logging from typing import Any, Dict # Prompt creation helpers extracted from managerChat.py def createTaskPlanningPrompt(self, context: Dict[str, Any]) -> str: """Create prompt for task planning""" return f"""You are a task planning AI that analyzes user requests and creates structured task plans. USER REQUEST: {context['user_request']} AVAILABLE DOCUMENTS: {', '.join(context['available_documents'])} INSTRUCTIONS: 1. Analyze the user request and available documents 2. Break down the request into 2-4 meaningful high-level task steps 3. Focus on business outcomes, not technical operations 4. For document processing, create ONE task with a comprehensive AI prompt rather than multiple granular tasks 5. Each task should produce meaningful, usable outputs 6. Ensure proper handover between tasks using result labels 7. Return a JSON object with the exact structure shown below TASK PLANNING PRINCIPLES: - Combine related operations into single tasks (e.g., \"Extract and analyze all candidate profiles\" instead of separate \"read file\" and \"analyze content\" tasks) - Use comprehensive AI prompts for document processing rather than multiple small tasks - Focus on business value and outcomes - Keep tasks at a meaningful level of abstraction - Each task should produce results that can be used by subsequent tasks REQUIRED JSON STRUCTURE: {{ \"overview\": \"Brief description of the overall plan\", \"tasks\": [ {{ \"id\": \"task_1\", \"description\": \"Clear description of what this task accomplishes (business outcome)\", \"dependencies\": [\"task_0\"], // IDs of tasks that must complete first \"expected_outputs\": [\"output1\", \"output2\"], \"success_criteria\": [\"criteria1\", \"criteria2\"], \"required_documents\": [\"doc1\", \"doc2\"], \"estimated_complexity\": \"low|medium|high\", \"ai_prompt\": \"Comprehensive AI prompt for document processing tasks (if applicable)\" }} ] }} EXAMPLES OF GOOD TASK DESCRIPTIONS: - \"Extract and analyze all candidate profiles to identify key qualifications and experience\" - \"Create evaluation matrix and rate candidates against product designer criteria\" - \"Generate comprehensive PowerPoint presentation for management decision\" - \"Store final presentation in SharePoint for specified account\" EXAMPLES OF BAD TASK DESCRIPTIONS: - \"Open and read the PDF file\" (too granular) - \"Identify table structure\" (technical detail) - \"Convert data to CSV format\" (implementation detail) NOTE: Respond with ONLY the JSON object. Do not include any explanatory text.""" async def createActionDefinitionPrompt(self, context) -> str: """Create prompt for action generation with enhanced document extraction guidance and retry context""" task_step = context.task_step workflow = context.workflow available_docs = context.available_documents or [] previous_results = context.previous_results or [] improvements = context.improvements or [] retry_count = context.retry_count or 0 previous_action_results = context.previous_action_results or [] previous_review_result = context.previous_review_result methodList = self.service.getMethodsList() method_actions = {} for sig in methodList: if '.' in sig: method, rest = sig.split('.', 1) action = rest.split('(')[0] method_actions.setdefault(method, []).append((action, sig)) messageSummary = await self.service.summarizeChat(workflow.messages) docRefs = self.service.getDocumentReferenceList() connRefs = self.service.getConnectionReferenceList() all_doc_refs = docRefs.get('chat', []) + docRefs.get('history', []) available_methods_str = '' for method, actions in method_actions.items(): available_methods_str += f"- {method}:\n" for action, sig in actions: available_methods_str += f" - {action}: {sig}\n" task_ai_prompt = task_step.ai_prompt or '' retry_context = "" if retry_count > 0: retry_context = f""" RETRY CONTEXT (Attempt {retry_count}): Previous action results that failed or were incomplete: """ for i, result in enumerate(previous_action_results): retry_context += f"- Action {i+1}: {result.actionMethod or 'unknown'}.{result.actionName or 'unknown'}\n" retry_context += f" Status: {result.success and 'success' or 'failed'}\n" retry_context += f" Error: {result.error or 'None'}\n" retry_context += f" Result: {(result.data.get('result', '') if result.data else '')[:100]}...\n" if previous_review_result: retry_context += f""" Previous review feedback: - Status: {previous_review_result.status or 'unknown'} - Reason: {previous_review_result.reason or 'No reason provided'} - Quality Score: {previous_review_result.quality_score or 0}/10 - Missing Outputs: {', '.join(previous_review_result.missing_outputs or [])} - Unmet Criteria: {', '.join(previous_review_result.unmet_criteria or [])} """ expected_outputs_str = ', '.join(task_step.expected_outputs or []) success_criteria_str = ', '.join(task_step.success_criteria or []) previous_results_str = ', '.join(previous_results) if previous_results else 'None' improvements_str = str(improvements) if improvements else 'None' available_connections_str = '\n'.join(f"- {conn}" for conn in connRefs) available_documents_str = '\n'.join( f"- {doc.documentsLabel} contains {', '.join(doc.documents)}" for doc in all_doc_refs ) prompt = f""" You are an action generation AI that creates specific actions to accomplish a task step. DOCUMENT REFERENCE TYPES: - docItem: Reference to a single document. Format: "docItem::" - docList: Reference to a group of documents under a label. Format: