File size: 2,741 Bytes
33253b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from tools.custom_tool import SearchAndContents, FindSimilar, GetContents
from langchain_groq import ChatGroq
from datetime import datetime
from langchain_core.agents import AgentFinish
import json
import os
import time
#os.environ['GROQ_API_KEY'] = os.getenv('GROQ_API')

@CrewBase
class NewsletterGenCrew:
    """NewsletterGen crew"""

    agents_config = "config/agents.yaml"
    tasks_config = "config/tasks.yaml"

    def llm(self):
        llm = ChatGroq(api_key=os.getenv("GROQ_API_KEY"), model="groq/llama-3.3-70b-versatile")
        #llm = LLM(api_key=os.getenv('GROQ_API_KEY'), model='groq/meta-llama/llama-4-scout-17b-16e-instruct')
        return llm

    @agent
    def researcher(self) -> Agent:
        return Agent(
            config=self.agents_config["researcher"],
            tools=[SearchAndContents()],
            verbose=False,
            allow_delegation=False,
            llm=self.llm()
            #step_callback=lambda step: self.step_callback(step, "Research Agent")
        )

    @agent
    def editor(self) -> Agent:
        return Agent(
            config=self.agents_config["editor"],
            verbose=False,
            allow_delegation=False,
            llm=self.llm()
            #step_callback=lambda step: self.step_callback(step, "Chief Editor")
        )

    @agent
    def designer(self) -> Agent:
        return Agent(
            config=self.agents_config["designer"],
            verbose=False,
            allow_delegation=False,
            llm=self.llm()
            #step_callback=lambda step: self.step_callback(step, "HTML Writer")
        )

    @task
    def research_task(self) -> Task:
        return Task(
            config=self.tasks_config["research_task"],
            agent=self.researcher()
        )
 
    @task
    def edit_task(self) -> Task:
        return Task(
            config=self.tasks_config["edit_task"],
            agent=self.editor()
        )

    @task
    def newsletter_task(self) -> Task:
    # Define the task
        return Task(
            config=self.tasks_config["newsletter_task"],
            agent=self.designer(),
            #output_file=output_file
        )
           
    @crew
    def crew(self) -> Crew:
        """Creates the NewsletterGen crew"""
        return Crew(
            agents=self.agents,  # Automatically created by the @agent decorator
            tasks=self.tasks,  # Automatically created by the @task decorator
            process=Process.sequential,
            verbose=False
            # process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
        )