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: AutoGen |
| #3 | --- |
| #4 | |
| #5 | Build conversational AI agents with memory capabilities. This integration combines AutoGen for creating AI agents with Mem0 for memory management, enabling context-aware and personalized interactions. |
| #6 | |
| #7 | ## Overview |
| #8 | |
| #9 | This guide demonstrates creating a conversational AI system with memory. We'll build a customer service bot that can recall previous interactions and provide personalized responses. |
| #10 | |
| #11 | ## Setup and Configuration |
| #12 | |
| #13 | Install necessary libraries: |
| #14 | |
| #15 | ```bash |
| #16 | pip install autogen mem0ai openai python-dotenv |
| #17 | ``` |
| #18 | |
| #19 | First, we'll import the necessary libraries and set up our configurations. |
| #20 | |
| #21 | <Note>Remember to get the Mem0 API key from [Mem0 Platform](https://app.mem0.ai).</Note> |
| #22 | |
| #23 | ```python |
| #24 | import os |
| #25 | from autogen import ConversableAgent |
| #26 | from mem0 import MemoryClient |
| #27 | from openai import OpenAI |
| #28 | from dotenv import load_dotenv |
| #29 | |
| #30 | load_dotenv() |
| #31 | |
| #32 | # Configuration |
| #33 | # OPENAI_API_KEY = 'sk-xxx' # Replace with your actual OpenAI API key |
| #34 | # MEM0_API_KEY = 'your-mem0-key' # Replace with your actual Mem0 API key from https://app.mem0.ai |
| #35 | USER_ID = "alice" |
| #36 | |
| #37 | # Set up OpenAI API key |
| #38 | OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY') |
| #39 | # os.environ['MEM0_API_KEY'] = MEM0_API_KEY |
| #40 | |
| #41 | # Initialize Mem0 and AutoGen agents |
| #42 | memory_client = MemoryClient() |
| #43 | agent = ConversableAgent( |
| #44 | "chatbot", |
| #45 | llm_config={"config_list": [{"model": "gpt-4", "api_key": OPENAI_API_KEY}]}, |
| #46 | code_execution_config=False, |
| #47 | human_input_mode="NEVER", |
| #48 | ) |
| #49 | ``` |
| #50 | |
| #51 | ## Storing Conversations in Memory |
| #52 | |
| #53 | Add conversation history to Mem0 for future reference: |
| #54 | |
| #55 | ```python |
| #56 | conversation = [ |
| #57 | {"role": "assistant", "content": "Hi, I'm Best Buy's chatbot! How can I help you?"}, |
| #58 | {"role": "user", "content": "I'm seeing horizontal lines on my TV."}, |
| #59 | {"role": "assistant", "content": "I'm sorry to hear that. Can you provide your TV model?"}, |
| #60 | {"role": "user", "content": "It's a Sony - 77\" Class BRAVIA XR A80K OLED 4K UHD Smart Google TV"}, |
| #61 | {"role": "assistant", "content": "Thank you for the information. Let's troubleshoot this issue..."} |
| #62 | ] |
| #63 | |
| #64 | memory_client.add(messages=conversation, user_id=USER_ID) |
| #65 | print("Conversation added to memory.") |
| #66 | ``` |
| #67 | |
| #68 | ## Retrieving and Using Memory |
| #69 | |
| #70 | Create a function to get context-aware responses based on user's question and previous interactions: |
| #71 | |
| #72 | ```python |
| #73 | def get_context_aware_response(question): |
| #74 | relevant_memories = memory_client.search(question, user_id=USER_ID) |
| #75 | context = "\n".join([m["memory"] for m in relevant_memories.get('results', [])]) |
| #76 | |
| #77 | prompt = f"""Answer the user question considering the previous interactions: |
| #78 | Previous interactions: |
| #79 | {context} |
| #80 | |
| #81 | Question: {question} |
| #82 | """ |
| #83 | |
| #84 | reply = agent.generate_reply(messages=[{"content": prompt, "role": "user"}]) |
| #85 | return reply |
| #86 | |
| #87 | # Example usage |
| #88 | question = "What was the issue with my TV?" |
| #89 | answer = get_context_aware_response(question) |
| #90 | print("Context-aware answer:", answer) |
| #91 | ``` |
| #92 | |
| #93 | ## Multi-Agent Conversation |
| #94 | |
| #95 | For more complex scenarios, you can create multiple agents: |
| #96 | |
| #97 | ```python |
| #98 | manager = ConversableAgent( |
| #99 | "manager", |
| #100 | system_message="You are a manager who helps in resolving complex customer issues.", |
| #101 | llm_config={"config_list": [{"model": "gpt-4", "api_key": OPENAI_API_KEY}]}, |
| #102 | human_input_mode="NEVER" |
| #103 | ) |
| #104 | |
| #105 | def escalate_to_manager(question): |
| #106 | relevant_memories = memory_client.search(question, user_id=USER_ID) |
| #107 | context = "\n".join([m["memory"] for m in relevant_memories.get('results', [])]) |
| #108 | |
| #109 | prompt = f""" |
| #110 | Context from previous interactions: |
| #111 | {context} |
| #112 | |
| #113 | Customer question: {question} |
| #114 | |
| #115 | As a manager, how would you address this issue? |
| #116 | """ |
| #117 | |
| #118 | manager_response = manager.generate_reply(messages=[{"content": prompt, "role": "user"}]) |
| #119 | return manager_response |
| #120 | |
| #121 | # Example usage |
| #122 | complex_question = "I'm not satisfied with the troubleshooting steps. What else can be done?" |
| #123 | manager_answer = escalate_to_manager(complex_question) |
| #124 | print("Manager's response:", manager_answer) |
| #125 | ``` |
| #126 | |
| #127 | ## Conclusion |
| #128 | |
| #129 | By integrating AutoGen with Mem0, you've created a conversational AI system with memory capabilities. This example demonstrates a customer service bot that can recall previous interactions and provide context-aware responses, with the ability to escalate complex issues to a manager agent. |
| #130 | |
| #131 | This integration enables the creation of more intelligent and personalized AI agents for various applications, such as customer support, virtual assistants, and interactive chatbots. |
| #132 | |
| #133 | <CardGroup cols={2}> |
| #134 | <Card title="CrewAI Integration" icon="users" href="/integrations/crewai"> |
| #135 | Build multi-agent systems with CrewAI and Mem0 |
| #136 | </Card> |
| #137 | <Card title="LangGraph Integration" icon="diagram-project" href="/integrations/langgraph"> |
| #138 | Create stateful workflows with LangGraph |
| #139 | </Card> |
| #140 | </CardGroup> |
| #141 | |
| #142 |