成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何使用AutoGen AI技術實現多代理對話 原創

發布于 2024-12-5 08:12
瀏覽
0收藏

本文將介紹一個實驗,展示多個人工智能代理如何通過群聊方式進行互動,并根據具體的業務需求協同工作,共同生成解決方案的架構。

本文介紹如何使用Databricks Community Edition (CE)(一個免費的基于云的平臺)運行一些基本的人工智能Python代碼。因為只處理開源庫,所以這個實驗可以很容易地在任何Python/PySpark環境中復現。

AutoGen和可對話代理簡介

??AutoGen???是一個開源平臺,使開發人員能夠創建協作人工智能代理。這些代理通常通過聊天群組進行交互,并共同完成任務。??可對話代理???可以發送、接收和生成消息,也可以使用人工智能模型、工具和人工輸入的組合來定制。可對話代理可以是以下任何一種:

  • 用戶代理,顧名思義,它是人類的代理,在用戶輸入與人工智能代理回復之間的某個環節發揮作用,并能執行代碼。
  • 一個或多個助理代理,它們是使用大型語言模型(LLM)但不需要人工輸入或代碼執行的人工智能助理。

以下將在用戶代理(例如,架構主管)和三個助理代理(云計算架構師、開源架構師和首席架構師)之間創建一個聊天群組。其目標是基于業務需求列表提供解決方案架構,可以用以下的互動圖來表示:

如何使用AutoGen AI技術實現多代理對話-AI.x社區

對話流程的工作原理如下:

  • 業務需求提供給代理。
  • 代理發起架構師之間的聊天。
  • 云計算架構師將首先發言,為每個主要的云計算提供商:Azure、AWS和谷歌云提供建議。
  • 下一位發言者。
  • 開源架構師將提供在云計算領域之外使用開源框架的一個解決方案。
  • 下一位(也是最后一位)發言者。
  • 首席架構師將審查所有解決方案并提供最終提案。

提示工程

首先創建提示,從包含一些簡單需求的公共部分(當前的任務)開始:

Plain Text 
1 task = '''
2  **Task**: As an architect, you are required to design a solution for the 
3  following business requirements:
4    - Data storage for massive amounts of IoT data
5    - Real-time data analytics and machine learning pipeline 
6    - Scalability
7    - Cost Optimization
8    - Region pairs in Europe, for disaster recovery
9    - Tools for monitoring and observability
10   - Timeline: 6 months
11
12    Break down the problem using a Chain-of-Thought approach. Ensure that your 
13    solution architecture is following best practices.
14    '''

云計算架構師提示:

Plain Text 
1 cloud_prompt = '''
2 **Role**: You are an expert cloud architect. You need to develop architecture proposals 
3 using either cloud-specific PaaS services, or cloud-agnostic ones.
4 The final proposal should consider all 3 main cloud providers: Azure, AWS and GCP, and provide 
5 a data architecture for each. At the end, briefly state the advantages of cloud over on-premises 
6 architectures, and summarize your solutions for each cloud provider using a table for clarity.
7 '''
8 cloud_prompt += task

開源架構師提示:

Plain Text 
1 oss_prompt = '''
2 **Role**: You are an expert on-premises, open-source software architect. You need 
3 to develop architecture proposals without considering cloud solutions.
4 Only use open-source frameworks that are popular and have lots of active contributors. 
5 At the end, briefly state the advantages of open-source adoption, and summarize your 
6  solutions using a table for clarity.
7 '''
8 oss_prompt += task

首席架構師提示:

Plain Text 
1 lead_prompt =  '''
2 **Role**: You are a lead Architect tasked with managing a conversation between 
3 the cloud and the open-source Architects.
4 Each Architect will perform a task and respond with their resuls. You will critically 
5 review those and also ask for, or pointo, the disadvantages of their soltuions.
6 You will review each result, and choose the best solution in accordance with the business 
7 requirements and architecture best practices. You will use any number of summary tables to 
8 communicate your decision.
9 '''
10 lead_prompt += task

在完成提示之后,可以開始創建可對話代理,并讓它們在聊天設置中進行交互。

實現多代理聊天

由于使用的是Python,需要安裝相應的pyautogen包:

Python 
1 pip install pyautogen

從導入必要的庫和一些配置開始。雖然可以使用多個模型,但在這個簡單的示例中,選擇僅使用GPT-4o。

Python 
1 import autogen
2 from autogen import UserProxyAgent
3 from autogen import AssistantAgent
4
5
6 config_list = [{'model': 'gpt-4o', 'api_key': '---------'}]
7
8 gpt4o_config = {
9    "cache_seed": 42,  # change the cache_seed for different trials
10    "temperature": 0,
11    "config_list": config_list,
12    "timeout": 120,
13 }

將溫度設為0可以最大限度地減少模型的隨機性,使其專注于最可能(即得分最高)的選擇。現在,將創建具有特定提示的代理:

