Spaces:
Sleeping
Sleeping
| from crewai import Agent, Task, Crew, Process, LLM | |
| import os | |
| import json | |
| from modules import llm | |
| #from schemas import CurriculumOutline | |
| # ========= 4. Outline Agent ========= | |
| outline_agent = Agent( | |
| role="Scientific Outline Generator", | |
| goal="\n".join( | |
| [ | |
| "Generate a complete and scientifically accurate training curriculum for the topic: {topic}.", | |
| "The curriculum must be structured, logically sequenced, and pedagogically useful.", | |
| "Avoid vague, redundant, or repetitive points—each topic must be unique and non-overlapping.", | |
| "Ensure strong logical flow: units must progress according to Bloom’s taxonomy principles—starting from simple recall/understanding, moving to deeper analysis, application, evaluation, and finally creation/innovation.", | |
| "Important: Do NOT explicitly use Bloom verbs (e.g., analyze, evaluate, create). Instead, embed the cognitive levels implicitly in the phrasing of topics.", | |
| "When generating topics, always use terms and concepts that are common, searchable, and can be easily found in Arabic or international online sources (articles, courses, books).", | |
| "Avoid overly creative or abstract titles that are difficult to map to real content.", | |
| "Follow this strict format:", | |
| "- Output must be in JSON.", | |
| "- Curriculum must include exactly 4 units.", | |
| "- Each unit must have exactly 5 sub-topics.", | |
| "- Units must be output with keys: unit_title, topics.", | |
| "Each unit must reflect and cover one of the core concepts of the topic, so that together they encompass all aspects of the subject.", | |
| "The 4 units must be interconnected, sequentially linked, and collectively ensure full coverage of all concepts of the topic, leaving no gaps.", | |
| "Ensure all text is written in **Arabic language**.", | |
| "Units should be connected and form a comprehensive training program that gradually increases in cognitive depth according to Bloom’s taxonomy.", | |
| "Always adapt to metadata: domain ({domain}), content_type ({content_type}), audience ({audience}), material_type ({material_type}).", | |
| "Apply DNA methodology explicitly in topic design:", | |
| "- material_type:", | |
| "-- Conceptual: theories, principles, abstract knowledge.", | |
| "-- Procedural: step-by-step instructions or methods.", | |
| "-- Structural: frameworks, models, or system views.", | |
| "-- Personal: learner reflection, skills, or self-development aspects.", | |
| "-- Realistic: real-world examples, applications, or case studies.", | |
| "- content_type:", | |
| "-- Educational → for structured learning (e.g., lessons, modules)", | |
| "-- Awareness → for informative/raising awareness purposes (e.g., campaigns, workshops)", | |
| "-- Training → for skill development with step-by-step practice (e.g., hands-on, exercises)", | |
| "Important: The curriculum title must be identical to the input topic, and unit titles must reflect or embed the meaning of this title.", | |
| ] | |
| ), | |
| backstory="\n".join( | |
| [ | |
| "This agent acts as both a scientific researcher and curriculum designer.", | |
| "It generates structured outlines in the form of 4 units × 5 topics, aligned with DNA methodology.", | |
| "It ensures progression follows Bloom’s taxonomy: Unit 1 covers basic recall/understanding, Unit 2 focuses on application of methods/tools, Unit 3 emphasizes analysis and evaluation in real contexts, and Unit 4 explores integration, innovation, or advanced synthesis.", | |
| "The topics must always be realistic, practical, and searchable in Arabic or global sources to ensure that real content can be gathered later.", | |
| "The final output must always be in Arabic.", | |
| "The curriculum should progress from simple to complex, reflecting Bloom’s cognitive hierarchy, but without explicitly naming Bloom’s verbs in the text.", | |
| ] | |
| ), | |
| llm=llm, | |
| verbose=True, | |
| reasoning=True, | |
| max_reasoning_attempts=3, | |
| max_iter=100, | |
| ) | |
| # ========= 5. Task ========= | |
| outline_task = Task( | |
| description="\n".join( | |
| [ | |
| "Generate a structured outline for the topic: {topic}.", | |
| "The output must strictly follow this format:", | |
| "- JSON object with keys: 'title' and 'units'.", | |
| "- 'title': must be exactly the same as the input topic (in Arabic).", | |
| "- 'units': exactly 4 items.", | |
| "- Each unit must have:", | |
| " - unit_title (string, Arabic, must reflect or embed the curriculum title meaning)", | |
| " - topics (list of exactly 5 short topics, in Arabic).", | |
| "Ensure the units flow logically, progressively, and cover the subject fully.", | |
| "The units must align with Bloom’s taxonomy progression: Unit 1 = basic knowledge & understanding, Unit 2 = tools & applications, Unit 3 = analysis & evaluation, Unit 4 = synthesis & advanced innovation.", | |
| "Do NOT explicitly use Bloom’s action verbs; express the cognitive levels implicitly in the phrasing of topics.", | |
| "Each topic must embed one aspect of DNA methodology (Conceptual, Procedural, Structural, Personal, Realistic) and (content_type: Training, Awareness, Educational).", | |
| "All topics must be formulated using widely recognized and searchable concepts (to allow collecting real content from online sources).", | |
| "Avoid repetition—no two topics should overlap in meaning.", | |
| "Do not add extra fields outside the schema.", | |
| "The entire output must be in Arabic.", | |
| ] | |
| ), | |
| expected_output=( | |
| "A valid JSON object with this structure:\n" | |
| "{\n" | |
| ' "title": "string (Arabic curriculum title)",\n' | |
| ' "units": [\n' | |
| " {\n" | |
| ' "unit_title": "string (Arabic, must reflect the title)",\n' | |
| ' "topics": ["topic1", "topic2", "topic3", "topic4", "topic5"]\n' | |
| " }, ... (4 units total)\n" | |
| " ]\n" | |
| "}" | |
| ), | |
| #output_json=CurriculumOutline, | |
| agent=outline_agent, | |
| ) | |