AutoGen提供了一个统一的多代理对话框架,作为使用基础模型的高级抽象。它的特点是功能强大、可定制且可对话的代理,这些代理通过自动代理聊天集成了llm、工具和人员。通过在多个有能力的代理之间自动化聊天,可以很容易地让它们共同自主地执行任务或使用人工反馈,包括需要通过代码使用工具的任务。
假设你已经按照需求安装了需要的环境,下面将会展示两个示例👇👇
1. 在Autogen的示例中,提供了两个agent的测试脚本,以下是运行方式:
cd test
python twoagent.py
有两个代理,用户让assistant画股票图,assistant给出了画的代码,但没有执行可视化展示
2.第二个例子是基于一个情景对话,让两个agent进行角色扮演:
system_message:扮演约翰。你现在正在参加新学期的开学典礼,碰巧遇到了你的新同学。你的任务是和新同学攀谈起来。为了更好地了解彼此,你可以问她的家乡,兴趣爱好,可以讨论家庭成员和其他相关的事情。你也可以谈论你未来的目标和过去的有趣经历。
user_message:你是安迪。你现在正在参加新学期的开学典礼,你刚刚遇到了一位新同学。为了开启一段新的友谊,你需要向他介绍自己。你可以告诉他你的家乡、兴趣、家庭成员以及其它相关细节。
由assistant先说第一句话,让用户来回答。代码参考如下:
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
import openai
# config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
assistant = AssistantAgent(
name = "assistant",
code_execution_config={"work_dir": "coding"},
llm_config={"model": "gpt-4", "api_key": "换成你自己的key"},
# human_input_mode="TERMINATE",
human_input_mode="NEVER",
max_consecutive_auto_reply=4,
system_message = "Act as a real human being John. You are now attending the opening ceremony of the new semester and happen to meet your new classmate. Your task is to strike up a conversation with the new classmate. To get to know each other better, you can ask her about her hometown, interests such as her favorite books, music and movies. ",
)
user_proxy = UserProxyAgent(
name = "user_proxy",
llm_config={"model": "gpt-4", "api_key": "换成你自己的key"},
human_input_mode="NEVER",
system_message = "You are Andy. You are currently attending the opening ceremony of a new semester, and you have just met a new classmate. To establish a new friendship, you need to introduce yourself to him. You can tell him about your hometown, interests, family members, and any other relevant details. ",
)
assistant.initiate_chat(
user_proxy,
message="Hello, I'm John. Are you new here?",
)
对话效果很不错🐮: