跟随模式
跟随者模式是 UFO 的一个功能,代理会遵循预定义的自然语言步骤列表,对应用程序执行操作。与普通模式不同,此模式会创建一个 FollowerAgent
,它遵循用户提供的计划列表与应用程序交互,而不是自行生成计划。此模式对于调试、软件测试或验证非常有用。
快速入门
步骤 1:创建计划文件
在启动跟随者模式之前,您需要创建一个计划文件,其中包含代理要遵循的步骤列表。计划文件是一个 JSON 文件,包含以下字段:
字段 | 描述 | 类型 |
---|---|---|
task | 任务描述。 | 字符串 |
steps | 代理要遵循的步骤列表。 | 字符串列表 |
object | 要与之交互的应用程序或文件。 | 字符串 |
以下是计划文件的示例:
{
"task": "Type in a text of 'Test For Fun' with heading 1 level",
"steps":
[
"1.type in 'Test For Fun'",
"2.Select the 'Test For Fun' text",
"3.Click 'Home' tab to show the 'Styles' ribbon tab",
"4.Click 'Styles' ribbon tab to show the style 'Heading 1'",
"5.Click 'Heading 1' style to apply the style to the selected text"
],
"object": "draft.docx"
}
注意
object
字段是代理将与之交互的应用程序或文件。启动跟随者模式时,该对象必须处于活动状态(可以最小化)。
步骤 2:启动跟随者模式
要启动跟随者模式,请运行以下命令:
# assume you are in the cloned UFO folder
python ufo.py --task_name {task_name} --mode follower --plan {plan_file}
提示
将 {task_name}
替换为任务名称,将 {plan_file}
替换为计划文件的路径。
步骤 3:批量运行(可选)
您还可以通过提供包含多个计划文件的文件夹,以批处理模式运行跟随者模式。代理将逐个遵循文件夹中的计划。要以批处理模式运行,请运行以下命令:
# assume you are in the cloned UFO folder
python ufo.py --task_name {task_name} --mode follower --plan {plan_folder}
UFO 将自动检测文件夹中的计划文件并逐个运行它们。
提示
将 {task_name}
替换为任务名称,将 {plan_folder}
替换为包含计划文件的文件夹路径。
评估
您可能希望通过遵循计划来评估 task
是否成功完成。如果 config_dev.yaml
文件中将 EVA_SESSION
设置为 True
,UFO 将调用 EvaluationAgent
来评估任务。
您可以在 logs/{task_name}/evaluation.log
文件中查看评估日志。
参考资料
跟随者模式采用 PlanReader
来解析计划文件,并创建 FollowerSession
来遵循计划。
PlanReader
PlanReader
位于 ufo/module/sessions/plan_reader.py
文件中。
用于计划文件的读取器。
初始化计划读取器。
参数 |
|
---|
源代码在 module/sessions/plan_reader.py
中
18 19 20 21 22 23 24 25 26 27 28 |
|
get_close()
检查计划是否已关闭。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
30 31 32 33 34 35 36 |
|
get_host_agent_request()
获取主机代理的请求。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
get_host_request()
获取主机代理的请求。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
get_initial_request()
获取计划中的初始请求。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
62 63 64 65 66 67 68 69 70 71 72 73 |
|
get_operation_object()
获取步骤中的操作对象。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
54 55 56 57 58 59 60 |
|
get_root_path()
获取计划的根路径。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
148 149 150 151 152 153 154 |
|
get_steps()
获取计划中的步骤。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
46 47 48 49 50 51 52 |
|
get_support_apps()
获取计划中的支持应用程序。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
103 104 105 106 107 108 109 |
|
get_task()
获取任务名称。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
38 39 40 41 42 43 44 |
|
next_step()
获取计划中的下一步。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
128 129 130 131 132 133 134 135 136 137 138 |
|
task_finished()
检查任务是否已完成。
返回 |
|
---|
源代码在 module/sessions/plan_reader.py
中
140 141 142 143 144 145 146 |
|
FollowerSession
FollowerSession
也位于 ufo/module/sessions/session.py
文件中。
基类:BaseSession
一个用于遵循操作计划列表的会话。此会话用于跟随者代理,它接受计划文件以使用 PlanReader 进行遵循。
初始化会话。
参数 |
|
---|
源代码在 module/sessions/session.py
中
285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
create_new_round()
创建一个新回合。
源代码在 module/sessions/session.py
中
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
next_request()
获取新一轮的请求。
源代码在 module/sessions/session.py
中
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
request_to_evaluate()
获取要评估的请求。返回:要评估的请求。
源代码在 module/sessions/session.py
中
371 372 373 374 375 376 377 |
|