Let’s create a simple crew that will help us research and report on the latest AI developments for a given topic or subject.
Before we proceed, make sure you have crewai and crewai-tools installed.
If you haven’t installed them yet, you can do so by following the installation guide.
Follow the steps below to get crewing! 🚣♂️
1
Create your crew
Create a new crew project by running the following command in your terminal.
This will create a new directory called latest-ai-development with the basic structure for your crew.
crewai create crew latest-ai-development
2
Modify your `agents.yaml` file
You can also modify the agents as needed to fit your use case or copy and paste as is to your project.
Any variable interpolated in your agents.yaml and tasks.yaml files like {topic} will be replaced by the value of the variable in the main.py file.
agents.yaml
# src/latest_ai_development/config/agents.yamlresearcher:role:>{topic} Senior Data Researchergoal:> Uncover cutting-edge developments in {topic}backstory:> You're a seasoned researcher with a knack for uncovering the latest developments in {topic}. Known for your ability to find the most relevant information and present it in a clear and concise manner.reporting_analyst:role:>{topic} Reporting Analystgoal:> Create detailed reports based on {topic} data analysis and research findingsbackstory:> You're a meticulous analyst with a keen eye for detail. You're known for your ability to turn complex data into clear and concise reports, making it easy for others to understand and act on the information you provide.
3
Modify your `tasks.yaml` file
tasks.yaml
# src/latest_ai_development/config/tasks.yamlresearch_task:description:> Conduct a thorough research about {topic} Make sure you find any interesting and relevant information given the current year is 2025.expected_output:> A list with 10 bullet points of the most relevant information about {topic}agent: researcherreporting_task:description:> Review the context you got and expand each topic into a full section for a report. Make sure the report is detailed and contains any and all relevant information.expected_output:> A fully fledge reports with the mains topics, each with a full section of information. Formatted as markdown without '```'agent: reporting_analystoutput_file: report.md
4
Modify your `crew.py` file
crew.py
# src/latest_ai_development/crew.pyfrom crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, taskfrom crewai_tools import SerperDevTool@CrewBaseclassLatestAiDevelopmentCrew():"""LatestAiDevelopment crew"""@agentdefresearcher(self)-> Agent:return Agent( config=self.agents_config['researcher'], verbose=True, tools=[SerperDevTool()])@agentdefreporting_analyst(self)-> Agent:return Agent( config=self.agents_config['reporting_analyst'], verbose=True)@taskdefresearch_task(self)-> Task:return Task( config=self.tasks_config['research_task'],)@taskdefreporting_task(self)-> Task:return Task( config=self.tasks_config['reporting_task'], output_file='output/report.md'# This is the file that will be contain the final report.)@crewdefcrew(self)-> Crew:"""Creates the LatestAiDevelopment 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=True,)
5
[Optional] Add before and after crew functions
crew.py
# src/latest_ai_development/crew.pyfrom crewai import Agent, Crew, Process, Taskfrom crewai.project import CrewBase, agent, crew, task, before_kickoff, after_kickofffrom crewai_tools import SerperDevTool@CrewBaseclassLatestAiDevelopmentCrew():"""LatestAiDevelopment crew"""@before_kickoffdefbefore_kickoff_function(self, inputs):print(f"Before kickoff function with inputs: {inputs}")return inputs # You can return the inputs or modify them as needed@after_kickoffdefafter_kickoff_function(self, result):print(f"After kickoff function with result: {result}")return result # You can return the result or modify it as needed# ... remaining code
6
Feel free to pass custom inputs to your crew
For example, you can pass the topic input to your crew to customize the research and reporting.
main.py
#!/usr/bin/env python# src/latest_ai_development/main.pyimport sysfrom latest_ai_development.crew import LatestAiDevelopmentCrewdefrun():""" Run the crew.""" inputs ={'topic':'AI Agents'} LatestAiDevelopmentCrew().crew().kickoff(inputs=inputs)
7
Set your environment variables
Before running your crew, make sure you have the following keys set as environment variables in your .env file:
An OpenAI API key (or other LLM API key): OPENAI_API_KEY=sk-...
A Serper.dev API key: SERPER_API_KEY=YOUR_KEY_HERE
8
Lock and install the dependencies
Lock the dependencies and install them by using the CLI command but first, navigate to your project directory:
cd latest-ai-developmentcrewai install
9
Run your crew
To run your crew, execute the following command in the root of your project:
crewai run
10
View your final report
You should see the output in the console and the report.md file should be created in the root of your project with the final report.
Here’s an example of what the report should look like:
# Comprehensive Report on the Rise and Impact of AI Agents in 2025## 1. Introduction to AI AgentsIn 2025, Artificial Intelligence (AI) agents are at the forefront of innovation across various industries. As intelligent systems that can perform tasks typically requiring human cognition, AI agents are paving the way for significant advancements in operational efficiency, decision-making, and overall productivity within sectors like Human Resources (HR) and Finance. This report aims to detail the rise of AI agents, their frameworks, applications, and potential implications on the workforce.## 2. Benefits of AI AgentsAI agents bring numerous advantages that are transforming traditional work environments. Key benefits include:-**Task Automation**: AI agents can carry out repetitive tasks such as data entry, scheduling, and payroll processing without human intervention, greatly reducing the time and resources spent on these activities.-**Improved Efficiency**: By quickly processing large datasets and performing analyses that would take humans significantly longer, AI agents enhance operational efficiency. This allows teams to focus on strategic tasks that require higher-level thinking.-**Enhanced Decision-Making**: AI agents can analyze trends and patterns in data, provide insights, and even suggest actions, helping stakeholders make informed decisions based on factual data rather than intuition alone.## 3. Popular AI Agent FrameworksSeveral frameworks have emerged to facilitate the development of AI agents, each with its own unique features and capabilities. Some of the most popular frameworks include:-**Autogen**: A framework designed to streamline the development of AI agents through automation of code generation.-**Semantic Kernel**: Focuses on natural language processing and understanding, enabling agents to comprehend user intentions better.-**Promptflow**: Provides tools for developers to create conversational agents that can navigate complex interactions seamlessly.-**Langchain**: Specializes in leveraging various APIs to ensure agents can access and utilize external data effectively.-**CrewAI**: Aimed at collaborative environments, CrewAI strengthens teamwork by facilitating communication through AI-driven insights.-**MemGPT**: Combines memory-optimized architectures with generative capabilities, allowing for more personalized interactions with users.These frameworks empower developers to build versatile and intelligent agents that can engage users, perform advanced analytics, and execute various tasks aligned with organizational goals.## 4. AI Agents in Human ResourcesAI agents are revolutionizing HR practices by automating and optimizing key functions:-**Recruiting**: AI agents can screen resumes, schedule interviews, and even conduct initial assessments, thus accelerating the hiring process while minimizing biases.-**Succession Planning**: AI systems analyze employee performance data and potential, helping organizations identify future leaders and plan appropriate training.-**Employee Engagement**: Chatbots powered by AI can facilitate feedback loops between employees and management, promoting an open culture and addressing concerns promptly.As AI continues to evolve, HR departments leveraging these agents can realize substantial improvements in both efficiency and employee satisfaction.## 5. AI Agents in FinanceThe finance sector is seeing extensive integration of AI agents that enhance financial practices:-**Expense Tracking**: Automated systems manage and monitor expenses, flagging anomalies and offering recommendations based on spending patterns.-**Risk Assessment**: AI models assess credit risk and uncover potential fraud by analyzing transaction data and behavioral patterns.-**Investment Decisions**: AI agents provide stock predictions and analytics based on historical data and current market conditions, empowering investors with informative insights.The incorporation of AI agents into finance is fostering a more responsive and risk-aware financial landscape.## 6. Market Trends and InvestmentsThe growth of AI agents has attracted significant investment, especially amidst the rising popularity of chatbots and generative AI technologies. Companies and entrepreneurs are eager to explore the potential of these systems, recognizing their ability to streamline operations and improve customer engagement.Conversely, corporations like Microsoft are taking strides to integrate AI agents into their product offerings, with enhancements to their Copilot 365 applications. This strategic move emphasizes the importance of AI literacy in the modern workplace and indicates the stabilizing of AI agents as essential business tools.## 7. Future Predictions and ImplicationsExperts predict that AI agents will transform essential aspects of work life. As we look toward the future, several anticipated changes include:- Enhanced integration of AI agents across all business functions, creating interconnected systems that leverage data from various departmental silos for comprehensive decision-making.- Continued advancement of AI technologies, resulting in smarter, more adaptable agents capable of learning and evolving from user interactions.- Increased regulatory scrutiny to ensure ethical use, especially concerning data privacy and employee surveillance as AI agents become more prevalent.To stay competitive and harness the full potential of AI agents, organizations must remain vigilant about latest developments in AI technology and consider continuous learning and adaptation in their strategic planning.## 8. ConclusionThe emergence of AI agents is undeniably reshaping the workplace landscape in 5. With their ability to automate tasks, enhance efficiency, and improve decision-making, AI agents are critical in driving operational success. Organizations must embrace and adapt to AI developments to thrive in an increasingly digital business environment.
The names you use in your YAML files (agents.yaml and tasks.yaml) should match the method names in your Python code.
For example, you can reference the agent for specific tasks from tasks.yaml file.
This naming consistency allows CrewAI to automatically link your configurations with your code; otherwise, your task won’t recognize the reference properly.
Note how we use the same name for the agent in the agents.yaml (email_summarizer) file as the method name in the crew.py (email_summarizer) file.
agents.yaml
email_summarizer:role:> Email Summarizergoal:> Summarize emails into a concise and clear summarybackstory:> You will create a 5 bullet point summary of the reportllm: openai/gpt-4o
Note how we use the same name for the agent in the tasks.yaml (email_summarizer_task) file as the method name in the crew.py (email_summarizer_task) file.
tasks.yaml
email_summarizer_task:description:> Summarize the email into a 5 bullet point summaryexpected_output:> A 5 bullet point summary of the emailagent: email_summarizer context:- reporting_task- research_task
Use the annotations to properly reference the agent and task in the crew.py file.
Used to define an agent in your crew. Use this when:
You need to create a specialized AI agent with a specific role
You want the agent to be automatically collected and managed by the crew
You need to reuse the same agent configuration across multiple tasks
@agentdefresearch_agent(self)-> Agent:return Agent( role="Research Analyst", goal="Conduct thorough research on given topics", backstory="Expert researcher with years of experience in data analysis", tools=[SerperDevTool()], verbose=True)
Used to define a task that can be executed by agents. Use this when:
You need to define a specific piece of work for an agent
You want tasks to be automatically sequenced and managed
You need to establish dependencies between different tasks
@taskdefresearch_task(self)-> Task:return Task( description="Research the latest developments in AI technology", expected_output="A comprehensive report on AI advancements", agent=self.research_agent(), output_file="output/research.md")
Used to create custom tools for your agents. Use this when:
You need to give agents specific capabilities (like web search, data analysis)
You want to encapsulate external API calls or complex operations
You need to share functionality across multiple agents
@tooldefweb_search_tool(query:str, max_results:int=5)->list[str]:""" Search the web for information. Args: query: The search query max_results: Maximum number of results to return Returns: List of search results"""# Implement your search logic herereturn[f"Result {i} for: {query}"for i inrange(max_results)]
Used to process results after the crew completes. Use this when:
You need to format or transform the final output
You want to perform cleanup operations
You need to save or log the results in a specific way
@after_kickoffdefprocess_results(self, result: CrewOutput)-> CrewOutput:"""Process and format the results after the crew completes.""" result.raw = result.raw.strip() result.raw =f"""# Research Results Generated on:{datetime.now().isoformat()}{result.raw}"""return result
Used to implement custom caching for task results. Use this when:
You want to avoid redundant expensive operations
You need to implement custom cache storage or expiration logic
You want to persist results between runs
@cache_handlerdefcustom_cache(self, key:str)-> Optional[str]:"""Custom cache implementation for storing task results.""" cache_file =f"cache/{key}.json"if os.path.exists(cache_file):withopen(cache_file,'r')as f: data = json.load(f)# Check if cache is still valid (e.g., not expired)if datetime.fromisoformat(data['timestamp'])> datetime.now()- timedelta(days=1):return data['result']returnNone
These decorators are part of the CrewAI framework and help organize your crew’s structure by automatically collecting agents, tasks, and handling various lifecycle events.
They should be used within a class decorated with @CrewBase.