├── agents.py ├── main.py ├── pyproject.toml ├── streamlit_app.py └── tasks.py /agents.py: -------------------------------------------------------------------------------- 1 | from crewai import Agent 2 | from langchain_openai import ChatOpenAI 3 | from crewai_tools import SerperDevTool, WebsiteSearchTool,YoutubeChannelSearchTool, TXTSearchTool 4 | 5 | 6 | 7 | 8 | class ResearchCrewAgents: 9 | 10 | def __init__(self): 11 | # Initialize tools if needed 12 | self.serper = SerperDevTool() 13 | self.web = WebsiteSearchTool() 14 | self.txt_tool = TXTSearchTool() 15 | self.gpt3 = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.7) 16 | self.gpt4 = ChatOpenAI(model_name="gpt-4", temperature=0.7) 17 | 18 | def researcher(self): 19 | # Detailed agent setup for the Researcher 20 | return Agent( 21 | role='Research Expert', 22 | goal='Systematically scour sources to gather current news and articles on diverse topics.', 23 | backstory="You are a paragon of meticulousness and analytical prowess, with a PhD in information science and over a decade of experience in high-stakes research roles, from academic institutions to top-tier consultancy firms. Known for your relentless pursuit of accuracy and depth, you have an uncanny ability to unearth gems of information that others might overlook. Your work is the bedrock upon which complex decisions and analyses are built, making you an indispensable cornerstone of any knowledge-driven team.", 24 | verbose=True, 25 | allow_delegation=False, 26 | tools=[self.web], 27 | llm=self.gpt3, 28 | ) 29 | 30 | def analyst(self): 31 | # Detailed agent setup for the Analyst 32 | return Agent( 33 | role='Data Analysis Specialist', 34 | goal='Evaluate and enhance the information collected to ensure accuracy and relevance.', 35 | backstory="With a formidable background in data science and a sharp, inquisitive mind, you stand out as a master of data interrogation and synthesis. Your career spans over fifteen years, involving roles in government intelligence and corporate strategy, where you've turned ambiguous data into clear, actionable insights. Your analytical reports are often cited as the gold standard in your field, and your capacity to dissect complex datasets is nothing short of legendary.", 36 | tools=[self.serper], 37 | verbose=True, 38 | allow_delegation=False, 39 | llm=self.gpt3, 40 | ) 41 | 42 | def writer(self): 43 | # Detailed agent setup for the Writer 44 | return Agent( 45 | role='Master Storyteller and Technical Writer', 46 | goal='Integrate and articulate insights into a compelling narrative with precise citations.', 47 | backstory="As a celebrated author and journalist with over twenty years of experience crafting stories that captivate and inform, you possess a unique flair for making intricate information accessible and engaging. Your writing has graced the pages of major publications and influential blogs, where your ability to elucidate complex concepts in an engaging manner has won you numerous accolades. In this role, you are the final architect, molding the raw analytical content into a final piece that is not only informative but also profoundly impactful.", 48 | tools=[self.txt_tool], 49 | verbose=True, 50 | allow_delegation=False, 51 | llm=self.gpt3, 52 | ) -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | from decouple import config 3 | from crewai import Crew, Process 4 | from textwrap import dedent 5 | from agents import ResearchCrewAgents 6 | from tasks import ResearchCrewTasks 7 | 8 | # Set up environment variables 9 | os.environ["OPENAI_API_KEY"] = "YOU API KEY HERE" 10 | os.environ["SERPER_API_KEY"] = "YOUR API KEY HERE" 11 | class ResearchCrew: 12 | def __init__(self, inputs): 13 | self.inputs = inputs 14 | self.agents = ResearchCrewAgents() 15 | self.tasks = ResearchCrewTasks() 16 | 17 | def run(self): 18 | # Initialize agents 19 | researcher = self.agents.researcher() 20 | analyst = self.agents.analyst() 21 | writer = self.agents.writer() 22 | 23 | # Initialize tasks with respective agents 24 | research_task = self.tasks.research_task(researcher, self.inputs) 25 | analysis_task = self.tasks.analysis_task(analyst, [research_task]) 26 | writing_task = self.tasks.writing_task(writer, [analysis_task]) 27 | 28 | # Form the crew with defined agents and tasks 29 | crew = Crew( 30 | agents=[researcher, analyst, writer], 31 | tasks=[research_task, analysis_task, writing_task], 32 | process=Process.sequential 33 | ) 34 | 35 | # Execute the crew to carry out the research project 36 | return crew.kickoff() 37 | 38 | if __name__ == "__main__": 39 | print("Welcome to the Research Crew Setup") 40 | print("---------------------------------------") 41 | topic = input("Please enter the main topic of your research: ") 42 | detailed_questions = input("What specific questions or subtopics are you interested in exploring? ") 43 | key_points = input("Are there any key points or specific information you need to be included in the research? ") 44 | 45 | inputs = f"Research Topic: {topic}\nDetailed Questions: {detailed_questions}\nKey Points: {key_points}" 46 | research_crew = ResearchCrew(inputs) 47 | result = research_crew.run() 48 | 49 | print("\n\n##############################") 50 | print("## Here are the results of your research project:") 51 | print("##############################\n") 52 | print(result) 53 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "crewai" 3 | version = "0.28.8" 4 | description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks." 5 | authors = ["Joao Moura "] 6 | readme = "README.md" 7 | packages = [ 8 | { include = "crewai", from = "src" }, 9 | ] 10 | 11 | [tool.poetry.urls] 12 | Homepage = "https://crewai.com" 13 | Documentation = "https://github.com/joaomdmoura/CrewAI/wiki/Index" 14 | Repository = "https://github.com/joaomdmoura/crewai" 15 | 16 | [tool.poetry.dependencies] 17 | python = ">=3.10,<=3.13" 18 | pydantic = "^2.4.2" 19 | langchain = "^0.1.10" 20 | openai = "^1.13.3" 21 | opentelemetry-api = "^1.22.0" 22 | opentelemetry-sdk = "^1.22.0" 23 | opentelemetry-exporter-otlp-proto-http = "^1.22.0" 24 | instructor = "^0.5.2" 25 | regex = "^2023.12.25" 26 | crewai-tools = { version = "^0.1.7", optional = true } 27 | click = "^8.1.7" 28 | python-dotenv = "1.0.0" 29 | embedchain = "^0.1.98" 30 | appdirs = "^1.4.4" 31 | 32 | [tool.poetry.extras] 33 | tools = ["crewai-tools"] 34 | 35 | [tool.poetry.group.dev.dependencies] 36 | isort = "^5.13.2" 37 | pyright = ">=1.1.350,<2.0.0" 38 | autoflake = "^2.2.1" 39 | pre-commit = "^3.6.0" 40 | mkdocs = "^1.4.3" 41 | mkdocstrings = "^0.22.0" 42 | mkdocstrings-python = "^1.1.2" 43 | mkdocs-material = {extras = ["imaging"], version = "^9.5.7"} 44 | mkdocs-material-extensions = "^1.3.1" 45 | pillow = "^10.2.0" 46 | cairosvg = "^2.7.1" 47 | crewai-tools = "^0.1.7" 48 | 49 | [tool.isort] 50 | profile = "black" 51 | known_first_party = ["crewai"] 52 | 53 | 54 | [tool.poetry.group.test.dependencies] 55 | pytest = "^8.0.0" 56 | pytest-vcr = "^1.0.2" 57 | python-dotenv = "1.0.0" 58 | 59 | [tool.poetry.scripts] 60 | crewai = "crewai.cli.cli:crewai" 61 | 62 | [build-system] 63 | requires = ["poetry-core"] 64 | build-backend = "poetry.core.masonry.api" -------------------------------------------------------------------------------- /streamlit_app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | from main import ResearchCrew # Import the ResearchCrew class from main.py 3 | import os 4 | 5 | st.title('Research Crew Setup') 6 | os.environ["OPENAI_API_KEY"] = "YOU API KEY HERE" 7 | os.environ["SERPER_API_KEY"] = "YOU API KEY HERE" 8 | 9 | with st.sidebar: 10 | st.header('Enter Research Details') 11 | topic = st.text_input("Main topic of your research:") 12 | detailed_questions = st.text_area("Specific questions or subtopics you are interested in exploring:") 13 | key_points = st.text_area("Key points or specific information needed:") 14 | 15 | if st.button('Run Research'): 16 | if not topic or not detailed_questions or not key_points: 17 | st.error("Please fill all the fields.") 18 | else: 19 | inputs = f"Research Topic: {topic}\nDetailed Questions: {detailed_questions}\nKey Points: {key_points}" 20 | research_crew = ResearchCrew(inputs) 21 | result = research_crew.run() 22 | st.subheader("Results of your research project:") 23 | st.write(result) 24 | -------------------------------------------------------------------------------- /tasks.py: -------------------------------------------------------------------------------- 1 | from crewai import Task 2 | 3 | from crewai import Task 4 | 5 | class ResearchCrewTasks: 6 | 7 | def research_task(self, agent, inputs): 8 | return Task( 9 | agent=agent, 10 | description=f"Systematically gather and document current and relevant news and articles from diverse sources about {inputs}. Use all available digital tools to ensure comprehensive coverage.", 11 | expected_output=f""" 12 | Detailed Research Report on {inputs} 13 | 1. **Executive Summary**: A concise overview of the research findings, highlighting the most critical insights and conclusions drawn from the gathered data. 14 | 2. **Introduction**: Background information on why the research on {inputs} is crucial at this point in time. Include the scope of the research and the main objectives. 15 | 3. **Methodology**: 16 | - **Sources Used**: List all sources utilized, including digital databases, news websites, and any subscriptions or specialized tools. 17 | - **Search Criteria**: Describe the search criteria and keywords used to gather the relevant information. 18 | - **Data Collection Process**: Outline the steps taken in the data collection process, including any automation tools or software used. 19 | 4. **Findings**: 20 | - **Key Information Gathered**: Summarize the key information gathered from each source, categorized by relevance and impact on the topic. 21 | - **Themes Identified**: Discuss any recurring themes or commonalities found across different sources. 22 | 5. **Analysis**: 23 | - **Relevance to Current Trends**: Analyze how the findings relate to current trends or developments in the field. 24 | - **Gaps in Information**: Highlight any noticeable gaps in information that could require further research. 25 | 6. **Conclusion**: 26 | - **Summary of Findings**: Briefly reiterate the most critical findings and their implications. 27 | - **Recommendations for Further Research**: Suggest areas where additional investigation could be beneficial based on gaps or emerging trends noted during the research. 28 | 7. **References**: 29 | - **Full Citations**: Provide full citations for all sources used, formatted according to a recognized academic standard. 30 | """ 31 | ) 32 | 33 | 34 | def analysis_task(self, agent, context): 35 | return Task( 36 | agent=agent, 37 | context=context, 38 | description="Critically assess the accuracy, relevance, and depth of the information collected. Employ advanced data analysis methodologies to enhance the information's value, ensuring it meets the high standards required for expert assessment.", 39 | expected_output=f""" 40 | Comprehensive Analysis Report: 41 | 1. **Executive Summary**: An overview summarizing the key findings, including the accuracy, relevance, and depth of the analyzed information. 42 | 2. **Accuracy Assessment**: 43 | - **Data Verification**: Evaluate the truthfulness and correctness of the data collected, identifying any discrepancies or inconsistencies. 44 | - **Source Reliability**: Assess the reliability of the sources used, providing a credibility score for each. 45 | 3. **Relevance Analysis**: 46 | - **Contextual Alignment**: Analyze how the information aligns with the current research questions and objectives. 47 | - **Currentness**: Verify that the information is up-to-date and discuss its significance in the current context. 48 | 4. **Depth Evaluation**: 49 | - **Comprehensiveness**: Evaluate the scope of the information and whether it covers all necessary aspects of the topic. 50 | - **Insightfulness**: Assess the depth of insights provided by the information, including any underlying implications or hidden patterns. 51 | 5. **Methodological Review**: 52 | - **Techniques Used**: Outline and critique the data analysis methodologies employed, suggesting improvements or alternatives if necessary. 53 | - **Data Handling**: Discuss how the data was processed and analyzed, including any tools or software utilized. 54 | 6. **Recommendations**: 55 | - **Further Research**: Suggest areas where additional information is needed and propose methods for gathering this data. 56 | - **Practical Applications**: Provide recommendations on how the findings can be utilized practically by stakeholders or in further research. 57 | 7. **Conclusion**: 58 | - **Summary of Key Points**: Concisely reiterate the most important findings and their implications for the research project. 59 | - **Future Directions**: Suggest how the findings can inform future research and decision-making processes in the relevant field. 60 | 8. **Appendices**: 61 | - **Data Tables and Figures**: Include comprehensive tables, charts, and graphs that were used in the analysis. 62 | - **Source Documentation**: Provide detailed citations and references for all sources and data used in the report. 63 | """ 64 | ) 65 | 66 | 67 | def writing_task(self, agent, context): 68 | return Task( 69 | agent=agent, 70 | context=context, 71 | description="Synthesize the information provided by the Researcher and enhanced by the Analyst into a compelling, clear, and well-structured summary. Include key findings and appropriately cite all sources to ensure credibility and traceability.", 72 | expected_output=f""" 73 | Comprehensive Summary Report: 74 | 1. **Introduction**: 75 | - **Background**: Provide a brief introduction to the topic, outlining the scope and purpose of the initial research. 76 | - **Objectives**: Recap the main objectives of the research to set the context for the findings. 77 | 78 | 2. **Synthesis of Research and Analysis**: 79 | - **Key Findings**: Present the key findings from the research phase, emphasizing significant data points, trends, and insights. 80 | - **Analytical Enhancements**: Discuss how the analysis phase added value to the initial findings, including any new insights or understandings derived from deeper examination. 81 | 82 | 3. **Discussion**: 83 | - **Implications**: Explore the implications of the findings in a broader context, discussing potential impacts on the field, industry, or society. 84 | - **Critical Evaluation**: Critically evaluate the findings, noting strengths, weaknesses, and any contentious points that emerged during the research and analysis phases. 85 | 86 | 4. **Recommendations**: 87 | - **Actionable Steps**: Provide clear, actionable recommendations based on the findings and discussions. These should be practical and tailored to specific stakeholders or policy implications. 88 | - **Future Research**: Suggest areas for future research that could build on the current findings, addressing any gaps or unresolved questions. 89 | 90 | 5. **Conclusion**: 91 | - **Summary of Findings**: Summarize the main points of the report, reinforcing the significance and reliability of the research conducted. 92 | - **Final Thoughts**: Offer concluding thoughts that underscore the importance of the findings and the potential for future work in this area. 93 | 94 | 6. **References**: 95 | - **Citations**: Include a detailed list of all sources cited in the document, formatted according to a recognized academic or professional standard. 96 | - **Source Annotations**: Optionally, provide annotations for key sources, explaining their relevance and reliability. 97 | 98 | 7. **Appendices** (if applicable): 99 | - **Supporting Documents**: Attach any supporting documents, data tables, or supplementary material referenced in the report. 100 | - **Glossary of Terms**: Include a glossary of key terms and definitions used throughout the report for clarity. 101 | """ 102 | ) 103 | 104 | 105 | 106 | 107 | --------------------------------------------------------------------------------