Introduction to a Simple Application Case of Large Language Model Multi - Agents
Explanation of Multi - Agent Roles
Recently, I’ve been exploring the application scenarios of LLM Multi Agent (Multi - Agents). Here is a case that I found quite useful and not too complicated recently.
This is a script written based on Microsoft’s AutoGen framework (for better readability, the complete code is placed at the end of the blog).
In this script, I take solving SRE requirements as a case. There are a total of 4 Agents, which can be thought of as 4 SRE engineers, but their areas of expertise are not exactly the same.
- sre_engineer_01 This is a senior SRE engineer, more focused on operations and maintenance, that is, manually executing commands and the like. He is good at solving online problems.
- sre_engineer_02 This role is an SRE engineer proficient in Python development. He is good at writing code and automating processes and operations.
- sre_reflection This role is for reflection. He will review the answers of the previous two Agents, identify problems, and provide optimization suggestions.
- sre_engineer_00 This role is mainly used to summarize the answers of the first 3 Agents and finally provide a clear, concise, and feasible solution.
You can modify the message
in the last paragraph of the script and input your own question, such as “How to deploy k8s?” here. Then execute the script, and it will give the answers of the above 4 Agents one by one in the command - line window. If you think it’s too verbose, you can just look at the last one. But from a learning perspective, it is recommended to look at all of them, as the answers given by different Agents are quite different.
1 | initializer.initiate_chat( |
Selection of Large Language Models
In this script, I used DeepSeek (I’m really a big fan of DeepSeek…), as shown in the following code.
1 | llm_config_deepseek = { |
And I only used this one model. However, from my personal experience, using multiple different models can yield better results. I think it may be because the algorithm architectures, training processes, and training data of each model are different, so the final effects are also different. Using different models can obtain greater diversity, and after the final summary, the effect will be better.
If you choose domestic models, besides DeepSeek, the Tongyi and Doubao series of models are also quite good. You can refer to the above code for configuration. However, if possible, it is more recommended to use gpt4o, claude - 3.5 - sonnot, and gemini - 1.5 - pro, one of these three or all of them.
Applicable Scenarios
In order to make this script as simple as possible to use, I didn’t add many functions, such as automatic command execution and human intervention. So this script is currently more suitable for relatively independent and complete problems, such as the above “How to deploy k8s”. It is not very suitable for handling online problems. It’s not that it can’t handle them, but it requires constant switching between the online environment and this script, which is very troublesome.
In addition to the 4 prompts for SRE written in the script, in fact, by modifying the Prompt, it can be used in many other scenarios.
The logic for writing Agents is roughly as follows:
- At the beginning, set up a planning or architecture Agent. It can refine the details of the user - input problem and also provide a general idea for other Agents later. In the above case, I didn’t set one up because in the SRE scenario, setting up a planning Agent would result in very long - winded answers.
- Then set up two Agents for doing the actual work. But their Prompts should not be exactly the same, and it’s better to use large language models from different companies for these two Agents. For example, sre_engineer_01 and sre_engineer_02 above. The recommended number here is 2 or 3. Setting 1 usually doesn’t work as well as 2, and setting more than 3 seems too complicated.
- Set up a special - purpose optimization Agent. There is no such Agent in the above case. Suppose you want to optimize an article now, you can set up an SEO - optimizing Agent. This is a special - purpose Agent, and such Agents are set according to needs.
- End with a summary - type Agent. It can summarize based on the initial task and the answers of the intermediate Agents and give the final answer.
Code
Here is the full text of the code.
There are three points to note about the code:
- Before using it, you need to install autogen version 0.3.1. You can execute
pip install autogen==0.3.1
. - Modify
"api_key": "xxxxxxxxxxxxxxxxxxxx",
to your own key. max_round = 20
means that an Agent is allowed to speak at most 20 times. If you modify the script and want to add human input or increase the number of times an Agent can speak, you may need to modify this upper limit.
1 | """ |