o
    kh%                     @   s   d dl mZmZmZmZ d dlmZmZmZm	Z	 d dl m
Z
 d dlmZ d dlmZ d dl mZmZ d dlmZmZmZ d dlZd dlZd d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ e  eG dd dZ dS )    )AgentCrewProcessTask)CrewBaseagentcrewtask)LLM)settings)GuardRailFn)
TaskOutputr   )OptionalTupleUnionN)partial)FileReadTool)load_dotenv)tool)read_defaultsc                   @   s  e Zd ZdZdd ZdZdZedefddZ	edefd	d
Z
edefddZedefddZedefddZedefddZedefddZedefddZedefddZedefddZdefddZdefddZded ed!edefd"d#Zded ed!edefd$d%Zdefd&d'Zdefd(d)Zdefd*d+Zdefd,d-Zdefd.d/Zdefd0d1Zd2d3 Zd4d5 Z d6ed ed!ede!fd7d8Z"d9ed ed!ede!fd:d;Z#defd<d=Z$defd>d?Z%d@dA Z&dBdC Z'dDdE Z(dFdG Z)dHS )IUserJourneyzUser Journey Development crewc              	   C   sh   t tj dtj tjtjtjtjtjtj	d| _
t tj dtj tjtjtjtjtjtj	d| _d S )N/)modeltemperatureapi_keyapi_baseapi_versionseedtimeout)r
   r   PROVIDERLLM1TEMPERATUREOPENAI_KEY1	ENDPOINT1API_VERSION1SEEDTIMEOUTllmLLM2OPENAI_KEY2	ENDPOINT2API_VERSION2llm2self r/   m/home/azureuser/microlearn/backend/user_journey_with_openai/agentic_workflow/src/user_journey_service/crew.py__init__   s$   	zUserJourney.__init__zconfig/agents.yamlzconfig/tasks.yamlreturnc                 C      t | jd | jddS )Ndefaults_estimatorTconfigr'   verboser   agents_configr'   r-   r/   r/   r0   r4   /   
   zUserJourney.defaults_estimatorc                 C   r3   )N
researcherTr5   r8   r-   r/   r/   r0   r;   7   r:   zUserJourney.researcherc                 C   r3   NrestructureTr5   r8   r-   r/   r/   r0   r=   @   r:   zUserJourney.restructurec                 C   r3   r<   )r   r9   r,   r-   r/   r/   r0   restructure2H   r:   zUserJourney.restructure2c                 C   r3   )Ncontent_creatureTr5   r8   r-   r/   r/   r0   r?   P   r:   zUserJourney.content_creaturec                 C   r3   )Nquestion_generatorTr5   r8   r-   r/   r/   r0   r@   X   r:   zUserJourney.question_generatorc                 C   r3   )Nanswer_evaluatorTr5   r8   r-   r/   r/   r0   rA   `   r:   zUserJourney.answer_evaluatorc                 C   r3   )Nfinal_assessmentTr5   r8   r-   r/   r/   r0   rB   h   r:   zUserJourney.final_assessmentc                 C   r3   )Nondemand_learningTr5   r8   r-   r/   r/   r0   rC   p   r:   zUserJourney.ondemand_learningc                 C   r3   )Nstructured_learningTr5   r8   r-   r/   r/   r0   rD   w   r:   zUserJourney.structured_learningc                 C   s   t | jd |t dS )Ndefaults_estimator_taskr6   output_file	guardrail)r   tasks_configr   validate_defaults_opr.   rG   r/   r/   r0   rE      s
   z#UserJourney.defaults_estimator_taskc                 C      t | jd |dS )Nresearch_taskr6   rG   r   rI   r.   research_filer/   r/   r0   rM         zUserJourney.research_taskrG   available_timefeedbackc                 C   2   |dkr
| j d }n| j d }t||t|dS NzFirst iterationrestructure_taskfeedback_taskrF   rI   r   r   get_validate_content_guardrailr.   rG   rS   rT   r6   r/   r/   r0   rW      s   
zUserJourney.restructure_taskc                 C   rU   rV   rY   r[   r/   r/   r0   restructure_task2   s   
zUserJourney.restructure_task2c                 C   rL   )Ncontent_creature_taskrN   rO   rK   r/   r/   r0   r]      rR   z!UserJourney.content_creature_taskc                 C   rL   )Nquestion_generator_taskrN   rO   rK   r/   r/   r0   r^      rR   z#UserJourney.question_generator_taskc                 C      t | jd dS )Nanswer_evaluator_taskr6   rO   r-   r/   r/   r0   r`         z!UserJourney.answer_evaluator_taskc                 C   r_   )Nfinal_assessment_taskra   rO   r-   r/   r/   r0   rc      rb   z!UserJourney.final_assessment_taskc                 C   rL   )Nondemand_learning_taskrN   rO   rK   r/   r/   r0   rd      rR   z"UserJourney.ondemand_learning_taskc                 C   rL   )Nstructured_learning_taskrN   rO   rK   r/   r/   r0   re      rR   z$UserJourney.structured_learning_taskc                 C   s(   t d t|  g| |gtjddS )$Creates the Content Development crewzInside defaults crew....Tagentstasksprocessr7   )printr   r4   rE   r   
sequentialrK   r/   r/   r0   defaults_crew   s   zUserJourney.defaults_crewc                 C       t |  g| |gtjddS )NTrg   )r   r;   rM   r   rl   rP   r/   r/   r0   researcher_crew   s   zUserJourney.researcher_crewoutput_file_1c                 C   $   t |  g| |||gtjddS z)Creates the User Journey Development crewTrg   )r   r=   rW   r   rl   )r.   rp   rS   rT   r/   r/   r0   restructure_crew1      zUserJourney.restructure_crew1output_file_2c                 C   rq   rr   )r   r>   r\   r   rl   )r.   ru   rS   rT   r/   r/   r0   restructure_crew2   rt   zUserJourney.restructure_crew2c                 C   rn   rf   Trg   )r   r?   r]   r   rl   rK   r/   r/   r0   second_stage_crew     zUserJourney.second_stage_crewc                 C   rn   rw   )r   r@   r^   r   rl   rK   r/   r/   r0   qa_gen_crew  ry   zUserJourney.qa_gen_crewc                 C      t |  g|  gtjddS rw   )r   rA   r`   r   rl   r-   r/   r/   r0   evaluator_crew     zUserJourney.evaluator_crewc                 C   r{   rw   )r   rB   rc   r   rl   r-   r/   r/   r0   assessment_crew)  r}   zUserJourney.assessment_crewc                 C   rn   rw   )r   rC   rd   r   rl   rK   r/   r/   r0   ondemand_crew6  ry   zUserJourney.ondemand_crewc                 C   rn   rw   )r   rD   re   r   rl   rK   r/   r/   r0   structured_crewC  ry   zUserJourney.structured_crewN)*__name__
__module____qualname____doc__r1   r9   rI   r   r   r4   r;   r=   r>   r?   r@   rA   rB   rC   rD   r   rE   rM   strrW   r\   r]   r^   r`   rc   rd   re   rm   ro   r   rs   rv   rx   rz   r|   r~   r   r   r/   r/   r/   r0   r      sZ    	r   )!crewair   r   r   r   crewai.projectr   r   r   r	   r
    user_journey_service.core.configr   ,user_journey_service.processors.guardrail_fnr   r   typingr   r   r   reos	functoolsr   crewai_toolsr   dotenvr   crewai.toolsr   &user_journey_service.tools.custom_toolr   r   r/   r/   r/   r0   <module>   s"    