📢 Announcing our research paper: Zentry achieves 26% higher accuracy than OpenAI Memory, 91% lower latency, and 90% token savings! Read the paper to learn how we're revolutionizing AI agent memory.
Build a personalized Customer Support AI Agent using LangGraph for conversation flow and Zentry for memory retention. This integration enables context-aware and efficient support experiences.
Define the core logic for the Customer Support AI Agent:
Copy
def chatbot(state: State): messages = state["messages"] user_id = state["Zentry_user_id"] # Retrieve relevant memories memories = Zentry.search(messages[-1].content, user_id=user_id) context = "Relevant information from previous conversations:\n" for memory in memories: context += f"- {memory['memory']}\n" system_message = SystemMessage(content=f"""You are a helpful customer support assistant. Use the provided context to personalize your responses and remember user preferences and past interactions.{context}""") full_messages = [system_message] + messages response = llm.invoke(full_messages) # Store the interaction in Zentry Zentry.add(f"User: {messages[-1].content}\nAssistant: {response.content}", user_id=user_id) return {"messages": [response]}
Implement a function to manage the conversation flow:
Copy
def run_conversation(user_input: str, Zentry_user_id: str): config = {"configurable": {"thread_id": Zentry_user_id}} state = {"messages": [HumanMessage(content=user_input)], "Zentry_user_id": Zentry_user_id} for event in compiled_graph.stream(state, config): for value in event.values(): if value.get("messages"): print("Customer Support:", value["messages"][-1].content) return
Set up the main program loop for user interaction:
Copy
if __name__ == "__main__": print("Welcome to Customer Support! How can I assist you today?") Zentry_user_id = "customer_123" # You can generate or retrieve this based on your user management system while True: user_input = input("You: ") if user_input.lower() in ['quit', 'exit', 'bye']: print("Customer Support: Thank you for contacting us. Have a great day!") break run_conversation(user_input, Zentry_user_id)
By integrating LangGraph with Zentry, you can build a personalized Customer Support AI Agent that can maintain context across interactions and provide personalized assistance.