Python 
1 user_proxy = autogen.UserProxyAgent(
2    name="supervisor",
3    system_message = "A Human Head of Architecture",
4    code_execution_config={
5        "last_n_messages": 2,
6        "work_dir": "groupchat",
7        "use_docker": False,
8    },  
9    human_input_mode="NEVER",
10 )
11
12 cloud_agent = AssistantAgent(
13    name = "cloud", 
14    system_message = cloud_prompt,
15    llm_config={"config_list": config_list}
16    )
17
18
oss_agent = AssistantAgent(
19    name = "oss", 
20    system_message = oss_prompt,
21    llm_config={"config_list": config_list}
22    )
23
24 lead_agent = AssistantAgent(
25    name = "lead", 
26    system_message = lead_prompt,
27    llm_config={"config_list": config_list}
28 )

上述代碼應該清晰易懂。在開始聊天之前,需明確交互順序,因為希望首席架構師在云計算架構師和開源架構師這兩個助理提供解決方案之后再進行總結與決策。首席架構師需要審閱這些方案并作出決定。為了確保這一流程得以順利執行,創建了一個狀態轉移函數,用于在聊天中選擇發言者:

Python 
1 def state_transition(last_speaker, groupchat):
2   messages = groupchat.messages
3
4   if last_speaker is user_proxy:
5       return cloud_agent
6   elif last_speaker is cloud_agent:
7       return oss_agent
8   elif last_speaker is oss_agent:
9       return lead_agent
10   elif last_speaker is lead_agent:
11       # lead -> end
12       return Non

這是一個有限狀態機(FSM)的簡單示例。現在,準備采用下面這段代碼來觸發聊天:

Python 
1  groupchat = autogen.GroupChat(
2    agents=[user_proxy, cloud_agent, oss_agent, lead_agent], 
3    messages=[], 
4    max_round=6,
5    speaker_selection_method=state_transition,
6 )
7 manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)
8
9 user_proxy.initiate_chat(
10    manager, message="Provide your best architecture based on these business requirements."
11 )

解釋輸出

由于篇幅所限,在這里只展示輸出的部分內容。該代碼易于復制,對細節感興趣的人可以直接在自己的環境中運行。

聊天從第一位發言者開始:

Plain Text 
1 supervisor (to chat_manager):
2
3 Provide your best architecture based on these business requirements.
4
5--------------------------------------------------------------------------------
6
7 Next speaker: cloud
8
9 cloud (to chat_manager):
10
11 ### Chain-of-Thought Approach
12
13 #### 1. Understanding the Business Requirements
14 Based on the given requirements, we need:
15 - **High-capacity data storage** for IoT data.
16 ...
17 ### Advantages of Cloud over On-Premises Architectures
18 - **Scalability**: Easily scale up/down based on demand without large capital expenditure.
19 - **Cost Efficiency**: Pay-as-you-go pricing.
20 - **High Availability**: Built-in options for redundancy and failover.
21 - **Global Reach**: Deploy services in multiple regions across the world.
22 - **Ease of Management**: Managed services reduce operational burden.
23 - **Innovation Velocity**: Rapid deployment of new services and features.
24 ...
25
26 ### Summary Table
27 
28| Criterion                     | AWS                                     | Azure                                      | GCP                                             |
29|-------------------------------|-----------------------------------------|--------------------------------------------|-------------------------------------------------|
30| **Primary Data Storage**      | Amazon S3, DynamoDB                    | Azure Blob Storage, Cosmos DB              | Google Cloud Storage, Bigtable         |          
31| **Real-time Analytics**       | Amazon Kinesis                            | Azure Stream Analytics                     | Google Cloud Dataflow                |               
32| **Machine Learning**          | Amazon SageMaker                       | Azure Machine Learning                     | Google AI Platform     
33 .....

然后,云計算架構師根據提供的需求列出每個云計算提供商的相關服務,解釋云計算相對于內部部署的優勢,并提供一個匯總表。

接下來是第二位發言者。開源架構師遵循大致相同的方法,列出相關服務,討論開源的優點,并給出自己的解決方案。

Plain Text 
1 Next speaker: oss
2
3 oss (to chat_manager):
4
5 ### Chain-of-Thought Approach
6
7 #### 1. Understanding the Business Requirements
8 ....
9 ### Advantages of Open-Source Adoption
10 - **Cost Savings**: No licensing fees.
11 - **Community Support**: Large active communities for troubleshooting and inquiries.
12- **Flexibility and Customization**: Ability to modify source code to meet unique business needs.
13- **Innovation**: Rapid adoption of cutting-edge technologies and features.
14 ...
15
16 ### Summary Table
17
18| Requirement                  | Solution Components         |                                                                                                                                             
19|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
20| **Data Storage**             | Apache Cassandra, HDFS      |                                                                                                                                               
21| **Real-time Analytics**      | Apache Kafka, Apache Flink, Apache Spark   |                                                                                                                                                
22| **Machine Learning**         | TensorFlow                  |                                                                                                                                                  
23| **Scalability**              | Kubernetes, Docker             |                                                                                                                                            
24| **Disaster Recovery Regions** | Primary: Germany (Berlin), Secondary: Netherlands (Amsterdam)  |
25| **Monitoring**               | Prometheus, Grafana, ELK Stack (Elasticsearch, Logstash, Kibana) 
26 ...

