repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: Memory-Powered Support Agent |
| #3 | description: "Build a support assistant that keeps past tickets and resolutions at its fingertips." |
| #4 | --- |
| #5 | |
| #6 | |
| #7 | You can create a personalized Customer Support AI Agent using Mem0. This guide will walk you through the necessary steps and provide the complete code to get you started. |
| #8 | |
| #9 | ## Overview |
| #10 | |
| #11 | The Customer Support AI Agent leverages Mem0 to retain information across interactions, enabling a personalized and efficient support experience. |
| #12 | |
| #13 | ## Setup |
| #14 | |
| #15 | Install the necessary packages using pip: |
| #16 | |
| #17 | ```bash |
| #18 | pip install openai mem0ai |
| #19 | ``` |
| #20 | |
| #21 | ## Full Code Example |
| #22 | |
| #23 | Below is the simplified code to create and interact with a Customer Support AI Agent using Mem0: |
| #24 | |
| #25 | ```python |
| #26 | import os |
| #27 | from openai import OpenAI |
| #28 | from mem0 import Memory |
| #29 | |
| #30 | # Set the OpenAI API key |
| #31 | os.environ['OPENAI_API_KEY'] = 'sk-xxx' |
| #32 | |
| #33 | class CustomerSupportAIAgent: |
| #34 | def __init__(self): |
| #35 | """ |
| #36 | Initialize the CustomerSupportAIAgent with memory configuration and OpenAI client. |
| #37 | """ |
| #38 | config = { |
| #39 | "vector_store": { |
| #40 | "provider": "qdrant", |
| #41 | "config": { |
| #42 | "host": "localhost", |
| #43 | "port": 6333, |
| #44 | } |
| #45 | }, |
| #46 | } |
| #47 | self.memory = Memory.from_config(config) |
| #48 | self.client = OpenAI() |
| #49 | self.app_id = "customer-support" |
| #50 | |
| #51 | def handle_query(self, query, user_id=None): |
| #52 | """ |
| #53 | Handle a customer query and store the relevant information in memory. |
| #54 | |
| #55 | :param query: The customer query to handle. |
| #56 | :param user_id: Optional user ID to associate with the memory. |
| #57 | """ |
| #58 | # Start a streaming chat completion request to the AI |
| #59 | stream = self.client.chat.completions.create( |
| #60 | model="gpt-4", |
| #61 | stream=True, |
| #62 | messages=[ |
| #63 | {"role": "system", "content": "You are a customer support AI agent."}, |
| #64 | {"role": "user", "content": query} |
| #65 | ] |
| #66 | ) |
| #67 | # Store the query in memory |
| #68 | self.memory.add(query, user_id=user_id, metadata={"app_id": self.app_id}) |
| #69 | |
| #70 | # Print the response from the AI in real-time |
| #71 | for chunk in stream: |
| #72 | if chunk.choices[0].delta.content is not None: |
| #73 | print(chunk.choices[0].delta.content, end="") |
| #74 | |
| #75 | def get_memories(self, user_id=None): |
| #76 | """ |
| #77 | Retrieve all memories associated with the given customer ID. |
| #78 | |
| #79 | :param user_id: Optional user ID to filter memories. |
| #80 | :return: List of memories. |
| #81 | """ |
| #82 | return self.memory.get_all(user_id=user_id) |
| #83 | |
| #84 | # Instantiate the CustomerSupportAIAgent |
| #85 | support_agent = CustomerSupportAIAgent() |
| #86 | |
| #87 | # Define a customer ID |
| #88 | customer_id = "jane_doe" |
| #89 | |
| #90 | # Handle a customer query |
| #91 | support_agent.handle_query("I need help with my recent order. It hasn't arrived yet.", user_id=customer_id) |
| #92 | ``` |
| #93 | |
| #94 | ### Fetching Memories |
| #95 | |
| #96 | You can fetch all the memories at any point in time using the following code: |
| #97 | |
| #98 | ```python |
| #99 | memories = support_agent.get_memories(user_id=customer_id) |
| #100 | for m in memories['results']: |
| #101 | print(m['memory']) |
| #102 | ``` |
| #103 | |
| #104 | ### Key Points |
| #105 | |
| #106 | - **Initialization**: The CustomerSupportAIAgent class is initialized with the necessary memory configuration and OpenAI client setup. |
| #107 | - **Handling Queries**: The handle_query method sends a query to the AI and stores the relevant information in memory. |
| #108 | - **Retrieving Memories**: The get_memories method fetches all stored memories associated with a customer. |
| #109 | |
| #110 | ### Conclusion |
| #111 | |
| #112 | As the conversation progresses, Mem0's memory automatically updates based on the interactions, providing a continuously improving personalized support experience. |
| #113 | |
| #114 | --- |
| #115 | |
| #116 | <CardGroup cols={2}> |
| #117 | <Card title="Build a Mem0 Companion" icon="users" href="/cookbooks/essentials/building-ai-companion"> |
| #118 | Master the foundational patterns for building memory-powered assistants. |
| #119 | </Card> |
| #120 | <Card title="Email Automation with Mem0" icon="envelope" href="/cookbooks/operations/email-automation"> |
| #121 | Extend support capabilities with intelligent email processing and routing. |
| #122 | </Card> |
| #123 | </CardGroup> |
| #124 |