linkedin_job_search_agent / tools /linkedin_job_search.py
preslaff's picture
Added job_search_tool tool in tools
eb3b209 unverified
raw
history blame
2.03 kB
from smolagents.tools import Tool
import requests
from typing import Dict, List
class LinkedInJobSearchTool(Tool):
name = "linkedin_job_search"
description = "Searches for jobs on LinkedIn based on job title, location, and work mode (remote, hybrid, in-office)."
inputs = {
"position": {"type": "string", "description": "Job title or keyword (e.g., Data Scientist)"},
"location": {"type": "string", "description": "City or country where the job is located (e.g., New York, Remote)"},
"work_mode": {"type": "string", "description": "Preferred work setting: remote, hybrid, in-office"}
}
output_type = "list" # Returning a list of job postings
def forward(self, position: str, location: str, work_mode: str) -> List[Dict]:
"""
Searches LinkedIn for job postings using SerpAPI.
"""
SERPAPI_KEY = "2f660e5a696e7d1d08662085b95f83a61224476ec19558de3c68218baf346e43" # Replace with your SerpAPI key
base_url = "https://serpapi.com/search"
params = {
"engine": "google_jobs",
"q": f"{position} {work_mode} jobs",
"location": location,
"hl": "en",
"api_key": SERPAPI_KEY
}
response = requests.get(base_url, params=params)
if response.status_code == 200:
data = response.json()
job_results = data.get("jobs_results", [])
# Extracting relevant job info
formatted_jobs = [
{
"title": job["title"],
"company": job.get("company_name", "N/A"),
"location": job.get("location", "N/A"),
"posted_date": job.get("detected_extensions", {}).get("posted_at", "N/A"),
"link": job.get("job_id", "N/A")
}
for job in job_results
]
return formatted_jobs
else:
return [{"error": f"Error {response.status_code}: {response.text}"}]