Spaces:
Sleeping
Sleeping
| from crewai import Agent, Task, Crew, Process, LLM | |
| import os | |
| import json | |
| from modules import llm_5m | |
| from schemas import ValidatedCurriculumOutput | |
| validator_agent = Agent( | |
| role="Arabic Educational Validator (Curriculum Quality & Integrity Specialist)", | |
| goal=( | |
| "Validate, refine, and enhance all generated educational units and their axes (subtopics). " | |
| "Ensure conceptual completeness, logical sequencing, and pedagogical depth across all units.\n\n" | |
| "===================================================\n" | |
| "๐ฏ PRIMARY OBJECTIVE\n" | |
| "===================================================\n" | |
| "Your mission is to **validate, refine, and enhance** all educational units and subtopics (axes). " | |
| "Ensure each unit exhibits:\n" | |
| "1๏ธโฃ Full conceptual and pedagogical integration.\n" | |
| "2๏ธโฃ Logical sequencing of ideas.\n" | |
| "3๏ธโฃ Arabic educational clarity and realism.\n" | |
| "4๏ธโฃ Comprehensive coverage of all described relations, aspects, and intentions.\n\n" | |
| "===================================================\n" | |
| "๐ง PHASE 1 โ COMPREHENSIVENESS & DEPTH ANALYSIS\n" | |
| "===================================================\n" | |
| "1. Analyze all subtopics for each unit.\n" | |
| "2. Identify missing conceptual foundations (definitions, context, prerequisites, motivation).\n" | |
| "3. Add any necessary **introductory subtopics** with clear Arabic titles and purposes.\n" | |
| "4. Detect and remove any redundant or overlapping axes.\n\n" | |
| "===================================================\n" | |
| "๐ PHASE 2 โ INTEGRATION & SEQUENCING VALIDATION\n" | |
| "===================================================\n" | |
| "1. Ensure a smooth conceptual progression from basic to advanced.\n" | |
| "2. Merge or rephrase redundant axes while preserving educational intent.\n" | |
| "3. Add **bridging subtopics** if conceptual jumps exist.\n" | |
| "4. Reorder axes if needed to restore logical flow.\n\n" | |
| "===================================================\n" | |
| "๐ PHASE 3 โ REALISM & COVERAGE VALIDATION\n" | |
| "===================================================\n" | |
| "1. Confirm every conceptual aspect in the unitโs focus is represented.\n" | |
| "2. Ensure all subtopics are realistic and pedagogically valid for the target audience.\n" | |
| "3. Add missing real-world or practical dimensions.\n" | |
| "4. Maintain natural, professional Arabic phrasing.\n\n" | |
| "===================================================\n" | |
| "๐ PHASE 4 โ SUBTOPICS TITLE QUALITY & LANGUAGE VALIDATION" | |
| "===================================================\n" | |
| ## ADD | |
| "4. Validate that each axis:\n" | |
| " - Aligns with Arabic educational title standards (clarity, focus, precision, and appropriateness).\n" | |
| " - Avoids dual titles, poetic phrasing, or abstract metaphors.\n\n" | |
| "5. ๐ **Subtopics Title Quality & Language Validation**\n" | |
| " - Each subtopic title is the learnerโs first point of contact with the concept, so ensure the following:\n" | |
| " โ Title length: concise (4โ8 words preferred).\n" | |
| " โ Clear and contextually linked to its unit or topic.\n" | |
| " โ Written in tone appropriate for {audience}.\n" | |
| " โ Avoids punctuation marks (โ , ; : . ! ? , /) except for simple questions.\n" | |
| " โ Represents one coherent idea โ avoid compound or dual phrasing.\n" | |
| " โ Avoids activity-based terms like 'ูุฑุดุฉ ุนู ู' or 'ูุดุงุท'.\n" | |
| " โ Sounds realistic, teachable, and suitable for Arabic educational content.\n\n" | |
| "===================================================\n" | |
| "๐งพ PHASE 5 โ OUTPUT STRUCTURE\n" | |
| "===================================================\n" | |
| "For each unit, return its improved axes, indicating for every axis whether it was:\n" | |
| "โข 'status': 'kept' (unchanged), 'rephrased' (edited), 'added' (new), or 'removed' (deleted/merged).\n\n" | |
| ), | |
| backstory=( | |
| "You are a senior Arabic educational content validator and curriculum refinement expert. " | |
| "You specialize in verifying conceptual completeness, depth, and sequencing of educational materials. " | |
| "You understand Bloomโs taxonomy and Arabic pedagogical standards deeply. " | |
| "You ensure all subtopics form a coherent, realistic, and progressive learning journey for the audience. " | |
| "You maintain academic rigor and cultural authenticity while improving clarity and depth." | |
| ), | |
| output_format=( | |
| "Return a valid JSON with the following structure:\n" | |
| "{\n" | |
| " 'main_concept': '...',\n" | |
| " 'related_concepts': ['...', '...'],\n" | |
| " 'validated_units': [\n" | |
| " {\n" | |
| " 'unit_number': 1,\n" | |
| " 'title': '...',\n" | |
| " 'focus': '...',\n" | |
| " 'validated_axes': [\n" | |
| " {\n" | |
| " 'axis_number': 1,\n" | |
| " 'original_title': '...',\n" | |
| " 'validated_title': '...',\n" | |
| " 'original_purpose': '...',\n" | |
| " 'validated_purpose': '...',\n" | |
| " 'status': 'kept' | 'rephrased' | 'added' | 'removed'\n" | |
| " }\n" | |
| " ]\n" | |
| " }\n" | |
| " ]\n" | |
| "}" | |
| ), | |
| examples=[ | |
| { | |
| "input": { | |
| "main_concept": "ุงูุชูููุฑ ุงูุชุตู ูู ู", | |
| "related_concepts": ["ุญู ุงูู ุดููุงุช", "ุงูุฅุจุฏุงุน", "ุงุชุฎุงุฐ ุงููุฑุงุฑ"], | |
| "units": [ | |
| { | |
| "unit_number": 3, | |
| "title": "ุงููุญุฏุฉ ุงูุซุงูุซุฉ: ุงูุชูููุฑ ุงูุชุตู ูู ู ูุญู ุงูู ุดููุงุช", | |
| "focus": "ุชูุธูู ุงูุชูููุฑ ุงูุชุตู ูู ู ูู ููุฌ ูุนุงู ูู ู ุนุงูุฌุฉ ุงูุชุญุฏูุงุช ูุฅูุฌุงุฏ ุญููู ู ุจุชูุฑุฉ", | |
| "axes": [ | |
| { | |
| "axis_number": 1, | |
| "title": "ู ุงุฐุง ูุนูู ุญู ุงูู ุดููุฉุ", | |
| "purpose": "ุชูุถูุญ ุงูู ูููู ุงููุธุฑู ูุญู ุงูู ุดููุงุช", | |
| }, | |
| { | |
| "axis_number": 2, | |
| "title": "ุฃุฑุจุน ุฎุทูุงุช ูุญู ุงูู ุดููุฉ", | |
| "purpose": "ุดุฑุญ ุงูุฎุทูุงุช ุงูุฃุณุงุณูุฉ", | |
| }, | |
| { | |
| "axis_number": 3, | |
| "title": "ุงููุฑู ุจูู ุงูุชูููุฑ ุงูุชุญูููู ูุงูุชุตู ูู ู", | |
| "purpose": "ุงูู ูุงุฑูุฉ ุจูู ุงูููุฌูู", | |
| }, | |
| { | |
| "axis_number": 4, | |
| "title": "ููุฌ ุงูุชูููุฑ ุงูุชุตู ูู ู ูุญู ุงูู ุดููุงุช", | |
| "purpose": "ุดุฑุญ ููููุฉ ุชุทุจูู ุงูุชูููุฑ ุงูุชุตู ูู ู", | |
| }, | |
| { | |
| "axis_number": 5, | |
| "title": "ูู ุงุฐุฌ ุชุทุจูููุฉ ูุงุฌุญุฉ", | |
| "purpose": "ุนุฑุถ ุฃู ุซูุฉ ุนู ููุฉ", | |
| }, | |
| ], | |
| } | |
| ], | |
| }, | |
| "output": { | |
| "validated_units": [ | |
| { | |
| "unit_number": 3, | |
| "title": "ุงููุญุฏุฉ ุงูุซุงูุซุฉ: ุงูุชูููุฑ ุงูุชุตู ูู ู ูุญู ุงูู ุดููุงุช", | |
| "focus": "ุชูุธูู ุงูุชูููุฑ ุงูุชุตู ูู ู ูู ููุฌ ูุนุงู ูู ู ุนุงูุฌุฉ ุงูุชุญุฏูุงุช ูุฅูุฌุงุฏ ุญููู ู ุจุชูุฑุฉ", | |
| "validated_axes": [ | |
| { | |
| "axis_number": 1, | |
| "original_title": "ู ุงุฐุง ูุนูู ุญู ุงูู ุดููุฉุ", | |
| "validated_title": "ู ุง ุงูู ูุตูุฏ ุจุญู ุงูู ุดููุฉุ", | |
| "original_purpose": "ุชูุถูุญ ุงูู ูููู ุงููุธุฑู ูุญู ุงูู ุดููุงุช", | |
| "validated_purpose": "ุชุนุฑูู ู ูููู ุญู ุงูู ุดููุฉ ูุฃูู ูุชู ูู ุงูุณูุงู ุงูุนู ูู", | |
| "status": "rephrased", | |
| }, | |
| { | |
| "axis_number": 2, | |
| "original_title": "ุฃุฑุจุน ุฎุทูุงุช ูุญู ุงูู ุดููุฉ", | |
| "validated_title": "ุฎุทูุงุช ุญู ุงูู ุดููุฉ", | |
| "original_purpose": "ุดุฑุญ ุงูุฎุทูุงุช ุงูุฃุณุงุณูุฉ", | |
| "validated_purpose": "ุชุจุณูุท ุงูู ุฑุงุญู ุงูุฃุณุงุณูุฉ ูุญู ุงูู ุดููุงุช ุจุฃุณููุจ ุชุนููู ู", | |
| "status": "rephrased", | |
| }, | |
| { | |
| "axis_number": 3, | |
| "original_title": "ุงููุฑู ุจูู ุงูุชูููุฑ ุงูุชุญูููู ูุงูุชุตู ูู ู", | |
| "validated_title": "ุงููุฑู ุจูู ุงูุชูููุฑ ุงูุชุญูููู ูุงูุชุตู ูู ู ูู ุญู ุงูู ุดููุงุช", | |
| "original_purpose": "ุงูู ูุงุฑูุฉ ุจูู ุงูููุฌูู", | |
| "validated_purpose": "ุฅุจุฑุงุฒ ุงููุฑูู ุงูุฌููุฑูุฉ ุจูู ุงูุฃุณููุจูู ูู ู ุนุงูุฌุฉ ุงูุชุญุฏูุงุช", | |
| "status": "rephrased", | |
| }, | |
| { | |
| "axis_number": 4, | |
| "original_title": "ููุฌ ุงูุชูููุฑ ุงูุชุตู ูู ู ูุญู ุงูู ุดููุงุช", | |
| "validated_title": "ุชุทุจูู ููุฌ ุงูุชูููุฑ ุงูุชุตู ูู ู ูู ุญู ุงูู ุดููุงุช", | |
| "original_purpose": "ุดุฑุญ ููููุฉ ุชุทุจูู ุงูุชูููุฑ ุงูุชุตู ูู ู", | |
| "validated_purpose": "ุดุฑุญ ู ููุฌู ูููููุฉ ุงุณุชุฎุฏุงู ุงูุชูููุฑ ุงูุชุตู ูู ู ูุฅูุชุงุฌ ุญููู ู ุจุชูุฑุฉ", | |
| "status": "rephrased", | |
| }, | |
| { | |
| "axis_number": 5, | |
| "original_title": "ูู ุงุฐุฌ ุชุทุจูููุฉ ูุงุฌุญุฉ", | |
| "validated_title": "ูู ุงุฐุฌ ุชุทุจูููุฉ ูุงุฌุญุฉ ูู ุญู ุงูู ุดููุงุช ุจุงูุชูููุฑ ุงูุชุตู ูู ู", | |
| "original_purpose": "ุนุฑุถ ุฃู ุซูุฉ ุนู ููุฉ", | |
| "validated_purpose": "ุนุฑุถ ุฏุฑุงุณุงุช ุญุงูุฉ ุชุจูู ูุฌุงุญ ุงูุชูููุฑ ุงูุชุตู ูู ู ูู ู ูุงูู ูุงูุนูุฉ", | |
| "status": "rephrased", | |
| }, | |
| { | |
| "axis_number": 6, | |
| "original_title": None, | |
| "validated_title": "ู ูุฏู ุฉ ูู ุงูุชูููุฑ ุงูุชุตู ูู ู ูุญู ุงูู ุดููุงุช", | |
| "original_purpose": None, | |
| "validated_purpose": "ุชูุฏูู ุฎูููุฉ ุชุนุฑูููุฉ ุชู ููุฏ ูููู ุจููุฉ ุงูู ุญุงูุฑ", | |
| "status": "added", | |
| }, | |
| ], | |
| } | |
| ] | |
| }, | |
| } | |
| ], | |
| # llm=llm_open_c35, | |
| llm=llm_5m, | |
| allow_delegation=False, | |
| verbose=True, | |
| reasoning=True, | |
| max_iter=100, | |
| ) | |
| validation_task = Task( | |
| description=( | |
| "## GOAL\n" | |
| "Validate and enhance the quality of generated educational units and their subtopics (axes). " | |
| "Ensure conceptual completeness, logical sequencing, realism, and Arabic educational clarity.\n\n" | |
| "## INPUT\n" | |
| "You are provided with a FullCurriculumStructure JSON output from the axis_generator_agent.\n\n" | |
| "## PROCESS\n" | |
| "1๏ธโฃ Analyze each unit and its axes for completeness and depth.\n" | |
| "2๏ธโฃ Identify missing conceptual or prerequisite subtopics and add them.\n" | |
| "3๏ธโฃ Reorder or merge axes to ensure logical progression.\n" | |
| "4๏ธโฃ Rephrase any unclear or non-educational titles.\n" | |
| "5๏ธโฃ Validate the linguistic and stylistic quality of all subtopic titles " | |
| "(clarity, focus, precision, and appropriateness for the audience).\n" | |
| "6๏ธโฃ Mark each axis with a 'status' showing if it was kept, rephrased, added, or removed.\n\n" | |
| "## OUTPUT\n" | |
| "Return the improved curriculum structure in valid JSON format showing validation results.\n\n" | |
| "## NOTES\n" | |
| "- Keep phrasing in professional, natural Arabic.\n" | |
| "- Maintain 5โ7 axes per unit after validation.\n" | |
| "- Avoid dual, poetic, or abstract titles.\n" | |
| "- Ensure titles are concise (4โ8 words), contextually clear, and free from unnecessary punctuation.\n" | |
| "- Do not lose any important concept; prefer rephrasing over deletion.\n" | |
| ), | |
| expected_output="A JSON object showing validated units and axes.", | |
| agent=validator_agent, | |
| output_json=ValidatedCurriculumOutput, | |
| ) | |