from crewai import Agent, Task, Crew, Process, LLM import os import json from modules import llm from schemas import AnalysisOutput analysis_agent = Agent( role="Training Analysis Agent", goal="\n".join( [ "Generate the analysis phase for the training program in Arabic based on the topic, outline, and training outcomes.", "Follow the DNA methodology defined in the Outline Agent.", "and follow the DNA parameters ({domain}, {content_type}, {audience}, {material_type}).", "The analysis must include the following elements (taken from the official analysis framework):", "", "1. Goal:", "- Overall goal expected after the training program.", "- Must start with: 'أن يتمكّن المتدرب من ...'.", "- Should be a complete sentence covering all training topics.", "- Must be comprehensive, not limited to one aspect.", "", "2. Target Audience:", "- The group receiving the training.", "- Include average age (e.g., شباب في العشرينات، موظفون في الثلاثينات).", "", "3. Previous Experiences:", "- Short sentences written as noun-phrases (مصادر).", "- Express prior practical or knowledge-based experiences.", "- Examples: ممارسة أنشطة جماعية، مواجهة ضغوط العمل، استخدام أدوات تنظيم، الالتزام بجداول، إدارة مهام يومية.", "", "4. Learner Characteristics:", "- Common traits considering age and developmental aspects:", " * Linguistic development: improving oral expression and listening.", " * Cognitive development: analyzing and linking concepts, applying analytical skills.", " * Social development: tendency to interact and collaborate.", " * Emotional development: reacting to emotional situations.", " * Personality growth: building independent identity and attitudes.", " * Learning styles: preference for practical, auditory, or visual learning.", "", "5. Training Needs:", "- Represent what the learner needs in skills, knowledge, and behaviors.", "- Must be extracted from the training topics.", "- 6 sentences required, each a noun-phrase.", "- Each starts with a مصدر (e.g., فهم، إدراك، توظيف، استيعاب).", "- Must not be copied titles but rephrased needs.", "", "6. Constraints:", "- Barriers that may negatively affect training.", "- Two types:", " * Trainer constraints (4 sentences):Examples: (e.g.,ضيق الوقت، محدودية الوسائل التعليمية، تباين مستويات المتدربين، قلة الدعم الإداري.).", " * Trainee constraints (4 sentences): Examples:(e.g.,ضعف الالتزام، ضعف الحافز، انشغالات شخصية، قلة الخبرة التقنية.).", "- All sentences must start with a مصدر (محدودية، ضعف، صعوبة، تباين).", "- Written as complete noun-phrases only.", "", "7. Duration:", "- Exact training duration (hours/days).", "- Training day = 4 hours.", "- Examples: دورة يوم واحد = 4 ساعات، دورتان = 8 ساعات.", "", "8. Sources of Analysis:", "- Pre-training instructional design processes.", "- Examples: البحث عن مصادر علمية، تحليل احتياجات المتدربين، دراسة محاور الدورة، تحديد الفجوات بين الواقع والمأمول، تجميع البيانات.", "- Must be written as noun-phrases starting and ending with a مصدر (e.g., جمع البيانات وتحليلها).", ] ), backstory="\n".join( [ "This agent acts as an instructional designer responsible for producing the full analysis phase.", "It ensures outputs are consistent with the Arabic training framework (مرحلة التحليل).", "It builds on the Outline and Training Outcomes, while following DNA methodology and ollow the DNA parameters (domain, content_type, audience, material_type).", ] ), llm=llm, verbose=True, ) # ====== Task ====== analysis_task = Task( description="\n".join( [ "Generate the complete analysis phase in Arabic for the training program.", "Use the outline (main_headings + sub_headings + sub_sub_headings) and training outcomes as input.", "Follow the analysis framework:", "- Goal", "- Target Audience", "- Previous Experiences", "- Learner Characteristics", "- Training Needs", "- Constraints", "- Duration", "- Sources of Analysis", "Ensure all outputs are written in Arabic, concise, and aligned with DNA methodology.", "Output must strictly match the Pydantic schema (AnalysisOutput) and be in JSON format.", ] ), expected_output="A JSON object in Arabic with all required analysis fields.", output_json=AnalysisOutput, agent=analysis_agent, )