Step By Step Guide to Build AI Based Job Application Assistant with Lyzr Agent API and Streamlit
In the ever-evolving job market, job seekers often struggle to tailor their applications to specific job descriptions effectively. Manual processes like analyzing job descriptions, creating cover letters, and matching CVs with job requirements can be time-consuming and prone to errors. To alleviate these challenges, we can leverage AI to create a Job Application Assistant. This assistant can automate various aspects of the job application process, allowing users to focus on securing the right job.
In this blog, we’ll explore how to build a Job Application Assistant using LyzrAgent and Streamlit. The assistant will guide users through the job application process by analyzing job descriptions, conducting company and SWOT analyses, and preparing application materials such as CVs, cover letters, and LinkedIn messages.
The traditional job application process involves several manual tasks:
- Company Research: Understanding the company’s location, sector, and financial health.
- SWOT Analysis: Identifying the strengths, weaknesses, opportunities, and threats associated with the job and the company.
- CV and Cover Letter Customization: Tailoring application materials to match the job description, which is often repetitive and time-consuming.
- Job Fit Analysis: Evaluating whether the job is a good fit based on various factors, including technical skills, experience, and cultural compatibility.
These tasks require considerable effort, especially for those applying to multiple positions. The Job Application Assistant aims to automate these tasks, providing a streamlined and efficient application process.
Code Walkthrough
1. Environment Setup
import os
from lyzr_agent import LyzrAgent
import streamlit as st
from dotenv import load_dotenv
from PIL import Image
# Load environment variables
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
LYZR_API_KEY = os.getenv("LYZR_API_KEY")
- Imports: The code imports necessary libraries, including
os
for environment variable management,lyzr_agent
for interacting with the Lyzr Agent API,streamlit
for creating the web app,dotenv
for loading environment variables, andPIL
for image handling. - Environment Variables: The
load_dotenv()
function loads the API keys from a.env
file, which are essential for authentication with the Lyzr and OpenAI APIs.
2. LyzrAgent Initialization
Agent = LyzrAgent(api_key=LYZR_API_KEY, llm_api_key=OPENAI_API_KEY)
- Agent Initialization: An instance of
LyzrAgent
is created, using the loaded API keys to authenticate with the Lyzr service.
3. Defining the System Prompt
prompt = """
You are an AI assistant trained to assist with job applications. Your task is to handle all aspects of the job application process when provided with a job description (JD). Follow the steps below:
Company Analysis:
-Identify the company's HQ location, sector, brief description.
-Provide insights into stock sentiment, employee satisfaction, and management quality.
-Compare the seniority of the current job profile to the user's profile.
Account Creation:
-Suggest an email and a randomly generated password for account creation.
SWOT Analysis:
-Conduct a SWOT analysis by assessing strengths, weaknesses, opportunities, and threats related to the job.
Match Analysis:
-Compare the job description with the user's CV.
-Evaluate the fit based on seniority level, industry experience, technical and soft skills.
-Consider company factors like profitability, ownership stability, size, gross margin, and IT spending.
-Consider language and cultural factors, including whether the company hires internationals.
-Provide a consolidated rating on the user's fit for the position and a nuanced conclusion on whether it is worth applying.
-Ask if the user wants to proceed.
Application Materials Preparation (if user continues):
-Adjust the CV to match the job description, ensuring it's ATS-friendly but doesn't look AI-generated.
-Create a concise, ATS-friendly cover letter.
-Provide 2-3 short LinkedIn messages designed to grab attention.
Job Tracking Outline:
-Summarize the job application details including company, position, date, follow-up, sentiment, and account creation details (email and password).
-Present this information in a tabular format suitable for copying into Excel.
Ensure the entire process can be completed efficiently with a single copy-paste of the job description.
"""
system prompt that guides the agent’s behavior during job application assistance. This prompt outlines various steps the agent should take:
- Company Analysis
- Account Creation
- SWOT Analysis
- Match Analysis
- Application Materials Preparation
- Job Tracking Outline
4. Creating the Agent
@st.cache_resource(show_spinner=True)
def create_agent():
"""Create and return the agent for generating cold emails."""
env_id = Agent.create_environment(
name="Job Assistant Environment",
features=[
{
"type": "SHORT_TERM_MEMORY",
"config": {},
"priority": 0
},
{
"type": "TOOL_CALLING",
"config": {"max_tries":3},
"priority": 0
}
],
tools=["perplexity_search"]
)
agent_id = Agent.create_agent(
env_id=env_id['env_id'],
system_prompt=prompt,
name="Job Assistant Agent"
)
return agent_id
- This function,
create_agent
, is cached using@st.cache_resource
for efficiency. - It defines the environment for the Lyzr agent, specifying features like short-term memory and tool calling (perplexity search).
- Finally, it creates the agent in the Lyzr environment with the defined prompt and name.
Features/Modules
The environment in this setup utilizes two synchronous (sync) modules:
a. TOOL_CALLING (Sync Module):
Type: Sync
Functionality: This module enables the agent to interact with external APIs registered through OpenAPI schemas. It’s configured to make up to three attempts (“max_tries”: 3) when invoking a specified tool, ensuring reliability in the tool’s execution.
Execution: It operates sequentially within the message processing pipeline, possessing read/write capabilities that allow it to alter the message stream as needed.
b. SHORT_TERM_MEMORY (Sync Module):
Type: Sync
Functionality: This module provides the agent with short-term contextual memory, retaining information from a configurable number of recent messages. This memory supports the agent in managing tasks that require immediate context.
Execution: Similar to other sync modules, it runs sequentially with the ability to read and write, influencing the message stream during processing.
Tools
The Perplexity search tool is registered for use within this environment:
Tools: These are external APIs that the agent can access. In this case, the Perplexity search tool is integrated, likely to help the agent retrieve information for generating newsletter content.
Note: With the TOOL_CALLING module active, the agent can access this tool as needed.
Environment ID (env_id)
env_id: This variable holds the unique identifier for the created environment. This ID is crucial for further configurations or interactions with the agent within the broader system.
Agent Creation
Agent Creation: The agent is being created using the
Agent.create_agent
method, which requires the environment ID, a system prompt, and the agent's name as input parameters. The resultingagent_id
uniquely identifies the newly created agent.
5. Session State Management
if "agent_id" not in st.session_state:
st.session_state.agent_id = create_agent()
- Session Management: The agent ID is stored in the Streamlit session state to maintain the agent’s context across user interactions.
6. User Input and Newsletter Generation
query = st.text_area("Enter Job Description", height=150)
if st.button("Submit"):
if query.strip():
with st.spinner("Researching..."):
response = Agent.send_message(
agent_id=st.session_state.agent_id['agent_id'],
user_id="default_user",
session_id="new_session",
message=query
)
# Display the generated email
st.markdown(f"\n\n{response['response']}")
else:
st.warning("Please provide Job Description...")
- Creates a text area using
st.text_area
for users to enter the job description. - A submit button is created using
st.button
. - When the button is clicked and the job description is not empty:
- A spinner is displayed using
st.spinner
to indicate processing. - The
send_message
method of the Lyzr Agent is called with the agent ID, user ID, session ID, and the job description as the message. - The generated response from the agent is displayed as markdown using
st.markdown
. - If the job description is empty, a warning message is displayed using
st.warning
.
Join Discord: https://discord.gg/dxKFHS6t
Follow us on X, Linkedin, Github❤️, Website
Project Link: https://github.com/harshit-lyzr/Landing_page_generator
Try it out: https://lyzr-job-assistant.streamlit.app/