Instanziierung
Der Instanziierungsprozess umfasst drei Hauptschritte
- Wählen Sie eine
Vorlagendatei entsprechend der angegebenen App und Anweisung aus.
Füllen Sie die Aufgabe vorab aus anhand des aktuellen Screenshots.
Filtern Sie die erstellte Aufgabe.
Gegeben die initiale Aufgabe, wählt der Datenfluss zuerst eine Vorlage aus (Phase 1), füllt dann die initiale Aufgabe basierend auf der Wortumgebung vor, um Aufgaben-Aktionsdaten zu erhalten (Phase 2). Schließlich filtert er die erstellte Aufgabe, um die Qualität der Aufgaben-Aktionsdaten zu bewerten.
1. Vorlagendatei auswählen
Vorlagen für Ihre App müssen in dataflow/templates/app definiert und beschrieben werden. Wenn Sie beispielsweise Aufgaben für die Word-Anwendung instanziieren möchten, legen Sie die relevanten .docx-Dateien in dataflow /templates/word ab, zusammen mit einer description.json-Datei. Die passende Vorlage wird basierend darauf ausgewählt, wie gut ihre Beschreibung mit der Anweisung übereinstimmt.
Der ChooseTemplateFlow verwendet semantische Abgleichverfahren, bei denen Aufgabenbeschreibungen mit Vorlagenbeschreibungen mithilfe von Embeddings und FAISS für eine effiziente Suche nach nächsten Nachbarn verglichen werden. Wenn der semantische Abgleich fehlschlägt, wird eine zufällige Vorlage aus den verfügbaren Dateien ausgewählt.
2. Aufgabe vorab ausfüllen
PrefillFlow
Die Klasse PrefillFlow orchestriert die Verfeinerung von Aufgabenplänen und UI-Interaktionen, indem sie PrefillAgent für Aufgabenplanung und Aktionsgenerierung nutzt. Sie automatisiert Aktualisierungen der UI-Steuerung, erfasst Screenshots und verwaltet Protokolle für Nachrichten und Antworten während der Ausführung.
PrefillAgent
Die Klasse PrefillAgent erleichtert die Aufgabeneinstanziierung und die Generierung von Aktionssequenzen, indem sie maßgeschneiderte Prompt-Nachrichten mithilfe des PrefillPrompter erstellt. Sie integriert System-, Benutzer- und dynamischen Kontext, um ausführbare Eingaben für nachfolgende Workflows zu generieren.
3. Aufgabe filtern
FilterFlow
Die Klasse FilterFlow ist dafür konzipiert, Aufgabenpläne zu verarbeiten und zu verfeinern, indem sie einen FilterAgent nutzt. Die Klasse FilterFlow fungiert als Brücke zwischen der Instanziierung von Aufgaben und der Ausführung eines Filterprozesses mit dem Ziel, Aufgabenschritte zu verfeinern und aufgabenspezifische Dateien basierend auf vordefinierten Filterkriterien vorab auszufüllen.
FilterAgent
Die Klasse FilterAgent ist ein spezialisierter Agent, der zur Bewertung verwendet wird, ob eine instanziierte Aufgabe korrekt ist. Sie erbt von der BasicAgent-Klasse und enthält mehrere Methoden und Attribute zur Handhabung ihrer Funktionalität.
Referenz
ChooseTemplateFlow
Klasse zur Auswahl und zum Kopieren der relevantesten Vorlagendatei basierend auf dem gegebenen Aufgabenkontext.
Initialisiert den Flow mit dem gegebenen Aufgabenkontext.
| Parameter |
-
app_name (str) –
-
file_extension (str) –
Die Dateiendung der Vorlage.
-
task_file_name (str) –
Der Name der Aufgabendatei.
|
Quellcode in instantiation/workflow/choose_template_flow.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 | def __init__(self, app_name: str, task_file_name: str, file_extension: str):
"""
Initialize the flow with the given task context.
:param app_name: The name of the application.
:param file_extension: The file extension of the template.
:param task_file_name: The name of the task file.
"""
self._app_name = app_name
self._file_extension = file_extension
self._task_file_name = task_file_name
self.execution_time = None
self._embedding_model = self._load_embedding_model(
model_name=_configs["CONTROL_FILTER_MODEL_SEMANTIC_NAME"]
)
|
execute()
Führt den Flow aus und gibt den Pfad der kopierten Vorlage zurück.
| Rückgabe |
-
str –
Der Pfad zur kopierten Vorlagendatei.
|
Quellcode in instantiation/workflow/choose_template_flow.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57 | def execute(self) -> str:
"""
Execute the flow and return the copied template path.
:return: The path to the copied template file.
"""
start_time = time.time()
try:
template_copied_path = self._choose_template_and_copy()
except Exception as e:
raise e
finally:
self.execution_time = round(time.time() - start_time, 3)
return template_copied_path
|
PrefillFlow
Basiert auf: AppAgentProcessor
Klasse zur Verwaltung des Vorabfüllprozesses durch Verfeinerung von Planungsschritten und Automatisierung von UI-Interaktionen
Initialisiert den Vorabfüll-Flow mit dem Anwendungskontext.
| Parameter |
-
app_name (str) –
-
task_file_name (str) –
Der Name der Aufgabendatei für Protokollierung und Nachverfolgung.
-
environment (WindowsAppEnv) –
|
Quellcode in instantiation/workflow/prefill_flow.py
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 | def __init__(
self,
app_name: str,
task_file_name: str,
environment: WindowsAppEnv,
) -> None:
"""
Initialize the prefill flow with the application context.
:param app_name: The name of the application.
:param task_file_name: The name of the task file for logging and tracking.
:param environment: The environment of the app.
"""
self.execution_time = None
self._app_name = app_name
self._task_file_name = task_file_name
self._app_env = environment
# Create or reuse a PrefillAgent for the app
if self._app_name not in PrefillFlow._app_prefill_agent_dict:
PrefillFlow._app_prefill_agent_dict[self._app_name] = PrefillAgent(
"prefill",
self._app_name,
is_visual=True,
main_prompt=_configs["PREFILL_PROMPT"],
example_prompt=_configs["PREFILL_EXAMPLE_PROMPT"],
api_prompt=_configs["API_PROMPT"],
)
self._prefill_agent = PrefillFlow._app_prefill_agent_dict[self._app_name]
# Initialize execution step and UI control tools
self._execute_step = 0
self._control_inspector = ControlInspectorFacade(_BACKEND)
self._photographer = PhotographerFacade()
# Set default states
self._status = ""
# Initialize loggers for messages and responses
self._log_path_configs = _configs["PREFILL_LOG_PATH"].format(
task=self._task_file_name
)
os.makedirs(self._log_path_configs, exist_ok=True)
# Set up loggers
self._message_logger = BaseSession.initialize_logger(
self._log_path_configs, "prefill_messages.json", "w", _configs
)
self._response_logger = BaseSession.initialize_logger(
self._log_path_configs, "prefill_responses.json", "w", _configs
)
|
execute(template_copied_path, original_task, refined_steps)
Startet die Ausführung durch Abrufen des instanziierten Ergebnisses.
| Parameter |
-
template_copied_path (str) –
Der Pfad der zu verwendenden kopierten Vorlage.
-
original_task (str) –
Die zu verfeinernde ursprüngliche Aufgabe.
-
refined_steps (List[str]) –
Die Schritte zur Anleitung des Verfeinerungsprozesses.
|
| Rückgabe |
-
Dict[str, Any] –
Die verfeinerte Aufgabe und die entsprechenden Aktionspläne.
|
Quellcode in instantiation/workflow/prefill_flow.py
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 | def execute(
self, template_copied_path: str, original_task: str, refined_steps: List[str]
) -> Dict[str, Any]:
"""
Start the execution by retrieving the instantiated result.
:param template_copied_path: The path of the copied template to use.
:param original_task: The original task to refine.
:param refined_steps: The steps to guide the refinement process.
:return: The refined task and corresponding action plans.
"""
start_time = time.time()
try:
instantiated_request, instantiated_plan = self._instantiate_task(
template_copied_path, original_task, refined_steps
)
except Exception as e:
raise e
finally:
self.execution_time = round(time.time() - start_time, 3)
return {
"instantiated_request": instantiated_request,
"instantiated_plan": instantiated_plan,
}
|
PrefillAgent
Basiert auf: BasicAgent
Der Agent für Aufgabeneinstanziierung und Generierung von Aktionssequenzen.
Initialisiert den PrefillAgent.
| Parameter |
-
name (str) –
-
process_name (str) –
-
is_visual (bool) –
Das Flag, das angibt, ob der Agent visuell ist oder nicht.
-
main_prompt (str) –
-
example_prompt (str) –
-
api_prompt (str) –
|
Quellcode in instantiation/agent/prefill_agent.py
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 | def __init__(
self,
name: str,
process_name: str,
is_visual: bool,
main_prompt: str,
example_prompt: str,
api_prompt: str,
):
"""
Initialize the PrefillAgent.
:param name: The name of the agent.
:param process_name: The name of the process.
:param is_visual: The flag indicating whether the agent is visual or not.
:param main_prompt: The main prompt.
:param example_prompt: The example prompt.
:param api_prompt: The API prompt.
"""
self._step = 0
self._complete = False
self._name = name
self._status = None
self.prompter: PrefillPrompter = self.get_prompter(
is_visual, main_prompt, example_prompt, api_prompt
)
self._process_name = process_name
|
get_prompter(is_visual, main_prompt, example_prompt, api_prompt)
Ruft den Prompt für den Agenten ab. Dies ist die abstrakte Methode von BasicAgent, die implementiert werden muss.
| Parameter |
-
is_visual (bool) –
Das Flag, das angibt, ob der Agent visuell ist oder nicht.
-
main_prompt (str) –
-
example_prompt (str) –
-
api_prompt (str) –
|
Quellcode in instantiation/agent/prefill_agent.py
44
45
46
47
48
49
50
51
52
53
54
55 | def get_prompter(self, is_visual: bool, main_prompt: str, example_prompt: str, api_prompt: str) -> str:
"""
Get the prompt for the agent.
This is the abstract method from BasicAgent that needs to be implemented.
:param is_visual: The flag indicating whether the agent is visual or not.
:param main_prompt: The main prompt.
:param example_prompt: The example prompt.
:param api_prompt: The API prompt.
:return: The prompt string.
"""
return PrefillPrompter(is_visual, main_prompt, example_prompt, api_prompt)
|
message_constructor(dynamic_examples, given_task, reference_steps, log_path)
Konstruiert die Prompt-Nachricht für den PrefillAgent.
| Parameter |
-
dynamic_examples (str) –
Die dynamischen Beispiele, die aus der Selbstdemonstration und menschlichen Demonstration abgerufen wurden.
-
given_task (str) –
-
reference_steps (List[str]) –
-
log_path (str) –
|
Quellcode in instantiation/agent/prefill_agent.py
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 | def message_constructor(
self,
dynamic_examples: str,
given_task: str,
reference_steps: List[str],
log_path: str,
) -> List[str]:
"""
Construct the prompt message for the PrefillAgent.
:param dynamic_examples: The dynamic examples retrieved from the self-demonstration and human demonstration.
:param given_task: The given task.
:param reference_steps: The reference steps.
:param log_path: The path of the log.
:return: The prompt message.
"""
prefill_agent_prompt_system_message = self.prompter.system_prompt_construction(
dynamic_examples
)
prefill_agent_prompt_user_message = self.prompter.user_content_construction(
given_task, reference_steps, log_path
)
appagent_prompt_message = self.prompter.prompt_construction(
prefill_agent_prompt_system_message,
prefill_agent_prompt_user_message,
)
return appagent_prompt_message
|
process_comfirmation()
Bestätigt den Prozess. Dies ist die abstrakte Methode von BasicAgent, die implementiert werden muss.
Quellcode in instantiation/agent/prefill_agent.py
| def process_comfirmation(self) -> None:
"""
Confirm the process.
This is the abstract method from BasicAgent that needs to be implemented.
"""
pass
|
FilterFlow
Klasse zur Verfeinerung von Planungsschritten und Vorabfüllung von Dateien basierend auf Filterkriterien.
Initialisiert den Filter-Flow für eine Aufgabe.
| Parameter |
-
app_name (str) –
Name der verarbeiteten Anwendung.
-
task_file_name (str) –
Name der verarbeiteten Aufgabendatei.
|
Quellcode in instantiation/workflow/filter_flow.py
21
22
23
24
25
26
27
28
29
30
31
32 | def __init__(self, app_name: str, task_file_name: str) -> None:
"""
Initialize the filter flow for a task.
:param app_name: Name of the application being processed.
:param task_file_name: Name of the task file being processed.
"""
self.execution_time = None
self._app_name = app_name
self._log_path_configs = _configs["FILTER_LOG_PATH"].format(task=task_file_name)
self._filter_agent = self._get_or_create_filter_agent()
self._initialize_logs()
|
execute(instantiated_request)
Führt den Filter-Flow aus: Filtert die Aufgabe und speichert das Ergebnis.
| Parameter |
-
instantiated_request (str) –
Das zu filternde Request-Objekt.
|
| Rückgabe |
-
Dict[str, Any] –
Ein Tupel, das ein Flag für die Aufgabenqualität, einen Kommentar und den Aufgabentyp enthält.
|
Quellcode in instantiation/workflow/filter_flow.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 | def execute(self, instantiated_request: str) -> Dict[str, Any]:
"""
Execute the filter flow: Filter the task and save the result.
:param instantiated_request: Request object to be filtered.
:return: Tuple containing task quality flag, comment, and task type.
"""
start_time = time.time()
try:
judge, thought, request_type = self._get_filtered_result(
instantiated_request
)
except Exception as e:
raise e
finally:
self.execution_time = round(time.time() - start_time, 3)
return {
"judge": judge,
"thought": thought,
"request_type": request_type,
}
|
FilterAgent
Basiert auf: BasicAgent
Der Agent zur Bewertung, ob die instanziierte Aufgabe korrekt ist.
Initialisiert den FilterAgent.
| Parameter |
-
name (str) –
-
process_name (str) –
-
is_visual (bool) –
Das Flag, das angibt, ob der Agent visuell ist oder nicht.
-
main_prompt (str) –
-
example_prompt (str) –
-
api_prompt (str) –
|
Quellcode in instantiation/agent/filter_agent.py
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 | def __init__(
self,
name: str,
process_name: str,
is_visual: bool,
main_prompt: str,
example_prompt: str,
api_prompt: str,
):
"""
Initialize the FilterAgent.
:param name: The name of the agent.
:param process_name: The name of the process.
:param is_visual: The flag indicating whether the agent is visual or not.
:param main_prompt: The main prompt.
:param example_prompt: The example prompt.
:param api_prompt: The API prompt.
"""
self._step = 0
self._complete = False
self._name = name
self._status = None
self.prompter: FilterPrompter = self.get_prompter(
is_visual, main_prompt, example_prompt, api_prompt
)
self._process_name = process_name
|
get_prompter(is_visual, main_prompt, example_prompt, api_prompt)
Ruft den Prompt für den Agenten ab.
| Parameter |
-
is_visual (bool) –
Das Flag, das angibt, ob der Agent visuell ist oder nicht.
-
main_prompt (str) –
-
example_prompt (str) –
-
api_prompt (str) –
|
Quellcode in instantiation/agent/filter_agent.py
43
44
45
46
47
48
49
50
51
52
53
54
55 | def get_prompter(
self, is_visual: bool, main_prompt: str, example_prompt: str, api_prompt: str
) -> FilterPrompter:
"""
Get the prompt for the agent.
:param is_visual: The flag indicating whether the agent is visual or not.
:param main_prompt: The main prompt.
:param example_prompt: The example prompt.
:param api_prompt: The API prompt.
:return: The prompt string.
"""
return FilterPrompter(is_visual, main_prompt, example_prompt, api_prompt)
|
message_constructor(request, app)
Konstruiert die Prompt-Nachricht für den FilterAgent.
| Parameter |
-
request (str) –
-
app (str) –
Der Name der bedienten App.
|
Quellcode in instantiation/agent/filter_agent.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 | def message_constructor(self, request: str, app: str) -> List[str]:
"""
Construct the prompt message for the FilterAgent.
:param request: The request sentence.
:param app: The name of the operated app.
:return: The prompt message.
"""
filter_agent_prompt_system_message = self.prompter.system_prompt_construction(
app=app
)
filter_agent_prompt_user_message = self.prompter.user_content_construction(
request
)
filter_agent_prompt_message = self.prompter.prompt_construction(
filter_agent_prompt_system_message, filter_agent_prompt_user_message
)
return filter_agent_prompt_message
|
process_comfirmation()
Bestätigt den Prozess. Dies ist die abstrakte Methode von BasicAgent, die implementiert werden muss.
Quellcode in instantiation/agent/filter_agent.py
| def process_comfirmation(self) -> None:
"""
Confirm the process.
This is the abstract method from BasicAgent that needs to be implemented.
"""
pass
|