ollama autogen

本文介绍了如何在Python环境中创建一个多角色对话场景,涉及AssistantAgent、CoderAgent和UserProxyAgent,通过LLM模型执行任务,如生成并运行1到100的数列脚本。
摘要由CSDN通过智能技术生成

原文地址

https://gist.github.com/mberman84/ea207e7d9e5f8c5f6a3252883ef16df3
import autogen
from autogen.agentchat.contrib.retrieve_assistant_agent import RetrieveAssistantAgent
from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json, GroupChat, GroupChatManager
import chromadb
import os
from autogen import GroupChat
import json
from autogen.retrieve_utils import TEXT_FORMATS

######################################################################
config_list_mistral = [
    {
        "base_url": "http://localhost:35666/v1",
        "api_key": "sk-111111111111",        
        "model": "TheBloke/Llama-2-7B-32K-Instruct-GGUF"
    }
]

config_list_codellama = [
    {
        "base_url": "http://localhost:8000/v1",
        "api_key": "sk-111111111111",        
        "model": "TheBloke/Llama-2-7B-32K-Instruct-GGUF"
    }
]
######################################################################
llm_config_mistral={
    "config_list": config_list_mistral,
}

llm_config_codellama={
    "config_list": config_list_codellama,
}
######################################################################
llm_config_mistral = llm_config_mistral
llm_config_codellama = llm_config_codellama
######################################################################
assistant = autogen.AssistantAgent(
    name="Assistant",
    llm_config=llm_config_mistral,
    # code_execution=False # Disable code execution entirely
    code_execution_config={"work_dir":"coding", "use_docker":False}
)

coder = autogen.AssistantAgent(
    name="Coder",
    llm_config=llm_config_codellama,
    # code_execution=False # Disable code execution entirely
    code_execution_config={"work_dir":"coding", "use_docker":False}
)

user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    #human_input_mode="TERMINATE",
    max_consecutive_auto_reply=10,
    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
    code_execution_config={"work_dir": "coding", "use_docker":False},
    llm_config=llm_config_mistral,
    system_message="""Reply TERMINATE if the task has been solved at full satisfaction.
Otherwise, reply CONTINUE, or the reason why the task is not solved yet."""
)

task="""
Write a python script to output numbers 1 to 100 and then the user_proxy agent should run the script
"""

#task="""
#Write a script to output numbers 1 to X where X is a random number generated by the user_proxy agent
#"""

#user_proxy.initiate_chat(coder, message=task)  # Simple chat with coder

groupchat = autogen.GroupChat(agents=[user_proxy, coder, assistant], messages=[], max_round=12)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config_mistral)
user_proxy.initiate_chat(manager, message=task)
  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Autogen multiagent是一种自动生成多智能体系统的方法。 在传统的多智能体系统中,需要手动设计和编写每个智能体的行为规则和决策策略。这样做的问题是,当系统需要扩展或修改时,需要手动调整每个智能体的规则和策略,非常耗时和困难。而autogen multiagent方法则通过自动生成智能体系统的规则和策略,极大地简化了系统的设计和维护过程。 具体实现autogen multiagent的方法有多种。一种常用的方法是基于机器学习和优化算法。系统首先采用机器学习算法对智能体的行为规则进行训练,让系统能够从大量的实例中学习合适的决策策略。然后,使用优化算法对系统中的智能体进行优化,并自动调整它们的规则和策略,以实现更高的性能和效率。 另一种实现autogen multiagent的方法是基于进化算法。系统首先通过随机生成一组智能体的规则和策略作为初始种群,然后使用进化算法对这些智能体进行迭代优化。在每一代中,系统通过评估智能体的性能选择出适应度高的个体,并通过交叉和变异等遗传操作生成新的智能体。通过不断迭代优化,系统可以自动生成合适的智能体规则和策略。 总的来说,autogen multiagent实现是一种通过机器学习、优化算法或进化算法等方法自动生成多智能体系统的规则和策略的方法。它可以大大简化多智能体系统的设计和维护过程,并且能够在系统性能和效率方面取得更好的结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值