Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Crew example #303

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 239 additions & 0 deletions examples/crew/job_posting.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install -U agentops\n",
"%pip install -U 'crewai[agentops]'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ[\"SERPER_API_KEY\"] = \"YOUR_SERPER_API_KEY\"\n",
"os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY\"\n",
"os.environ[\"AGENTOPS_API_KEY\"] = \"YOUR_AGENTOPS_API_KEY\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from crewai import Agent\n",
"from crewai_tools.tools import WebsiteSearchTool, SeperDevTool, FileReadTool\n",
"\n",
"web_search_tool = WebsiteSearchTool()\n",
"seper_dev_tool = SeperDevTool()\n",
"file_read_tool = FileReadTool(\n",
" file_path=\"job_description_example.md\",\n",
" description=\"A tool to read the job description example file.\",\n",
")\n",
"\n",
"class Agents:\n",
" def research_agent(self):\n",
" return Agent(\n",
" role=\"Research Analyst\",\n",
" goal=\"Analyze the company website and provided description to extract insights on culture, values, and specific needs.\",\n",
" tools=[web_search_tool, seper_dev_tool],\n",
" backstory=\"Expert in analyzing company cultures and identifying key values and needs from various sources, including websites and brief descriptions.\",\n",
" verbose=True,\n",
" )\n",
"\n",
" def writer_agent(self):\n",
" return Agent(\n",
" role=\"Job Description Writer\",\n",
" goal=\"Use insights from the Research Analyst to create a detailed, engaging, and enticing job posting.\",\n",
" tools=[web_search_tool, seper_dev_tool, file_read_tool],\n",
" backstory=\"Skilled in crafting compelling job descriptions that resonate with the company's values and attract the right candidates.\",\n",
" verbose=True,\n",
" )\n",
"\n",
" def review_agent(self):\n",
" return Agent(\n",
" role=\"Review and Editing Specialist\",\n",
" goal=\"Review the job posting for clarity, engagement, grammatical accuracy, and alignment with company values and refine it to ensure perfection.\",\n",
" tools=[web_search_tool, seper_dev_tool, file_read_tool],\n",
" backstory=\"A meticulous editor with an eye for detail, ensuring every piece of content is clear, engaging, and grammatically perfect.\",\n",
" verbose=True,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from textwrap import dedent\n",
"from crewai import Task\n",
"\n",
"class Tasks:\n",
" def research_company_culture_task(self, agent, company_description, company_domain):\n",
" return Task(\n",
" description=dedent(\n",
" f\"\"\"\\\n",
"\t\t\t\t\t\t\t\tAnalyze the provided company website and the hiring manager's company's domain {company_domain}, description: \"{company_description}\". Focus on understanding the company's culture, values, and mission. Identify unique selling points and specific projects or achievements highlighted on the site.\n",
"\t\t\t\t\t\t\t\tCompile a report summarizing these insights, specifically how they can be leveraged in a job posting to attract the right candidates.\"\"\"\n",
" ),\n",
" expected_output=dedent(\n",
" \"\"\"\\\n",
"\t\t\t\t\t\t\t\tA comprehensive report detailing the company's culture, values, and mission, along with specific selling points relevant to the job role. Suggestions on incorporating these insights into the job posting should be included.\"\"\"\n",
" ),\n",
" agent=agent,\n",
" )\n",
"\n",
" def research_role_requirements_task(self, agent, hiring_needs):\n",
" return Task(\n",
" description=dedent(\n",
" f\"\"\"\\\n",
"\t\t\t\t\t\t\t\tBased on the hiring manager's needs: \"{hiring_needs}\", identify the key skills, experiences, and qualities the ideal candidate should possess for the role. Consider the company's current projects, its competitive landscape, and industry trends. Prepare a list of recommended job requirements and qualifications that align with the company's needs and values.\"\"\"\n",
" ),\n",
" expected_output=dedent(\n",
" \"\"\"\\\n",
"\t\t\t\t\t\t\t\tA list of recommended skills, experiences, and qualities for the ideal candidate, aligned with the company's culture, ongoing projects, and the specific role's requirements.\"\"\"\n",
" ),\n",
" agent=agent,\n",
" )\n",
"\n",
" def draft_job_posting_task(\n",
" self, agent, company_description, hiring_needs, specific_benefits\n",
" ):\n",
" return Task(\n",
" description=dedent(\n",
" f\"\"\"\\\n",
"\t\t\t\t\t\t\t\tDraft a job posting for the role described by the hiring manager: \"{hiring_needs}\". Use the insights on \"{company_description}\" to start with a compelling introduction, followed by a detailed role description, responsibilities, and required skills and qualifications. Ensure the tone aligns with the company's culture and incorporate any unique benefits or opportunities offered by the company.\n",
"\t\t\t\t\t\t\t\tSpecfic benefits: \"{specific_benefits}\"\"\"\n",
" ),\n",
" expected_output=dedent(\n",
" \"\"\"\\\n",
"\t\t\t\t\t\t\t\tA detailed, engaging job posting that includes an introduction, role description, responsibilities, requirements, and unique company benefits. The tone should resonate with the company's culture and values, aimed at attracting the right candidates.\"\"\"\n",
" ),\n",
" agent=agent,\n",
" )\n",
"\n",
" def review_and_edit_job_posting_task(self, agent, hiring_needs):\n",
" return Task(\n",
" description=dedent(\n",
" f\"\"\"\\\n",
"\t\t\t\t\t\t\t\tReview the draft job posting for the role: \"{hiring_needs}\". Check for clarity, engagement, grammatical accuracy, and alignment with the company's culture and values. Edit and refine the content, ensuring it speaks directly to the desired candidates and accurately reflects the role's unique benefits and opportunities. Provide feedback for any necessary revisions.\"\"\"\n",
" ),\n",
" expected_output=dedent(\n",
" \"\"\"\\\n",
"\t\t\t\t\t\t\t\tA polished, error-free job posting that is clear, engaging, and perfectly aligned with the company's culture and values. Feedback on potential improvements and final approval for publishing. Formated in markdown.\"\"\"\n",
" ),\n",
" agent=agent,\n",
" output_file=\"job_posting.md\",\n",
" )\n",
"\n",
" def industry_analysis_task(self, agent, company_domain, company_description):\n",
" return Task(\n",
" description=dedent(\n",
" f\"\"\"\\\n",
"\t\t\t\t\t\t\t\tConduct an in-depth analysis of the industry related to the company's domain: \"{company_domain}\". Investigate current trends, challenges, and opportunities within the industry, utilizing market reports, recent developments, and expert opinions. Assess how these factors could impact the role being hired for and the overall attractiveness of the position to potential candidates.\n",
"\t\t\t\t\t\t\t\tConsider how the company's position within this industry and its response to these trends could be leveraged to attract top talent. Include in your report how the role contributes to addressing industry challenges or seizing opportunities.\"\"\"\n",
" ),\n",
" expected_output=dedent(\n",
" \"\"\"\\\n",
"\t\t\t\t\t\t\t\tA detailed analysis report that identifies major industry trends, challenges, and opportunities relevant to the company's domain and the specific job role. This report should provide strategic insights on positioning the job role and the company as an attractive choice for potential candidates.\"\"\"\n",
" ),\n",
" agent=agent,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from crewai import Crew\n",
"\n",
"import agentops\n",
"\n",
"agentops.init(tags=[\"crew-job-posting-example\"])\n",
"\n",
"tasks = Tasks()\n",
"agents = Agents()\n",
"\n",
"company_description = input(\"What is the company description?\\n\")\n",
"company_domain = input(\"What is the company domain?\\n\")\n",
"hiring_needs = input(\"What are the hiring needs?\\n\")\n",
"specific_benefits = input(\"What are specific_benefits you offer?\\n\")\n",
"\n",
"# Create Agents\n",
"researcher_agent = agents.research_agent()\n",
"writer_agent = agents.writer_agent()\n",
"review_agent = agents.review_agent()\n",
"\n",
"# Define Tasks for each agent\n",
"research_company_culture_task = tasks.research_company_culture_task(\n",
" researcher_agent, company_description, company_domain\n",
")\n",
"industry_analysis_task = tasks.industry_analysis_task(\n",
" researcher_agent, company_domain, company_description\n",
")\n",
"research_role_requirements_task = tasks.research_role_requirements_task(\n",
" researcher_agent, hiring_needs\n",
")\n",
"draft_job_posting_task = tasks.draft_job_posting_task(\n",
" writer_agent, company_description, hiring_needs, specific_benefits\n",
")\n",
"review_and_edit_job_posting_task = tasks.review_and_edit_job_posting_task(\n",
" review_agent, hiring_needs\n",
")\n",
"\n",
"# Instantiate the crew with a sequential process\n",
"crew = Crew(\n",
" agents=[researcher_agent, writer_agent, review_agent],\n",
" tasks=[\n",
" research_company_culture_task,\n",
" industry_analysis_task,\n",
" research_role_requirements_task,\n",
" draft_job_posting_task,\n",
" review_and_edit_job_posting_task,\n",
" ],\n",
")\n",
"\n",
"# Kick off the process\n",
"result = crew.kickoff()\n",
"\n",
"print(\"Job Posting Creation Process Completed.\")\n",
"print(\"Final Job Posting:\")\n",
"print(result)\n",
"\n",
"agentops.end_session(\"Success\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "env",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading