DEV Community

Nari
Nari

Posted on • Updated on

How to Use Microsoft AutoGen

Introduction

I tried AutoGen, an open source software published by Micorsoft.

https://github.com/microsoft/autogen

Reference Documents

Official Documents
https://microsoft.github.io/autogen/docs/getting-started

FAQ
https://microsoft.github.io/autogen/docs/FAQ/

Multi-agent Conversation Framework
https://microsoft.github.io/autogen/docs/Use-Cases/agent_chat/


Sample code

This time, considering the cost, I experimented with only gpt-3.5-turbo, with multiple agents just chatting. We also set max_round=4 for the number of conversations.

install
Python version >= 3.8

pip install pyautogen
Name: pyautogen
Version: 0.2.15
Enter fullscreen mode Exit fullscreen mode

Create File
Create a directory (e.g. test_autogen)

  • /test_autogen/OAI_CONFIG_LIST
  • /test_autogen/app/test.py

OAI_CONFIG_LIST
Do not add extensions to file names.
Describe OpenAI's API KEY information.
For an overview of LLM configurations and other implementation methods, please see below.
https://microsoft.github.io/autogen/docs/llm_configuration/

[
  {
    "model": "gpt-3.5-turbo-1106",
    "api_key": ""**********""
  },
  {
    "model": "gpt-3.5-turbo-0125",
    "api_key": "**********"
  }
]
Enter fullscreen mode Exit fullscreen mode

test.py

import autogen

# OAI_CONFIG_LIST
config_list_gpt = autogen.config_list_from_json(
   "OAI_CONFIG_LIST",
   file_location="..",
   # optional
   # filter_dict={
   #     "model": {
   #         "gpt-3.5-turbo-0125",
   #     }
   # },
)

llm_config = {
   "config_list": config_list_gpt,
   "seed": 10,
   "temperature": 0.7,
}

# This time, we experimented without using user_proxy.
# user_proxy = autogen.UserProxyAgent(
#     name="User_proxy",
#     system_message="A human admin.",
#     code_execution_config={"last_n_messages": 2, "work_dir": "groupchat"},
#     human_input_mode="TERMINATE",
# )
agent_a = autogen.AssistantAgent(
    name="Agent-A",
    system_message="You love French food.",
    llm_config=llm_config,
)
agent_b = autogen.AssistantAgent(
    name="Agent-B",
    system_message="You love Japanese food!",
    llm_config=llm_config,
)
agent_c = autogen.AssistantAgent(
    name="Agent-C",
    system_message="You love Chinese food!",
    llm_config=llm_config,
)

groupchat = autogen.GroupChat(
    agents=[agent_a, agent_b, agent_c], messages=[], max_round=4
)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)

manager.initiate_chat(manager, message="Chatting about food.")

Enter fullscreen mode Exit fullscreen mode

Execute from a terminal.
python test.py

Output Result
Conversations were generated up to the specified number of times.

python test.py
chat_manager (to chat_manager):

Chatting about food.

--------------------------------------------------------------------------------
Agent-A (to chat_manager):

Yes, I absolutely love French food! The rich flavors, delicate techniques, and exquisite presentation of French cuisine never fail to impress me. From classic dishes like coq au vin and boeuf bourguignon to the indulgent pastries like croissants and macarons, French food is a true delight for the senses. The use of fresh, high-quality ingredients and the emphasis on balance and harmony in flavors make every bite a memorable experience. Whether it's a simple bistro meal or a fancy Michelin-starred restaurant, French food always brings me joy.

--------------------------------------------------------------------------------
Agent-B (to chat_manager):

That sounds absolutely delicious! French cuisine is renowned for its elegance and sophistication. The way they elevate simple ingredients into masterpieces is truly remarkable. The buttery croissants, rich sauces, and perfectly cooked meats are just a few examples of the culinary excellence that French cuisine offers. It's no wonder that French food is considered one of the finest in the world. Do you have a favorite French dish?

--------------------------------------------------------------------------------
Agent-C (to chat_manager):

It's hard to choose just one favorite French dish, but if I had to pick, it would probably be coq au vin. The tender chicken braised in red wine with onions, mushrooms, and herbs is simply divine. The flavors are rich and complex, and the dish is incredibly comforting. It's a classic French dish that never fails to impress. How about you? Do you have a favorite French dish?

Enter fullscreen mode Exit fullscreen mode

Conclusion

GroupChat was easy to implement with sample code.

This time it was just a conversation between AIs with no particular meaning, but there are several examples of using GPT-4, such as automatic task resolution for code generation, so it seems that something interesting can be created.

Top comments (0)