追随者智能体 🚶🏽‍♂️

FollowerAgent 继承自 AppAgent,负责根据用户的指令在应用程序内执行特定任务。FollowerAgent 旨在根据用户的指导执行一系列动作。它对于软件测试特别有用,当提供明确的指令来验证应用程序的行为时。

与 AppAgent 的区别

FollowerAgentAppAgent 共享大部分功能,但它的设计是为了遵循用户提供的分步指令,而不是自己推理以确定下一步动作。

用法

FollowerAgentfollower 模式可用。您可以在文档中找到更多详细信息。它还使用不同的 SessionProcessor 来处理用户的指令。用户在 json 文件中提供分步指令,然后由 FollowerAgent 解析该文件以执行动作。json 文件示例如下所示

{
    "task": "Type in a bold text of 'Test For Fun'",
    "steps": 
    [
        "1.type in 'Test For Fun'",
        "2.select the text of 'Test For Fun'",
        "3.click on the bold"
    ],
    "object": "draft.docx"
}

参考

基类:AppAgent

FollowerAgent 类是 FollowedAgent 的管理器,它遵循分步指令在应用程序中执行动作。它是 AppAgent 的子类,AppAgent 完成应用程序中的动作执行。

初始化 FollowAgent。

参数
  • name (str) –

    智能体的名称。

  • process_name (str) –

    应用程序的进程名称。

  • app_root_name (str) –

    应用程序的根名称。

  • is_visual (bool) –

    指示智能体是否可视的标志。

  • main_prompt (str) –

    主提示文件路径。

  • example_prompt (str) –

    示例提示文件路径。

  • api_prompt (str) –

    API 提示文件路径。

  • app_info_prompt (str) –

    应用程序信息提示文件路径。

源代码位于 agents/agent/follower_agent.py
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
def __init__(
    self,
    name: str,
    process_name: str,
    app_root_name: str,
    is_visual: bool,
    main_prompt: str,
    example_prompt: str,
    api_prompt: str,
    app_info_prompt: str,
):
    """
    Initialize the FollowAgent.
    :param name: The name of the agent.
    :param process_name: The process name of the app.
    :param app_root_name: The root name of the app.
    :param is_visual: The flag indicating whether the agent is visual or not.
    :param main_prompt: The main prompt file path.
    :param example_prompt: The example prompt file path.
    :param api_prompt: The API prompt file path.
    :param app_info_prompt: The app information prompt file path.
    """
    super().__init__(
        name=name,
        process_name=process_name,
        app_root_name=app_root_name,
        is_visual=is_visual,
        main_prompt=main_prompt,
        example_prompt=example_prompt,
        api_prompt=api_prompt,
        skip_prompter=True,
    )

    self.prompter = self.get_prompter(
        is_visual,
        main_prompt,
        example_prompt,
        api_prompt,
        app_info_prompt,
        app_root_name,
    )

get_prompter(is_visual, main_prompt, example_prompt, api_prompt, app_info_prompt, app_root_name='')

获取追随者智能体的提示器。

参数
  • is_visual (str) –

    指示智能体是否可视的标志。

  • main_prompt (str) –

    主提示文件路径。

  • example_prompt (str) –

    示例提示文件路径。

  • api_prompt (str) –

    API 提示文件路径。

  • app_info_prompt (str) –

    应用程序信息提示文件路径。

  • app_root_name (str, 默认值: '' ) –

    应用程序的根名称。

返回
  • FollowerAgentPrompter

    提示器实例。

源代码位于 agents/agent/follower_agent.py
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
def get_prompter(
    self,
    is_visual: str,
    main_prompt: str,
    example_prompt: str,
    api_prompt: str,
    app_info_prompt: str,
    app_root_name: str = "",
) -> FollowerAgentPrompter:
    """
    Get the prompter for the follower agent.
    :param is_visual: The flag indicating whether the agent is visual or not.
    :param main_prompt: The main prompt file path.
    :param example_prompt: The example prompt file path.
    :param api_prompt: The API prompt file path.
    :param app_info_prompt: The app information prompt file path.
    :param app_root_name: The root name of the app.
    :return: The prompter instance.
    """
    return FollowerAgentPrompter(
        is_visual,
        main_prompt,
        example_prompt,
        api_prompt,
        app_info_prompt,
        app_root_name,
    )

message_constructor(dynamic_examples, dynamic_knowledge, image_list, control_info, prev_subtask, plan, request, subtask, host_message, current_state, state_diff, blackboard_prompt, include_last_screenshot)

为 FollowAgent 构建提示消息。

参数
  • dynamic_examples (str) –

    从自我演示和人工演示中检索到的动态示例。

  • dynamic_knowledge (str) –

    从自我演示和人工演示中检索到的动态知识。

  • image_list (List[str]) –

    屏幕截图图像列表。

  • control_info (str) –

    控制信息。

  • prev_subtask (List[str]) –

    上一个子任务。

  • plan (List[str]) –

    计划。

  • request (str) –

    请求。

  • subtask (str">str) –

    子任务。

  • host_message (List[str]) –

    主机消息。

  • current_state (Dict[str, str]) –

    应用程序的当前状态。

  • state_diff (Dict[str, str]) –

    当前状态与之前状态之间的状态差异。

  • blackboard_prompt (List[Dict[str, str]]) –

    黑板提示。

  • include_last_screenshot (bool) –

    指示是否应包含最后一张屏幕截图的标志。

返回
  • List[Dict[str, str]]

    提示消息。

源代码位于 agents/agent/follower_agent.py
 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
def message_constructor(
    self,
    dynamic_examples: str,
    dynamic_knowledge: str,
    image_list: List[str],
    control_info: str,
    prev_subtask: List[str],
    plan: List[str],
    request: str,
    subtask: str,
    host_message: List[str],
    current_state: Dict[str, str],
    state_diff: Dict[str, str],
    blackboard_prompt: List[Dict[str, str]],
    include_last_screenshot: bool,
) -> List[Dict[str, str]]:
    """
    Construct the prompt message for the FollowAgent.
    :param dynamic_examples: The dynamic examples retrieved from the self-demonstration and human demonstration.
    :param dynamic_knowledge: The dynamic knowledge retrieved from the self-demonstration and human demonstration.
    :param image_list: The list of screenshot images.
    :param control_info: The control information.
    :param prev_subtask: The previous subtask.
    :param plan: The plan.
    :param request: The request.
    :param subtask: The subtask.
    :param host_message: The host message.
    :param current_state: The current state of the app.
    :param state_diff: The state difference between the current state and the previous state.
    :param blackboard_prompt: The blackboard prompt.
    :param include_last_screenshot: The flag indicating whether the last screenshot should be included.
    :return: The prompt message.
    """
    followagent_prompt_system_message = self.prompter.system_prompt_construction(
        dynamic_examples
    )
    followagent_prompt_user_message = self.prompter.user_content_construction(
        image_list=image_list,
        control_item=control_info,
        prev_subtask=prev_subtask,
        prev_plan=plan,
        user_request=request,
        subtask=subtask,
        current_application=self._process_name,
        host_message=host_message,
        retrieved_docs=dynamic_knowledge,
        current_state=current_state,
        state_diff=state_diff,
        include_last_screenshot=include_last_screenshot,
    )

    followagent_prompt_message = self.prompter.prompt_construction(
        followagent_prompt_system_message, followagent_prompt_user_message
    )

    return followagent_prompt_message