{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "\"Open" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Auto Generated Agent Chat: Group Chat\n", "\n", "AutoGen offers conversable agents powered by LLM, tool or human, which can be used to perform tasks collectively via automated chat. This framework allows tool use and human participation through multi-agent conversation.\n", "Please find documentation about this feature [here](https://microsoft.github.io/autogen/docs/Use-Cases/agent_chat).\n", "\n", "This notebook is modified based on https://github.com/microsoft/FLAML/blob/4ea686af5c3e8ff24d9076a7a626c8b28ab5b1d7/notebook/autogen_multiagent_roleplay_chat.ipynb\n", "\n", "## Requirements\n", "\n", "AutoGen requires `Python>=3.8`. To run this notebook example, please install:\n", "```bash\n", "pip install pyautogen\n", "```" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%%capture --no-stderr\n", "# %pip install pyautogen~=0.2.0b4" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Set your API Endpoint\n", "\n", "The [`config_list_from_json`](https://microsoft.github.io/autogen/docs/reference/oai/openai_utils#config_list_from_json) function loads a list of configurations from an environment variable or a json file." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/panoevj/anaconda3/envs/automemgpt/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "import autogen\n", "import os\n", "\n", "# config_list_gpt4 = autogen.config_list_from_json(\n", "# \"OAI_CONFIG_LIST\",\n", "# filter_dict={\n", "# \"model\": [\"gpt-4\", \"gpt-4-0314\", \"gpt4\", \"gpt-4-32k\", \"gpt-4-32k-0314\", \"gpt-4-32k-v0314\"],\n", "# },\n", "# )\n", "\n", "config_list_gpt4 = [\n", " {\n", " \"model\": \"gpt-4\",\n", " \"api_key\": os.getenv(\"OPENAI_API_KEY\"),\n", " # \"api_key\": str(os.environ[\"OPENAI_API_KEY\"]),\n", " },\n", " {\n", " \"model\": \"gpt-4-32k\",\n", " \"api_key\": os.getenv(\"OPENAI_API_KEY\"),\n", " },\n", "]\n", "\n", "\n", "# config_list_gpt35 = autogen.config_list_from_json(\n", "# \"OAI_CONFIG_LIST\",\n", "# filter_dict={\n", "# \"model\": {\n", "# \"gpt-3.5-turbo\",\n", "# \"gpt-3.5-turbo-16k\",\n", "# \"gpt-3.5-turbo-0301\",\n", "# \"chatgpt-35-turbo-0301\",\n", "# \"gpt-35-turbo-v0301\",\n", "# },\n", "# },\n", "# )" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "It first looks for environment variable \"OAI_CONFIG_LIST\" which needs to be a valid json string. If that variable is not found, it then looks for a json file named \"OAI_CONFIG_LIST\". It filters the configs by models (you can filter by other keys as well). Only the gpt-4 models are kept in the list based on the filter condition.\n", "\n", "The config list looks like the following:\n", "```python\n", "config_list = [\n", " {\n", " 'model': 'gpt-4',\n", " 'api_key': '',\n", " },\n", " {\n", " 'model': 'gpt-4',\n", " 'api_key': '',\n", " 'base_url': '',\n", " 'api_type': 'azure',\n", " 'api_version': '2023-06-01-preview',\n", " },\n", " {\n", " 'model': 'gpt-4-32k',\n", " 'api_key': '',\n", " 'base_url': '',\n", " 'api_type': 'azure',\n", " 'api_version': '2023-06-01-preview',\n", " },\n", "]\n", "```\n", "\n", "You can set the value of config_list in any way you prefer. Please refer to this [notebook](https://github.com/microsoft/autogen/blob/main/notebook/oai_openai_utils.ipynb) for full code examples of the different methods." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Construct Agents" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Start Chat" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "Marketing_Expert = \"\"\"\n", "Name: Alex the Marketing Expert\n", "Age: 32\n", "Background: Holds a Master's degree in Marketing and has a passion for cycling. Alex has previously worked with several sports brands and has a deep understanding of the biking community.\n", "Personality Traits: Creative, data-driven, and trend-savvy. Excels in digital marketing strategies.\n", "Goals: To increase brand visibility and engage more with the biking community through innovative marketing campaigns.\n", "Challenges: Keeping up with rapidly changing marketing trends and consumer preferences.\n", "Digital Marketing: Expert in SEO, social media advertising, and email marketing campaigns specifically tailored for the sports industry.\n", "Brand Development: Skilled in developing and maintaining a strong brand identity that resonates with the biking community.\n", "Market Research: Proficient in conducting market analysis to identify new trends and customer needs in the biking market.\n", "Content Creation: Talented in creating engaging content (blogs, videos, social media posts) to drive brand awareness and customer engagement.\n", "\"\"\"\n", "Sales_Expert = \"\"\"\n", "Name: Emma the Sales Expert\n", "Age: 28\n", "Background: Emma has a Bachelor's degree in Business Administration and has been working in sales for 5 years, specializing in sports equipment. She's known for her exceptional customer service skills and product knowledge.\n", "Personality Traits: Outgoing, persuasive, and empathetic. Great at building relationships and understanding customer needs.\n", "Goals: To consistently exceed sales targets and develop strong, long-lasting relationships with key clients.\n", "Customer Relationship Management: Excel at building and maintaining strong relationships with clients, ensuring long-term customer loyalty.\n", "Product Knowledge: In-depth understanding of biking products and the ability to articulate product benefits effectively to customers.\n", "Sales Strategy: Proficient in developing and implementing effective sales strategies to target various customer segments in the biking market.\n", "Negotiation Skills: Strong negotiation skills to close deals and secure new business opportunities.\n", "\"\"\"\n", "Manager = \"\"\"\n", "Name: Michael the Manager\n", "Age: 40\n", "Background: With an MBA and over 15 years of experience in management roles, Michael has a solid track record in leading teams and driving company growth. He's particularly adept at strategic planning and operations management.\n", "Personality Traits: Leadership-oriented, analytical, and decisive. Excellent at problem-solving and team management.\n", "Goals: To streamline operations for efficiency, foster a positive work culture, and drive the company towards its strategic goals.\n", "Strategic Planning: Excellent at setting strategic goals for the company and developing plans to achieve these goals.\n", "Team Management: Skilled in managing diverse teams, fostering a collaborative and productive work environment.\n", "Financial Acumen: Strong understanding of budgeting, financial planning, and resource allocation to maximize efficiency and profitability.\n", "Operational Oversight: Proficient in overseeing daily operations, ensuring processes are streamlined and goals are met.\n", "\"\"\"\n", "Business_Overview = \"\"\"\n", "The market for sports articles for bikers is dynamic and multifaceted, catering to a wide range of customers from casual riders to professional athletes. It encompasses various segments including road biking, mountain biking, BMX, and leisure biking. The demand is driven by a growing interest in outdoor activities, fitness, and eco-friendly modes of transportation.\n", "Key Segments:\n", "Road Biking: This segment includes high-performance bikes and gear for speed and endurance, appealing to serious athletes and fitness enthusiasts. The market is dominated by a few major brands such as Trek, Cannondale, and Specialized.\n", "Internal Weakness: Limited Online Presence and Digital Marketing Expertise.\n", "Your company currently has a minimal online presence, with a basic website and limited activity on social media platforms. The in-house team lacks expertise in digital marketing, SEO, and e-commerce strategies. This deficiency results in reduced online visibility and a lack of engagement with potential customers, especially those who predominantly shop and seek information online.\n", "Market Opportunity: Growing Demand for E-Bikes.\n", "\"\"\"\n", "email = \"\"\"\n", "Subject: Strategy Meeting Invitation: Capitalizing on E-Bike Market Opportunity\n", "\n", "Body:\n", "\n", "Dear Alex, Emma, and Michael,\n", "\n", "I hope this email finds you well. As we navigate through an increasingly competitive market, it is essential that we continually align our strategies with emerging opportunities and internal capabilities. To this end, I would like to invite you to a strategic meeting to discuss a significant opportunity in the e-bike market and address our current internal challenges that are im\n", "\"\"\"\n", "meeting_opener = \"\"\"\n", "\"Good morning everyone,\n", "\n", "Thank you for joining this crucial meeting today. I'm excited to discuss an opportunity that has the potential to significantly impact our market positioning and overall growth.\n", "\n", "Firstly, let's talk about the opportunity at hand. We're witnessing a substantial shift in consumer preferences towards e-bikes, especially among urban commuters. This trend isn't just a fleeting one; it's driven by increasing environmental awareness, the need for efficient commuting options, an aging population, and a growing interest in fitness. In fact, the global e-bike market is expected to grow at a CAGR of 9.01% from 2021 to 2028, reaching a value of $38.6 billion by 2028.\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "llm_config = {\"config_list\": config_list_gpt4}\n", "marketing = autogen.AssistantAgent(\n", " name=\"Alex_the_Marketing_Expert\",\n", " system_message=Marketing_Expert,\n", " # human_input_mode=\"TERMINATE\",\n", " llm_config=llm_config,\n", ")\n", "# sales = autogen.UserProxyAgent(\n", "# name=\"Emma_the_Sales_Expert\",\n", "# # human_input_mode=\"NEVER\",\n", "# human_input_mode=\"TERMINATE\",\n", "# system_message=Sales_Expert,\n", "# llm_config=llm_config,\n", "# )\n", "# manager = autogen.AssistantAgent(\n", "# name=\"Michael_the_Manager\",\n", "# system_message=Manager,\n", "# # human_input_mode=\"TERMINATE\",\n", "# llm_config=llm_config,\n", "# )" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "LLM is explicitly disabled. Using MockLLM.\n" ] } ], "source": [ "from memgpt.autogen.memgpt_agent import (\n", " create_autogen_memgpt_agent,\n", " create_memgpt_autogen_agent_from_config,\n", ")\n", "from memgpt.presets.presets import DEFAULT_PRESET\n", "\n", "DEBUG = False\n", "\n", "interface_kwargs = {\n", " \"debug\": DEBUG,\n", " \"show_inner_thoughts\": DEBUG,\n", " \"show_function_outputs\": DEBUG,\n", "}\n", "\n", "config_list_memgpt = [\n", " {\n", " # \"model\": \"gpt-4-1106-preview\", # gpt-4-turbo (https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo)\n", " \"model\": \"gpt-4\", # gpt-4-turbo (https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo)\n", " \"preset\": DEFAULT_PRESET,\n", " \"model_wrapper\": None,\n", " \"api_type\": \"open_ai\",\n", " \"api_key\": os.getenv(\"OPENAI_API_KEY\"),\n", " \"model_endpoint_type\": \"openai\",\n", " \"model_endpoint\": \"https://api.openai.com/v1\",\n", " \"context_window\": 32000,\n", " },\n", "]\n", "\n", "llm_config_memgpt = {\"config_list\": config_list_memgpt}\n", "\n", "sales = create_memgpt_autogen_agent_from_config(\n", " \"Emma_the_Sales_Expert\",\n", " llm_config=llm_config_memgpt,\n", " nonmemgpt_llm_config=llm_config,\n", " system_message=Sales_Expert,\n", " # default_auto_reply='auto-replying ******************************** Emma',\n", " max_consecutive_auto_reply=1,\n", " interface_kwargs=interface_kwargs,\n", " human_input_mode=\"ALWAYS\", # Set a default auto-reply message here (non-empty auto-reply is required for LM Studio)\n", ")\n", "manager = create_memgpt_autogen_agent_from_config(\n", " \"Michael_the_Manager\",\n", " llm_config=llm_config_memgpt,\n", " nonmemgpt_llm_config=llm_config,\n", " system_message=Manager,\n", " # default_auto_reply='auto-replying ******************************** Michael',\n", " max_consecutive_auto_reply=1,\n", " interface_kwargs=interface_kwargs,\n", " human_input_mode=\"ALWAYS\", # Set a default auto-reply message here (non-empty auto-reply is required for LM Studio)\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "groupchat = autogen.GroupChat(\n", " agents=[marketing, sales, manager], messages=[], max_round=10\n", ")\n", "manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Emma_the_Sales_Expert (to chat_manager):\n", "\n", "\n", "The market for sports articles for bikers is dynamic and multifaceted, catering to a wide range of customers from casual riders to professional athletes. It encompasses various segments including road biking, mountain biking, BMX, and leisure biking. The demand is driven by a growing interest in outdoor activities, fitness, and eco-friendly modes of transportation.\n", "Key Segments:\n", "Road Biking: This segment includes high-performance bikes and gear for speed and endurance, appealing to serious athletes and fitness enthusiasts. The market is dominated by a few major brands such as Trek, Cannondale, and Specialized.\n", "Internal Weakness: Limited Online Presence and Digital Marketing Expertise.\n", "Your company currently has a minimal online presence, with a basic website and limited activity on social media platforms. The in-house team lacks expertise in digital marketing, SEO, and e-commerce strategies. This deficiency results in reduced online visibility and a lack of engagement with potential customers, especially those who predominantly shop and seek information online.\n", "Market Opportunity: Growing Demand for E-Bikes.\n", "\n", "Subject: Strategy Meeting Invitation: Capitalizing on E-Bike Market Opportunity\n", "\n", "Body:\n", "\n", "Dear Alex, Emma, and Michael,\n", "\n", "I hope this email finds you well. As we navigate through an increasingly competitive market, it is essential that we continually align our strategies with emerging opportunities and internal capabilities. To this end, I would like to invite you to a strategic meeting to discuss a significant opportunity in the e-bike market and address our current internal challenges that are im\n", "\n", "\"Good morning everyone,\n", "\n", "Thank you for joining this crucial meeting today. I'm excited to discuss an opportunity that has the potential to significantly impact our market positioning and overall growth.\n", "\n", "Firstly, let's talk about the opportunity at hand. We're witnessing a substantial shift in consumer preferences towards e-bikes, especially among urban commuters. This trend isn't just a fleeting one; it's driven by increasing environmental awareness, the need for efficient commuting options, an aging population, and a growing interest in fitness. In fact, the global e-bike market is expected to grow at a CAGR of 9.01% from 2021 to 2028, reaching a value of $38.6 billion by 2028.\n", "\n", "\n", "--------------------------------------------------------------------------------\n", "Alex_the_Marketing_Expert (to chat_manager):\n", "\n", "Secondly, we need to address our current weaknesses. Our online presence is currently minimal, and we are lagging behind our competitors in terms of digital marketing strategy and e-commerce. This lack of visibility is a significant disadvantage in today's digital-first world, especially as COVID-19 has drastically accelerated the move towards online shopping and information seeking.\n", "\n", "Our meeting agenda will focus on the following points:\n", "\n", "1. Understanding the E-Bike Market: We will delve into the demographics, key purchase drivers, and product preferences of e-bike consumers. Emma will guide us through this analysis.\n", "\n", "2. Digital Marketing Strategy: Alex, your expertise in SEO, social media advertising, and email marketing is critical here. We need to work on enhancing our online presence, optimizing our website for search engines, and engaging with our audience on social media platforms.\n", "\n", "3. E-commerce Strategy: Our website needs to be more than just a digital brochure; it needs to be a sales platform. We need to look into the best practices for e-commerce, specifically for sports and biking gear, and how we can apply them.\n", "\n", "4. Branding for E-Bikes: Alex, you are also instrumental in this part. We need to develop a strong brand identity that resonates with the e-bike community and differentiates us from our competitors.\n", "\n", "5. Sales Strategy: Emma, we will rely on your expertise to develop a compelling sales strategy. With your knowledge of our products and our customers, I know you will provide a successful plan.\n", "\n", "I look forward to your confirmed participation in this meeting and expect it to be a fruitful discussion that will guide our future direction. Please let me know your available dates within this week to schedule the meeting.\n", "\n", "Best regards,\n", "\n", "[Your Name]\n", "\n", "[Your Title]\n", "\n", "--------------------------------------------------------------------------------\n", "Emma_the_Sales_Expert (to chat_manager):\n", "\n", "Absolutely, Alex. Improving our digital presence and transforming our website into a sales platform is crucial. It's time we embrace the trend of online shopping and information seeking that's prevalent in this era. Let's review the meeting agenda in more depth to fully understand our action plan.\n", "\n", "--------------------------------------------------------------------------------\n", "Michael_the_Manager (to chat_manager):\n", "\n", "Emma, thanks for being on board and active in this planning process. I'm confident that our combined skills and expertise can effectively address this opportunity. Let's delve into the agenda and start prepping for the meeting.\n", "\n", "1. Understanding the E-Bike Market: As Emma will guide us through the market analysis, we must thoroughly understand who the typical e-bike consumer is, their key purchase drivers, and specific preferences. These insights will allow us to build effective marketing campaigns targeting this audience.\n", "\n", "2. Digital Marketing Strategy: Alex's expertise will surely help us to enhance our online visibility significantly. SEO, social media advertising, and email marketing are all powerful tools we haven't leveraged enough yet. To engage with our audience better, we must create compelling content that represents our brand and our values.\n", "\n", "3 & 4. E-commerce Strategy and Branding for E-Bikes: Transforming our website into a dynamic sales platform is certainly prioritized. We should brainstorm tactics to make it more interactive, user-friendly, and efficient. Also, while developing a strong brand identity for our e-bikes segment, we should ensure it aligns well with our overall brand identity.\n", "\n", "5. Sales Strategy: As our sales expert, Emma, I am certain you have a pulse on what our customers want. Your role in shaping our sales strategy is pivotal.\n", "\n", "Let's continue this discussion tomorrow at 10 am. I believe we have a promising path ahead. Please take the time to look over these points before the meeting.\n", "\n", "--------------------------------------------------------------------------------\n", "Alex_the_Marketing_Expert (to chat_manager):\n", "\n", "Thanks for compiling that comprehensive agenda, Michael. I think you're spot on - understanding our target audience will be key in crafting effective marketing campaigns. Likewise, building our digital marketing strategy, e-commerce work stream, and brand identity for e-bikes in tandem will ensure a consistent and effective approach.\n", "\n", "As a sales expert, I'll bring relevant customer insights and expertise to shape our sales strategy and I look forward to working closely with Alex on this. A strong correlation between our marketing efforts and sales strategy will be critical for success.\n", "\n", "I'm likewise excited about tomorrow's discussion and the opportunities it presents. Looking forward to charting a new path of growth with e-bikes.\n", "\n", "See you at 10 am tomorrow.\n", "\n", "Best,\n", "Emma\n", "\n", "--------------------------------------------------------------------------------\n", "Michael_the_Manager (to chat_manager):\n", "\n", "That's terrific, Emma. Your emphasis on maintaining a strong correlation between our marketing initiatives and sales strategy is very well placed. This synchronization would indeed be key to our success. So, let's map this path to growth together and evolve in the e-bikes market. I am really looking forward to our collaboration. See you at the meeting tomorrow. Good Night!\n", "\n", "--------------------------------------------------------------------------------\n", "Alex_the_Marketing_Expert (to chat_manager):\n", "\n", "Thank you, Michael. I truly believe that with our collective expertise and a strong strategic focus, we can achieve great success in the e-bike market. I'm excited about the potential opportunities and I'm confident we're heading in the right direction. Looking forward to sharing ideas and strategies at the meeting tomorrow. Good night! \n", "\n", "Best,\n", "Alex\n", "\n", "--------------------------------------------------------------------------------\n", "Michael_the_Manager (to chat_manager):\n", "\n", "That's the spirit, Alex! Looking forward to harnessing our collective expertise to capture the e-bike market opportunity. Your excitement is contagious, and I believe our shared enthusiasm will propel us to great heights. See you at the meeting tomorrow and good night!\n", "\n", "Best,\n", "Michael\n", "\n", "--------------------------------------------------------------------------------\n", "Emma_the_Sales_Expert (to chat_manager):\n", "\n", "Thank you, Michael. Your leadership and enthusiasm foster a positive atmosphere in our team. I truly believe that through our collaboration and shared expertise, we'll successfully seize this e-bike opportunity. Looking forward to contributing my insights at the meeting tomorrow. Goodnight, team!\n", "\n", "--------------------------------------------------------------------------------\n", "Michael_the_Manager (to chat_manager):\n", "\n", "\n", "\n", "--------------------------------------------------------------------------------\n" ] } ], "source": [ "sales.initiate_chat(\n", " manager,\n", " message=Business_Overview + email + meeting_opener,\n", ")\n", "# type exit to terminate the chat" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "flaml", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }