How to integrate LangGraph with existing AI chatbot for interview management system

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:

  1. Built basic chat functions with Crew AI for talking to candidates
  2. Started reading about LangGraph for better conversation management
  3. 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!

I just dealt with this exact same thing when I added LangGraph to my interview bot. Here’s what I learned - don’t rewrite everything. LangGraph works best as a conversation flow controller that sits on top of what you already have. Map out your interview as a state graph. Each node is a conversation stage - greeting, technical questions, behavioral stuff, whatever. Your existing get_candidate_info() and get_user_input() functions? They become node actions in the graph. The real win is how LangGraph routes conversations based on responses. Someone shows they know their stuff? Dive deeper into technical. They seem nervous? Switch to softer questions. Start simple - build a linear flow first, then add conditional branches later. You’ll need to tweak your chat history storage to track graph state, but your core logic stays the same. Yeah, it’s trickier than basic OpenAI calls, but the conversation quality jump is worth it once you get it down.