I’m working on a Python app that uses AI to conduct interviews and analyze candidate responses. Right now I have basic functionality working but I want to add LangGraph to make the conversation flow better.
Here’s what my current code looks like:
import os
import random
import openai
from personality_traits import BEHAVIORAL_TRAITS
# Store chat history in a file
def store_chat_log(chat_data):
file_id = ''.join(random.choices('abcdefghijklmnopqrstuvwxyz0123456789', k=10)) + '.log'
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 details at start
def greet_candidate():
client = openai.OpenAI()
greeting_prompt = "Create a professional greeting to ask for the candidate's full name. Make it sound natural and welcoming."
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": greeting_prompt}]
)
greeting_text = response.choices[0].message.content
user_name = input(f"\nInterviewer: {greeting_text}\nYour answer: ").strip()
print(f"\nInterviewer: Nice to meet you, {user_name}. We'll start with some behavioral questions now.\n")
return user_name
# Collect responses from candidate
def get_candidate_response(question_text):
while True:
answer = input(f"\nInterviewer: {question_text}\n\nYour response: ").strip()
if answer:
return answer
else:
print("Interviewer: Could you please answer the question?")
# Start the interview process
candidate_name = greet_candidate()
# More interview logic follows here
I’ve tried using CrewAI before and looked into LangGraph but I’m having trouble figuring out how to add it to my existing code. I’m pretty new to these AI frameworks so I’m not sure about the best approach.
What I’ve done so far:
- Built basic interview functionality with CrewAI for candidate interaction and conversation logging
- Started learning about LangGraph to improve conversation management and decision logic
- Created functions for greeting candidates, asking questions, and processing their answers with OpenAI
What I need help with:
- How to properly add LangGraph to my current setup or if there’s an easier framework to use
- Best practices for organizing AI agents to handle interview tasks and behavioral assessment
I’d really appreciate any advice from people who have experience with these tools. Thanks for any help you can provide!