A First Try at AutoGen
Introduction to AutoGen
AutoGen was first created in FLAML (A Fast Library for Automated Machine Learning & Tuning) on May 29, 2023. It is an open - source framework for building AI Agents and simplifying the cooperation of multiple Agents. Currently, it is mainly developed by Microsoft, Pennsylvania State University, and the University of Washington. The goal of AutoGen is to provide an easy - to - use and flexible framework for the development and research of generative AI.
In the official introduction of AutoGen, it compares itself to generative AI as PyTorch is to deep learning.
There are many definitions of Agents. In AutoGen, an Agent is an entity that can receive messages, send messages, and generate responses using one or more of large language models, tools, and human input.
AutoGen is developed by numerous researchers and engineers. It incorporates the latest achievements in multi - agent research and has been applied to many practical applications, such as investment, AI employees, writing, blockchain, customer service, cybersecurity, data analysis, etc.
Initial Attempt
Before using it, you need to install it first.
1 | pip install pyautogen |
The following is a sample code. In the code, I used Azure OPENAI gpt - 4o. You can run it by replacing the variables with your real values.
1 | import os |
The execution result is as follows:
1 | user_proxy (to assistant): |
This code defines a simple environment and two cooperative agents. Each agent performs a simple action until the goal state of the environment is reached. In this way, the basic concept of multi - agent collaboration is demonstrated.
I hope this information is helpful to you! If you have any other questions, feel free to continue asking. TERMINATE
1 |
|
The following is the return:
1 | user_proxy (to assistant): |
This script will output the system version information, CPU information, and memory information. Please execute the script and let me know the result.
--------------------------------------------------------------------------------
Replying as user_proxy. Provide feedback to assistant. Press enter to skip and use auto - reply, or type 'exit' to end the conversation:
NO HUMAN INPUT RECEIVED.
USING AUTO REPLY...
EXECUTING CODE BLOCK (inferred language is sh)... user_proxy (to assistant):
exitcode: 0 (execution succeeded)
Code output: No LSB modules are available.
System version information:
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
-e
CPU information:
Architecture: x86_64
CPU op - mode(s): 32 - bit, 64 - bit
Byte Order: Little Endian
Address sizes: 39 bits physical, 48 bits virtual
CPU(s): 8
On - line CPU(s) list: 0 - 7
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 142
Model name: Intel(R) Core(TM) i7 - 10610U CPU @ 1.80GHz
Stepping: 12
CPU MHz: 2304.007
BogoMIPS: 4608.01
Virtualization: VT - x
Hypervisor vendor: Microsoft
Virtualization type: full
L1d cache: 128 KiB
L1i cache: 128 KiB
L2 cache: 1 MiB
L3 cache: 8 MiB
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
Vulnerability Srbds: Mitigation; TSX disabled
Vulnerability Tsx async abort: Mitigation; TSX disabled
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid ept_ad fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves md_clear flush_l1d arch_capabilities
-e
Memory information:
total used free shared buff/cache available
Mem: 7.6Gi 2.6Gi 3.5Gi 34Mi 1.5Gi 4.7Gi
Swap: 2.0Gi 0B 2.0Gi
--------------------------------------------------------------------------------
assistant (to user_proxy):
Based on the output information you provided, I can summarize the current system version, CPU, and memory information as follows:
### System Version Information
- **Publisher**: Ubuntu
- **Version Description**: Ubuntu 20.04.4 LTS
- **Release Version**: 20.04
- **Codename**: focal
### CPU Information
- **Architecture**: x86_64
- **Operation Mode**: 32 - bit, 64 - bit
- **Byte Order**: Little Endian
- **Number of CPUs**: 8
- **Online CPU List**: 0 - 7
- **Number of Threads per Core**: 2
- **Number of Cores per Socket**: 4
- **Number of Sockets**: 1
- **Vendor ID**: GenuineIntel
- **CPU Family**: 6
- **Model**: 142
- **Model Name**: Intel(R) Core(TM) i7 - 10610U CPU @ 1.80GHz
- **Stepping**: 12
- **CPU Frequency**: 2304.007 MHz
- **Virtualization**: VT - x
### Memory Information
- **Total Memory**: 7.6 GiB
- **Used Memory**: 2.6 GiB
- **Free Memory**: 3.5 GiB
- **Shared Memory**: 34 MiB
- **Buffered/Cached**: 1.5 GiB
- **Available Memory**: 4.7 GiB
- **Swap Partition**: 2.0 GiB (unused)
This information can help you understand the basic situation of the current system. Please let me know if there is anything else I can help with.
TERMINATE
As you can see, AutoGen can indeed execute code. In this way, **AutoGen has the ability to interact with the physical world to a certain extent**, and can do more things.
AutoGen has two ways to execute code. One is to execute directly in the current environment (Local Execution), just like in the above case; the other is to execute in a container (Docker Execution), mainly for security reasons, worrying that the code generated by the large language model has security issues.
## Multi Agents
The two cases above are single - agent. AutoGen supports multiple agents. The following is a multi - agent case. In this case, I set up two agents, one is a Python developer role, and the other is a front - end developer role. Let them develop a personal blog website. The code is as follows:
```python
import os
import autogen
from autogen import AssistantAgent, UserProxyAgent
from autogen import ConversableAgent
llm_config = {
"model": "gpt - 4o",
"api_key": os.environ.get("OPENAI_API_KEY"),
"base_url": os.environ.get("OPENAI_API_BASE"),
"api_type": "azure",
"api_version": "2023 - 03 - 15 - preview",
"temperature": 0.9,
}
cathy = ConversableAgent(
"cathy",
system_message="""
You are an expert in Python development, proficient in Python syntax, good at writing high - performance and easy - to - maintain Python code, and proficient in frameworks such as Django, Django Rest Framework, FastAPI, as well as VUE3 and ElementPlus development. Please complete the development tasks I assign to you.
You are good at choosing and selecting the best tools and try your best to avoid unnecessary repetition and complexity.
Please complete the tasks I assign to you. When solving problems, you will break the problem into small problems and improvement items, and suggest small tests after each step to ensure that things are on the right track.
If there is anything unclear or ambiguous, you will always ask for clarification. You will pause the discussion to weigh and consider implementation options if there is a need to make a choice.
It is important that you follow this method and do your best to teach your interlocutor how to make effective decisions. You avoid unnecessary apologies and do not repeat earlier mistakes when reviewing the conversation.
""",
llm_config = llm_config,
human_input_mode="NEVER", # Never ask for human input.
)
joe = ConversableAgent(
"joe",
system_message="""
You are an expert in web development, including CSS, JavaScript, React, Tailwind, Node.JS, and Hugo/Markdown. You are good at choosing and selecting the best tools and try your best to avoid unnecessary repetition and complexity.
When making suggestions, you break things down into discrete changes and suggest small tests after each stage to ensure that things are on the right track.
Write code to illustrate examples or write code when instructed in the conversation. If you can answer without code, this is preferred, and you will be asked to elaborate when necessary.