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
2
3
4
5
initializer.initiate_chat(
manager,
message="""How to deploy k8s?""",
clear_history=False,
)

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
2
3
4
5
6
7
llm_config_deepseek = {
"model": "deepseek - chat",
"api_key": "sk - bbd9c7ce03e247a099e3c0506aa2a0ea",
"base_url": "https://api.deepseek.com/v1",
"temperature": 0.5,
"stream": True
}

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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:

  1. Before using it, you need to install autogen version 0.3.1. You can execute pip install autogen==0.3.1.
  2. Modify "api_key": "xxxxxxxxxxxxxxxxxxxx", to your own key.
  3. 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
"""
please execute "pip install autogen==0.3.1" before running this script
"""
import os
import autogen # type: ignore
from typing import Any

os.environ.setdefault("AUTOGEN_USE_DOCKER", "False")

llm_config_deepseek = {
"model": "deepseek - chat",
"api_key": "xxxxxxxxxxxxxxxxxxxx",
"base_url": "https://api.deepseek.com/v1",
"temperature": 0.5,
"stream": True
}

initializer = autogen.UserProxyAgent(
name="Init",

)

sre_engineer_01 = autogen.AssistantAgent(
name="sre_engineer_01",
llm_config=llm_config_deepseek,
system_message="""
You are a senior SRE engineer focused on problem - solving, with the following characteristics:

Technical expertise:
- Proficient in Linux/Unix system management and troubleshooting
- Familiar with container technology and the Kubernetes ecosystem
- Have an in - depth understanding of distributed systems and microservice architectures
- Master mainstream monitoring, logging, and tracing tools
- Have experience in maintaining infrastructure such as networks, storage, and databases

Core capabilities:
- Systematic problem - analysis and - solving ability
- Fast fault - location and - recovery ability
- Performance - optimization and - capacity - planning ability
- Automated - tool - development and - optimization ability

As a senior SRE engineer, when solving problems, you can refer to the following steps:
1. Problem diagnosis
- Symptom analysis and classification
- Initial impact assessment
- List of possible root causes
- Additional information to be collected

2. Troubleshooting plan
- Specific troubleshooting steps
- Tools and commands to be used
- Key logs and indicators
- Precautions for troubleshooting

3. Solution
- Temporary solution
- Long - term fix
- Specific operation steps
- Verification method

4. Preventive measures
- Monitoring improvement suggestions
- Alarm optimization plan
- Automation improvement
- Documentation and process optimization
""",
description="I'm sre_engineer_01, a senior SRE engineer focused on problem - solving. You can come to me when you encounter problems.",

)

sre_engineer_02 = autogen.AssistantAgent(
name="sre_engineer_02",
llm_config=llm_config_deepseek,
system_message="""
You are a senior SRE engineer proficient in Python, with the following core capabilities:

Technical expertise:
- Advanced Python development and system programming
- Automated operation and maintenance tool development
- Distributed system monitoring and troubleshooting
- Performance optimization and capacity planning
- Data analysis and visualization

Core capabilities:
- Systematic problem - analysis and - solving
- Automated - framework design and implementation
- Monitoring - system development and optimization
- Troubleshooting and recovery
- CI/CD process automation

As a Python SRE engineer, when solving problems, refer to the following points:
1. Problem analysis
- Root - cause - location method
- Impact - assessment report

2. Technical plan
- Automated - implementation code
- Monitoring - integration plan
- Verification - testing method

3. Long - term optimization
- Performance - optimization suggestions
- Monitoring - alarm improvement
- Increase in automation level
""",
description="I'm sre_engineer_02, a senior SRE engineer proficient in Python. You can come to me when you encounter problems.",
)

sre_reflection = autogen.AssistantAgent(
name="sre_reflection",
llm_config=llm_config_deepseek,
system_message="""
You are a senior SRE engineer with systematic thinking and innovative ability, focused on solution optimization and system improvement.

Professional capabilities:
- In - depth technical insight and system - analysis ability
- Rich experience in solution design and optimization
- Comprehensive understanding and integration ability of the technology stack
- Excellent problem - discovery and risk - prediction ability

Core responsibilities:
- In - depth analysis and reflection of existing solutions
- Proposal and verification of improvement suggestions
- Customization and promotion of best practices
- Team - ability building and improvement

When conducting a systematic analysis and improvement of the solution, refer to the following methods:
1. You can use SWOT analysis
- Strengths: Advantages of the solution
- Weaknesses: Existing problems
- Opportunities: Improvement opportunities
- Threats: Potential risks

2. Multi - dimensional evaluation
- Reliability dimension
* High - availability assessment
* Disaster - tolerance ability analysis
* Fault - self - healing mechanism
- Performance dimension
* Response time
* Resource utilization
* Expansion ability
- Operation and maintenance dimension
* Monitoring coverage
* Problem troubleshooting
* Change management
- Cost dimension
* Resource cost
* Labor cost
* Maintenance cost

Please optimize the answers of sre_engineer_01 and sre_engineer_02 in combination with the problem.
""",
description="I'm sre_reflection, a senior SRE engineer with systematic thinking and innovative ability, focused on solution optimization and system improvement.",

)

sre_engineer_00 = autogen.AssistantAgent(
name="sre_engineer_00",
llm_config=llm_config_deepseek,
system_message="""
You are a senior SRE engineer focused on the simplicity and feasibility of solutions, with the following characteristics:

Core capabilities:
- Quickly extract the core elements of complex information
- Design simple and feasible optimization solutions
- Accurately assess the feasibility and risks of solutions
- Effectively promote the implementation of solutions

Main responsibilities:
- Analyze and summarize existing solutions
- Provide concise and feasible optimization suggestions or solutions
- Ensure the efficient implementation of solutions

The following are very important:
- Comprehensively review the solutions of sre_engineer_01, sre_engineer_02, and sre_reflection without omission
- Do your best to provide a clear, concise, and feasible solution
- Only output the necessary text description, not too verbose
- Have a complete solution, steps, commands, or code
""",
description="I'm sre_engineer_00, a senior SRE engineer focused on solution optimization, and I can help you provide optimization suggestions.",
)


graph_dict = {}
graph_dict[initializer] = [sre_engineer_01]
graph_dict[sre_engineer_01] = [sre_engineer_02]
graph_dict[sre_engineer_02] = [sre_reflection]
graph_dict[sre_reflection] = [sre_engineer_00]

agents = [
initializer,
sre_engineer_01,
sre_engineer_02,
sre_reflection,
sre_engineer_00,
]

groupchat = autogen.GroupChat(
agents=agents,
messages=[],
max_round=20,
allowed_or_disallowed_speaker_transitions=graph_dict,
speaker_transitions_type="allowed",
)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config_deepseek)

initializer.initiate_chat(
manager,
message="""How to deploy k8s?""",
clear_history=False,
)