ContiAI / agents /final_outliners /subtopics_generator.py
alaa wael
alaa handeled content2
6eb2e17
Raw
History Blame Contribute Delete
8.52 kB
from crewai import Agent, Task, Crew, Process, LLM
import os
import json
from modules import llm_g
from schemas import FullCurriculumStructure
def subtopics_generator_agent():
model = llm_g()
return Agent(
role="Arabic Educational Subtopic Generator (Subtopic Developer)",
goal=(
"Analyze the provided metadata ({topic}, {domain}, {audience}, {content_type}, {material_type}) "
"along with the CurriculumStructure (containing the main concept, General_objectives_of_the_plan, and list of units and their details). "
"For each unit — based on its title and details — generate list of coherent and progressive Arabic subtopics (axes). "
"These subtopics should represent a logical and educational flow from foundational understanding "
"to advanced application and creativity. "
"Each unit's subtopic should represent a specific stage of learning progression — starting from basic knowledge acquisition "
"and moving toward critical thinking and creative application. "
## ADD
"Example:"
"- Unit: التفكير التصميمي وحل المشكلات"
"- Given Subtopics:"
" • ماذا يعنى حل المشكلة؟"
" • 4 خطوات لحل المشكلة"
" • الفرق بين التفكير التحليلي والتصميمي في حل المشكلات"
" • نهج التفكير التصميمي لحل المشكلات"
" • نماذج تطبيقية ناجحة في حل المشكلات بالتفكير التصميمي"
"- Observation: The first two are introductory — essential for understanding the later applied parts."
## ADD
"Finally, ensure that all generated subtopics comply with the approved Arabic educational titling standards:\n"
"- Titles must be clear, direct, and precise, avoiding ambiguous or poetic phrasing.\n"
"- Avoid dual or compound titles; use a single, focused phrasing.\n"
"- Each title must reflect its actual educational content accurately.\n"
# "- Limited creativity is acceptable, but without exaggeration or metaphorical obscurity.\n"
"- Always adapt the title to the target audience’s cultural and cognitive level.\n"
"These standards ensure the linguistic clarity and educational value of all generated subtopics."
"Ensure that the subtopics are written as Arabic educational subheadings that align with the unit’s focus, "
"support conceptual growth, and maintain thematic coherence across the curriculum."
"Ensure all subtopics are contextually relevant to the unit's focus and contribute to the learner's comprehensive understanding."
),
backstory=(
"You are a senior Arabic curriculum designer and learning progression specialist. "
# "You possess deep expertise in Arabic pedagogy and cognitive development frameworks such as Bloom’s Taxonomy. "
"You skillfully expand each educational unit into coherent Arabic subtopics that reflect a logical learning progression — "
"starting from basic understanding and moving toward higher-order thinking and creative application. "
"Each subtopic builds upon the previous one to form a cohesive and culturally relevant learning journey. "
"Your designs prioritize conceptual clarity, educational depth, and alignment with Arabic academic standards."
"You also ensure that each generated subtopic is research-backed and can be supported by credible educational materials available online, enabling later integration with content retrieval systems."
## ADD
"You strictly follow the approved Arabic educational title formulation standards, ensuring clarity, precision, and appropriateness for the learner’s level."
),
output_format=(
"Return valid JSON strictly following this structure:\n"
"{\n"
" 'main_concept': '...',\n"
" 'units': [\n"
" {\n"
" 'unit_number': 1,\n"
" 'title': 'الوحدة الأولى: ...',\n"
" 'focus': '...',\n"
" 'axes': [\n"
" {'axis_number': 1, 'title': '...', 'purpose': '...'},\n"
" {'axis_number': 2, 'title': '...', 'purpose': '...'},\n"
" {'axis_number': 3, 'title': '...', 'purpose': '...'},\n"
" {'axis_number': 4, 'title': '...', 'purpose': '...'},\n"
" {'axis_number': 5, 'title': '...', 'purpose': '...'}\n"
" ]\n"
" }, ...\n"
" ]\n"
"}"
),
# llm=llm_open_c35,
llm=model,
allow_delegation=False,
verbose=True,
reasoning=True,
max_iter=100,
)
# ============================================================
# 🧩 3. Axis Generation Task
# ============================================================
def subtopics_generation_task(subtopics_generator_agent):
return Task(
description=(
"## GOAL\n"
"Expand each educational unit from the given file into number of structured Arabic subtopics: {units}. "
# "Each axis should develop the learner’s understanding progressively — starting with remembering, "
# "then understanding, applying, analyzing, and finally creating.\n"
"Each subtopic should represent a cognitive development stage — moving from foundational understanding to applied mastery.\n\n"
"## CONTEXT\n"
# "You are provided with a units_agent_conceptual JSON (containing the main concept, related concepts, and list of units). "
"You are provided with a CurriculumStructure JSON (containing the main concept, General_objectives_of_the_plan, and list of units and their details). "
# "Each unit includes a title and conceptual focus.\n\n"
"## STEPS\n"
"1. Read the CurriculumStructure carefully to understand the hierarchy and conceptual logic.\n"
"2. For each unit:\n"
" - Identify its title and details.\n"
" - Generate list of progressive subtopics that unfold logically.\n"
" - Each subtopic must include:\n"
" • 'subtopic_number': numerical order of the subtopic in the unit.\n"
" • 'title': Arabic title that feels like a subheading in a textbook.\n"
" • 'purpose': one-sentence explanation of the educational goal behind that subtopic.\n\n"
"3. For each generated subtopic\n"
" - Prefer subtopics that are well-established in educational or academic literature.\n"
" - Avoid overly niche or abstract titles that would lack sufficient learning resources.\n\n"
## ADD
"4. Validate that each subtopic:\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"
" can be in form of short sentence or a question\n\n"
"## NOTES\n"
# "- Make sure the subtopics flow naturally, covering introduction, comprehension, practice, and innovation.\n"
# "- The 5 axes should reflect a natural flow following Bloom’s taxonomy: Remember → Understand → Apply → Analyze → Create.\n"
"- Ensure the titles sound academic, culturally appropriate, and pedagogically progressive.\n"
"- Return the result as a valid FullCurriculumStructure JSON containing all units with their subtopics."
),
expected_output="A FullCurriculumStructure JSON object containing all units and their respective list of subtopics each.",
agent=subtopics_generator_agent,
output_json=FullCurriculumStructure,
)