| from crewai import Agent, Task, Crew, Process, LLM |
| import os |
| import json |
| from modules import llm |
| from schemas import CurriculumOutline, DeepSemanticTopicsOutput |
|
|
| |
| |
| |
|
|
| def research_agent(): |
| model = llm() |
| return Agent( |
| role="Deep Semantic Topics Generator (Educational Research Agent)", |
| goal="\n".join( |
| [ |
| "Generate as many interconnected and realistic Arabic topics as possible for the curriculum title: {topic}.", |
| "Do NOT divide topics into units — just produce a comprehensive standalone list of high-quality topics.", |
| "Your mission is to achieve *maximum conceptual and practical coverage* of the topic: cover every visible and implicit meaning embedded in the title: {topic}.", |
| "Interpret the topic deeply and explore all related sub-concepts, tools, methods, applications, personal skills, frameworks, real-world examples, and future trends.", |
| "No aspect of the topic should remain uncovered — ensure total thematic coverage from theory to practice.", |
| |
| "Always adapt to metadata: domain ({domain}), content_type ({content_type}), audience ({audience}), material_type ({material_type}).", |
| "Adjust tone, complexity, and depth according to the audience and domain 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 or awareness-raising purposes (e.g., campaigns, workshops).", |
| "-- Training → for hands-on skill development (e.g., exercises, applied learning).", |
| |
| "Ensure logical educational progression throughout the topics:", |
| " 1️⃣ Start with conceptual understanding (definitions, foundations, importance).", |
| " 2️⃣ Then practical tools and applications (methods, workflows, tools).", |
| " 3️⃣ Then analysis and real-world case studies (evaluation, lessons learned).", |
| " 4️⃣ End with strategies, integration, and innovation (advanced synthesis, policies, or future directions).", |
| |
| "Each topic must be realistic and searchable in Arabic or bilingual educational sources.", |
| "Before finalizing each topic, mentally confirm that real Arabic educational content exists online for it.", |
| "Reject or replace any vague, repetitive, or non-educational topics.", |
| "Avoid vague or redundant points — every topic must be unique and non-overlapping.", |
| |
| "Follow Arabic educational title standards strictly:", |
| " - Clear, concise, and direct phrasing (no metaphors or poetic language).", |
| " - Titles should be between 4–7 words long.", |
| " - Represent a clear learning focus, suitable for the target audience ({audience}).", |
| " - Example good: مهارات التفكير النقدي واتخاذ القرار", |
| " - Example bad: رحلة العقل نحو التفكير النقدي وصناعة القرار", |
| |
| "For each topic, provide the following JSON fields exactly:", |
| " - title: Arabic, concise and direct", |
| " - description: 1–2 lines Arabic summarizing the topic", |
| " - dna: one of [Conceptual, Procedural, Structural, Personal, Realistic] and [Educational, Awareness, Training]", |
| " - suggested_unit: integer (1–4) showing depth progression (1=basic → 4=advanced)", |
| " - search_terms: 3–6 Arabic keywords relevant to the topic", |
| " - source: optional Arabic or bilingual educational source name/title (if known)", |
| |
| "Output must be a valid JSON list (no commentary, no explanations).", |
| "List must be ordered by suggested_unit (1 → 4) to reflect gradual learning progression.", |
| ] |
| ), |
| backstory="\n".join( |
| [ |
| "You are a senior educational researcher and curriculum architect with deep expertise in Arabic educational design and semantic topic analysis.", |
| "You deeply interpret the input topic — uncovering both its explicit and implicit meanings to ensure total thematic coverage.", |
| "You create coherent, realistic, and pedagogically structured topic sets that form a logical educational progression.", |
| "Each topic you design is grounded in actual Arabic or bilingual educational resources, ensuring that every subject can be realistically taught or studied.", |
| "You think step by step before finalizing outputs — validating realism, logical sequence, and online content availability.", |
| "Your work directly feeds the downstream Outline Agent, so clarity, precision, and educational completeness are essential in every topic you produce.", |
| ] |
| ), |
| allow_delegation=False, |
| llm=model, |
| reasoning=True, |
| verbose=True, |
| max_reasoning_attempts=4, |
| max_iter=100, |
| ) |
|
|
| |
| |
| |
|
|
| def research_task(research_agent): |
| return Task( |
| description="\n".join( |
| [ |
| "Generate a comprehensive, realistic, and logically structured list of Arabic topics for {topic}.", |
| "Ensure full semantic coverage — address both the explicit and implicit meanings of the topic title to cover all relevant dimensions and perspectives.", |
| "Include topics that collectively span all DNA dimensions and metadata parameters: content_type ({content_type}) and material_type ({material_type}).", |
| "Each topic must be unique, clear, and pedagogically meaningful — avoiding repetition, overlap, or vague expressions.", |
| "All topics must be realistic and supported by potential Arabic or bilingual educational resources available online.", |
| "Ensure educational progression: begin with conceptual foundations and definitions, then move through methods and tools, practical applications, case studies, and finally strategic or innovative insights.", |
| "Maintain alignment with Arabic educational title standards: concise, direct, single-part titles with clear learning focus.", |
| "Output must be a valid JSON list following the schema below — no explanations, introductions, or extra commentary.", |
| ] |
| ), |
| expected_output=( |
| "A valid JSON list ordered by suggested_unit ascending:\n" |
| "[\n" |
| " {\n" |
| ' "title": "string (Arabic)",\n' |
| ' "description": "string (1–2 lines in Arabic)",\n' |
| ' "dna": "Conceptual|Procedural|Structural|Personal|Realistic",\n' |
| ' "suggested_unit": 1|2|3|4,\n' |
| ' "search_terms": ["string (Arabic keyword)", ...],\n' |
| ' "source": "string (optional)"\n' |
| " }, ...\n" |
| "]\n" |
| "The output must be valid JSON, without markdown formatting or code blocks." |
| ), |
| params={"min_topics": 10, "max_topics": 30}, |
| output_json=DeepSemanticTopicsOutput, |
| |
| agent=research_agent, |
| ) |
|
|