ContiAI / agents /outliner_phase /topic_expander_2.py
ziadsameh32's picture
Add login page
325b94c
Raw
History Blame Contribute Delete
2.07 kB
from crewai import Agent, Task, Crew, Process, LLM
import os
import json
from modules import llm
from schemas import ExpandedTopicsList
# ---------------------------
# === Agent 2: Expander to 20 Topics ===
# ---------------------------
def structure_agent():
model = llm()
return Agent(
role="Expander to 20 Topics Agent (Structure & Relations)",
goal=(
"استلم قائمة المحاور المبدئية من Agent1. راجعها لإزالة التكرار ودمج المتقارب منها، "
"ثم أكمل ووسع القائمة لتصل إلى **بالضبط 20 محورًا** مترابطًا. "
"لكل محور اكتب وصفًا تفصيليًا 3-5 سطور يشرح محتوى المحور، ولماذا هو مهم، "
"واذكر علاقات واضحة بين المحاور (مثال: 'مرتبط بـ X لأن...'، أو 'يأتي بعد Y لأنه...'). "
"لا تقسم الوحدات بعد — فقط اضمن اتساق وترابط المحاور الـ20."
),
backstory=(
"أنت مصمم تعليمي بارع في بناء التسلسل المنطقي بين الموضوعات. مهمتك تحويل قائمة أولية "
"إلى خريطة معرفية من 20 محورًا."
),
llm=model,
allow_delegation=False,
verbose=True,
)
def structure_task(structure_agent):
return Task(
description="تنظيف القائمة السابقة وتوسيعها لتصل إلى 20 محورًا مترابطًا مع وصف مفصل.",
expected_output=(
"A JSON list of exactly 20 items:\n"
"[\n"
' { "title": "string (topic title)",\n'
' "description": "string (3–5 lines)",\n'
' "relation": "string (e.g., related to X because...)" }\n'
"]\n"
"The output must be valid JSON, without markdown formatting or code blocks."
),
output_json=ExpandedTopicsList,
# output_file=os.path.join(output_dir, "expanded_20_topics.json"),
agent=structure_agent,
)