最后,首席架構師介入,對各種解決方案的優缺點進行分析,利用適用性矩陣等方法進行評估,并提出最終建議:

Plain Text 
1 Next speaker: lead
2
3 lead (to chat_manager):
4
5 ### Evaluating Solutions Based on the Business Requirements and Best Practices
6
7 #### Analysis and Comparison of Proposed Architectures
8
9| **Criterion**                     | **AWS**                                                       | **Azure**                                                     | **GCP**                                                        | **Open-Source**                                              |
10|-----------------------------------|----------------------------------------------------------------|----------------------------------------------------------------|----------------------------------------------------------------|---------------------------------------------------------------|
11| **Primary Data Storage**          | Amazon S3, DynamoDB                                            | Azure Blob Storage, Cosmos DB                                  | Google Cloud Storage, Bigtable                                 |   Apache Cassandra, HDFS |                                        
12| **Real-time Analytics**           | Amazon Kinesis                                                 | Azure Stream Analytics                                       | Google Cloud Dataflow                                          | Apache Kafka, Apache Flink                                     |
13| **Machine Learning**              | Amazon SageMaker                                               | Azure Machine Learning                                       | Google AI Platform                                             | TensorFlow                                                     |
14 ...
15
16 ### Advantages and Disadvantages
17 ...
18
19 #### Recommendation:
20
21 Based on the evaluation, here is a recommendation considering the timeline of 6 months, the requirements for scalability, disaster recovery, machine learning, and cost optimization:
22
23 - **Primary Recommendation**: **AWS**
24  - **Reasoning**: AWS provides a highly-integrated suite of services that are easy to deploy rapidly. They have strong support for both real-time analytics and machine learning. AWS offers robust monitoring tools and several options for cost optimization, which are fully managed, reducing the operational overhead and the complexity of the setup. They have a well-established global presence with region pairs suitable for disaster recovery.
25
26 - **Secondary Recommendation**: **Azure**
27  - **Reasoning**: If there is a heavier reliance on Microsoft ecosystems within the current infrastructure, Azure would be a suitable alternative. Azure provides strong support for machine learning, analytics, and disaster recovery and offers robust monitoring tools similar to AWS.
28
29 - **Alternative Consideration**: **GCP** for organizations already invested in Google technologies or with a requirement for industry-leading machine learning and data analytics capabilities.
30
31 - **Open-Source Option**: While it might be cost-effective and avoid vendor lock-in, the complexity, high maintena

需要注意的是,首席架構師表達的意見都是他自己的意見,并不一定反映本文作者的意見。

結語

這次實驗使用簡單的設置,創建了一個基本的架構團隊組織,其中不同類型的參與者相互協作為業務提供解決方案。

架構師不僅僅是提供技術層面的建議,他們經常面對復雜且獨特的挑戰,這要求他們對業務需求有深刻的理解,并對長期影響進行批判性思考。而人工智能在處理某些無形因素方面還存在一些局限,這主要歸因于它缺乏必要的人際交往能力和情商,至少目前是這樣。

原文標題:??Multi-Agent Conversation With AutoGen AI???,作者:Tony Siciliani


?著作權歸作者所有,如需轉載,請注明出處,否則將追究法律責任
已于2024-12-5 09:19:36修改
收藏
回復
舉報
回復
相關推薦
主站蜘蛛池模板: www.日韩av.com| 免费黄网站在线观看 | 欧美一区二区三区久久精品 | 国产色婷婷精品综合在线手机播放 | 99热精品国产 | 亚洲精品国产综合区久久久久久久 | 伊人网站 | 99久久精品国产毛片 | 欧美一区二区三区小说 | 久久成人高清视频 | 成人自拍视频网站 | 亚洲区一区二 | 91久久精品一区二区三区 | 精品一区久久 | 免费成人高清在线视频 | 日韩av在线一区 | 精品成人在线 | 日韩二 | 日韩网站免费观看 | 亚洲欧美日韩精品久久亚洲区 | 亚洲福利一区二区 | 精品不卡 | 免费在线视频精品 | 黑人性hd| 色网在线观看 | 日本亚洲欧美 | 久久99精品久久 | 亚洲91精品 | 久久久久久天堂 | 日韩中文字幕一区二区 | 91激情视频 | 亚洲精品视频免费观看 | 久久久久一区二区三区四区 | 欧美色视频免费 | 日韩精品一区二区三区免费视频 | 日韩一区二区在线看 | 欧美一区2区三区3区公司 | 久久这里有精品 | 国产午夜精品视频 | 精品久久久久久久人人人人传媒 | 在线看片网站 |