I’m working on a Python app that uses AI to chat with job candidates and analyze their behavior. Right now I have basic functions working but I want to add LangGraph to make the conversations flow better.
Here’s what my current code looks like:
import os
import json
import openai
from personality_data import PERSONALITY_TYPES
# Store chat history in JSON format
def store_chat_history(chat_data):
filename = f"interview_{os.urandom(4).hex()}.json"
with open(filename, 'w') as f:
for message in chat_data:
if len(message) == 3: # Context, Query, Answer
f.write(json.dumps({
"context": message[0],
"query": message[1],
"answer": message[2]
}) + "\n")
else: # Query, Answer
f.write(json.dumps({
"query": message[0],
"answer": message[1]
}) + "\n")
# Get candidate details at start
def get_candidate_info():
client = openai.OpenAI()
greeting_prompt = "Create a welcoming message to collect the candidate's full name. Keep it professional but warm."
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": greeting_prompt}]
)
greeting_text = response.choices[0].message.content
full_name = input(f"\nBot: {greeting_text}\nYou: ").strip()
print(f"\nBot: Great to meet you, {full_name}. Ready to begin the assessment?\n")
return full_name
# Handle user input with validation
def get_user_input(question_text):
while True:
answer = input(f"\nBot: {question_text}\n\nYou: ").strip()
if answer:
return answer
else:
print("Bot: I didn't catch that. Could you please respond?")
# Start the interview process
candidate_name = get_candidate_info()
# More interview logic continues here
I tried using Crew AI before and looked into LangGraph but I’m still confused about how to set it up properly. The documentation seems complex for someone just starting out.
What I’ve done so far:
- Built basic chat functions with Crew AI for talking to candidates
- Started reading about LangGraph for better conversation management
- Created helper functions for getting candidate info and handling their responses
What I need help with:
- Simple steps to add LangGraph to my existing code
- Better ways to structure AI agents for interview scenarios
- Any easier alternatives if LangGraph is too complicated
I’d really appreciate any tips or examples from people who have done this before. Thanks for any help you can offer!