I’m working on a Python project that uses AI to conduct interviews with job candidates. My current setup works but I want to make it better by adding LangGraph for more advanced conversation handling.
Here’s what my code looks like right now:
import os
import secrets
import openai
from personality_traits import BEHAVIORAL_TRAITS
# Save chat history to file
def store_chat_log(chat_data):
file_id = secrets.token_hex(6) + '.txt'
with open(file_id, 'w') as log_file:
for message in chat_data:
if len(message) == 3: # Context, Query, Answer
log_file.write(f"Context: {message[0]}\nQuery: {message[1]}\nAnswer: {message[2]}\n\n")
else: # Query, Answer
log_file.write(f"Query: {message[0]}\nAnswer: {message[1]}\n\n")
# Get candidate information
def get_candidate_info():
client = openai.OpenAI()
greeting_prompt = "Create a professional greeting to ask for the candidate's full name. Keep it brief and welcoming."
greeting_response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": greeting_prompt}]
)
greeting_text = greeting_response.choices[0].message.content
user_name = input(f"\nAssistant: {greeting_text} ").strip()
print(f"\nAssistant: Nice to meet you, {user_name}. We'll now begin the interview process.\n")
return user_name
# Collect user input
def collect_response(question_text):
while True:
user_input = input(f"\nAssistant: {question_text}\n\nYou: ").strip()
if user_input:
return user_input
else:
print("Assistant: I didn't catch that. Could you please respond?")
# Start the interview process
candidate_name = get_candidate_info()
The system works fine for basic interviews but I want to add LangGraph to make the conversations flow better and handle complex decision trees. I’ve tried using CrewAI before but found it hard to set up properly.
I need help with:
- Adding LangGraph to my existing code without breaking what already works
- Making the AI agent smarter about choosing follow-up questions
- Better ways to organize the conversation flow
Has anyone successfully integrated LangGraph with interview automation systems? What approach worked best for you?