resumate / functions /writer_agent.py
gperdrizet's picture
Cleaned up data directory structure for intermediate results
bef6750 verified
raw
history blame
2.52 kB
'''Agent responsible for writing the resume based on user provided context'''
import json
import logging
import os
from smolagents import CodeAgent
from configuration import AGENT_MODEL, INSTRUCTIONS
# pylint: disable=broad-exception-caught
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def write_resume(content: str, user_instructions: str = None, job_summary: str = None) -> str:
"""
Generates a resume based on the provided content.
Args:
content (str): The content to be used for generating the resume.
user_instructions (str, optional): Additional instructions from the user.
job_summary (str, optional): Extracted/summarized job call information.
Returns:
str: The generated resume.
"""
if content['status'] == 'success':
agent = CodeAgent(
model=AGENT_MODEL,
tools=[],
additional_authorized_imports=['json'],
name="writer_agent",
verbosity_level=5,
max_steps=20,
planning_interval=5
)
# Prepare instructions - combine default with user instructions and job summary
instructions = INSTRUCTIONS
if job_summary and job_summary.strip():
instructions += f"\n\nJob Requirements and Details:\n{job_summary.strip()}"
logger.info("Added job summary to agent prompt (%d characters)", len(job_summary))
if user_instructions and user_instructions.strip():
instructions += f"\n\nAdditional user instructions:\n{user_instructions.strip()}"
logger.info("Added user instructions to agent prompt")
submitted_answer = agent.run(
instructions + '\n' + json.dumps(content['structured_text']),
)
logger.info("submitted_answer: %s", submitted_answer)
# Create data directory if it doesn't exist
data_dir = 'data'
if not os.path.exists(data_dir):
os.makedirs(data_dir)
logger.info("Created data directory: %s", data_dir)
# Save the resume to resume.md in the data directory
resume_file_path = os.path.join(data_dir, 'resume.md')
try:
with open(resume_file_path, 'w', encoding='utf-8') as f:
f.write(submitted_answer)
logger.info("Resume saved to: %s", resume_file_path)
except Exception as e:
logger.error("Failed to save resume to file: %s", e)
return submitted_answer