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

Add Preparing for an Interview example #82

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions prep-for-interview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
venv
.idea/
56 changes: 56 additions & 0 deletions prep-for-interview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Due Diligence Interview

By [@JosemyDuarte](https://github.com/JosemyDuarte)

## Description

Here you will find the implementation of a crew of AI agents that will investigate a company for you, helping you prepare for an interview. These agents will gather relevant information about the company and industry to provide you with valuable insights.

## Requirements

- Python 3.12 or higher
- pip
- [ollama](https://ollama.com/)
- +32GB of RAM (for the LLM model, can be reduced by using a smaller model)

## Installation

1. Clone the repository

2. Create a virtual environment
```bash
python -m venv venv
```

3. Activate the virtual environment
```bash
source venv/bin/activate
```

4. Install the dependencies
```bash
pip install -r requirements.txt
```

5. Download local LLM model. I'm using [this one](https://ollama.com/library/mixtral:8x7b-instruct-v0.1-q6_K)
```bash
ollama pull mixtral:8x7b-instruct-v0.1-q6_K
```

**Note**: You can also use a different LLM model for the agents. Just replace the model name used for the `llm` variable on the `main.py` file.

## Usage

1. Run the main script to start the investigation:

```bash
python main.py
```

2. Write the name of the company you are investigating

3. Review the generated reports and insights on the console.

Example report for **Twitter**

<img width="1783" alt="image" src="https://github.com/JosemyDuarte/DueDiligenceAI/assets/6247860/3037d8f8-50f4-43c7-8876-394c35e5254f">
57 changes: 57 additions & 0 deletions prep-for-interview/agents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from textwrap import dedent

from crewai import Agent
from langchain_community.llms.ollama import Ollama
from langchain_core.tools import Tool


def create_research_agent(llm: Ollama, tools: list[Tool]) -> Agent:
"""Create a Research Specialist agent."""
return Agent(
role='Research Specialist',
goal='Conduct thorough research on the company that is doing the interview.',
llm=llm,
tools=tools,
backstory=dedent(f"""\
As a Research Specialist, you know how to use an Internet Search Engine to find
information about the company you are investigating. You reflect on the information you find and decide if it is
relevant and enough to the task at hand or if you need to change your search direction.
"""),
allow_delegation=True,
verbose=True
)


def create_industry_analysis_agent(llm: Ollama, tools: list[Tool]) -> Agent:
"""Create an Industry Analyst agent."""
return Agent(
role='Industry Analyst',
goal='Conduct thorough research on the industry the company interviewing operates in.',
llm=llm,
tools=tools,
backstory=dedent(f"""\
As an Industry Analyst, you know how to use an Internet Search Engine to find
information about the industry the company operates in.
You know how to identify if the information you have about the industry is
relevant and enough to the task at hand or if you need to change your search direction.
"""),
allow_delegation=True,
verbose=True
)


def create_report_writer_agent(llm: Ollama, tools: list[Tool]) -> Agent:
"""Create an Insightful Writer agent."""
return Agent(
role='Insightful Writer',
goal='Write a well structured report about the company and the industry with all the information gathered including the sources.',
llm=llm,
tools=tools,
backstory=dedent(f"""\
As an Insightful Writer, you know how to write a well structured report, with clear sections and
all the information you have gathered about the company and the industry. You don't summarize anything,
just structure the information in a way that is easy to read and understand and include the sources.
"""),
allow_delegation=True,
verbose=True,
)
60 changes: 60 additions & 0 deletions prep-for-interview/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from textwrap import dedent

from crewai import Crew
from langchain_community.llms.ollama import Ollama
from langchain_community.tools import DuckDuckGoSearchRun
from langchain_core.tools import Tool

import agents
import tasks

if __name__ == "__main__":
print("## Welcome to the Interview Prep Crew")
print('-------------------------------')
company_name = input("What's the name of the company conducting the interview?\n")

# Tools
search_tool = Tool.from_function(
func=DuckDuckGoSearchRun().run,
name="Search",
description="Internet Search Engine useful for when you need to search the internet for information"
)

# LLM Model
llm = Ollama(model="mixtral:8x7b-instruct-v0.1-q6_K", temperature=0.2, num_ctx="8192")

# Agents
researcher_agent = agents.create_research_agent(llm, [search_tool])
industry_analyst_agent = agents.create_industry_analysis_agent(llm, [search_tool])
report_writer_agent = agents.create_report_writer_agent(llm, [])

# Tasks
suffix_prompt = dedent(f"""\
IMPORTANT: Don't forget to include all the URLs and titles to the sources from where you got the information.
You'll get a $1000 tip if you do your best work!""")
company_research_task = tasks.create_company_research_task(researcher_agent, company_name, suffix_prompt)
industry_research_task = tasks.create_industry_research_task(industry_analyst_agent, company_name, suffix_prompt)
write_report_task = tasks.create_write_report_task(report_writer_agent, suffix_prompt)

write_report_task.context = [company_research_task, industry_research_task]

report_crew = Crew(
agents=[
researcher_agent,
industry_analyst_agent,
report_writer_agent,
],
tasks=[
company_research_task,
industry_research_task,
write_report_task,
],
)

report = report_crew.kickoff()

print("\n\n################################################")
print("## Here is the report")
print("################################################\n")
print(report)
print("################################################\n")
3 changes: 3 additions & 0 deletions prep-for-interview/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
crewai==0.22.5
setuptools==69.2.0
duckduckgo_search==5.2.1
73 changes: 73 additions & 0 deletions prep-for-interview/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from textwrap import dedent

from crewai import Task


def create_company_research_task(agent, company_name, suffix_prompt=""):
"""Create a company research task."""
return Task(
description=dedent(f"""\
Conduct a thorough research on the company conducting the interview.
Gather information about its history, products, services, reputation,
culture, competitors, recent news and any relevant business activities.
Identify potential red flags that could be relevant to know before the interview.

Don't leave any stone unturned!

Company conducting the interview: {company_name}

{suffix_prompt}
"""),
expected_output=dedent("""\
A detailed report highlighting all the key findings about the company on each of the categories researched.
"""),
async_execution=True,
agent=agent
)


def create_industry_research_task(agent, company_name, suffix_prompt=""):
"""Task to research the industry of the company conducting the interview."""
return Task(
description=dedent(f"""\
Analyze the current industry trends, challenges, and opportunities
relevant to the company. Consider factors such as market growth,
competition, regulations, and technological advancements to provide a comprehensive
overview of the industry landscape.

Company Name: {company_name}

{suffix_prompt}
"""),
expected_output=dedent("""\
An insightful analysis that identifies major trends, potential challenges and strategic opportunities.
"""),
agent=agent
)


def create_write_report_task(agent, suffix_prompt=""):
"""Task to compile all the information into a single report."""
return Task(
description=dedent(f"""\
Compile all the information into one single report. Don't summarize anything,
just compile all the information you got about the company and the industry.
If you are missing information for any section, ask the respective agent to provide it.
"""),
expected_output=dedent(f"""\
A well structured document with a section for the company information and another for the industry.

For the company, include subsections such as Services, Reputation, Products, Culture,
Recent News, Competitors, Strengths and Weaknesses, and Potential Red Flags. Inside each subsection,
discuss the main points and provide examples, references or explanations where necessary.

For the industry, include subsections such as Trends, Challenges, and Opportunities.

Finalize with a section for Insightful Questions about the company and the industry
that could be asked during the interview to show interest and knowledge.
YOUR FINAL ANSWER MUST RETURN THE COMPLETE REPORT AND DETAILS, NOT JUST A SUMMARY.

{suffix_prompt}
"""),
agent=agent
)