@empiricalrun/test-gen 0.38.28 → 0.38.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/actions/skill.d.ts +1 -1
- package/dist/actions/skill.d.ts.map +1 -1
- package/dist/agent/master/element-annotation.d.ts +11 -0
- package/dist/agent/master/element-annotation.d.ts.map +1 -0
- package/dist/agent/master/element-annotation.js +134 -0
- package/dist/agent/master/next-action.d.ts +19 -0
- package/dist/agent/master/next-action.d.ts.map +1 -0
- package/dist/agent/master/next-action.js +161 -0
- package/dist/agent/master/planner.d.ts +15 -0
- package/dist/agent/master/planner.d.ts.map +1 -0
- package/dist/agent/master/planner.js +143 -0
- package/dist/agent/master/run.d.ts +1 -18
- package/dist/agent/master/run.d.ts.map +1 -1
- package/dist/agent/master/run.js +124 -175
- package/dist/agent/master/with-hints.d.ts.map +1 -1
- package/dist/agent/master/with-hints.js +3 -1
- package/dist/evals/master-agent.evals.js +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -29
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +9 -1
- package/dist/agent/master/run-v2.d.ts +0 -88
- package/dist/agent/master/run-v2.d.ts.map +0 -1
- package/dist/agent/master/run-v2.js +0 -708
package/CHANGELOG.md
CHANGED
package/dist/actions/skill.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/actions/skill.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/actions/skill.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,cAAc;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK,EAAE;IAEnC,kBAAkB;IAIlB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE;CAG7B;AAED,eAAO,MAAM,cAAc,gBAAyB,CAAC;AAErD,eAAO,MAAM,oBAAoB,EAAE,yBAmHlC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LLM, TraceClient } from "@empiricalrun/llm";
|
|
2
|
+
import { BrowsingAgentOptions } from "../browsing";
|
|
3
|
+
export declare function getElementAnnotation({ elementDescription, annotations, annotatedScreenshot, trace, llm, options, }: {
|
|
4
|
+
elementDescription: string;
|
|
5
|
+
annotations: string;
|
|
6
|
+
annotatedScreenshot: string;
|
|
7
|
+
trace?: TraceClient;
|
|
8
|
+
llm?: LLM;
|
|
9
|
+
options?: BrowsingAgentOptions;
|
|
10
|
+
}): Promise<string | undefined>;
|
|
11
|
+
//# sourceMappingURL=element-annotation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-annotation.d.ts","sourceRoot":"","sources":["../../../src/agent/master/element-annotation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AASrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAgDnD,wBAAsB,oBAAoB,CAAC,EACzC,kBAAkB,EAClB,WAAW,EACX,mBAAmB,EACnB,KAAK,EACL,GAAG,EACH,OAAO,GACR,EAAE;IACD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA4F9B"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getElementAnnotation = void 0;
|
|
4
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
+
const vision_1 = require("@empiricalrun/llm/vision");
|
|
6
|
+
const constants_1 = require("../../constants");
|
|
7
|
+
const annotationToolAction = {
|
|
8
|
+
name: "element_annotation",
|
|
9
|
+
schema: {
|
|
10
|
+
type: "function",
|
|
11
|
+
function: {
|
|
12
|
+
name: "element_annotation",
|
|
13
|
+
description: "Handles annotations for elements and enriched annotations.",
|
|
14
|
+
parameters: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
enriched_annotations: {
|
|
18
|
+
type: "array",
|
|
19
|
+
description: "List of enriched annotations for elements.",
|
|
20
|
+
items: {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
element_id: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Unique element ID for the element.",
|
|
26
|
+
},
|
|
27
|
+
description: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Detailed description for the element. Must not be NA",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
required: ["element_id", "description"],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
reason: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Explain why this element is selected. The reason should be clear and align with the task or purpose.",
|
|
38
|
+
},
|
|
39
|
+
element_annotation: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "Return the unique element ID for the element on which the action needs to be performed.",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
required: ["enriched_annotations", "reason", "element_annotation"],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
async function getElementAnnotation({ elementDescription, annotations, annotatedScreenshot, trace, llm, options, }) {
|
|
50
|
+
const annotationsSpan = trace?.span({
|
|
51
|
+
name: "get-element-annotation",
|
|
52
|
+
input: {
|
|
53
|
+
elementDescription,
|
|
54
|
+
annotations,
|
|
55
|
+
annotatedScreenshot,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
const systemMessage = {
|
|
59
|
+
role: "system",
|
|
60
|
+
content: `You are an expert in describing the images and it's content. You need to provide the descriptions of annotated elements present in the image.
|
|
61
|
+
|
|
62
|
+
You will be provided with an annotated screenshot where interact-able / clickable elements are annotated. The annotation is done by drawing a red box around the element and a small yellow box on it which contains unique element id.
|
|
63
|
+
|
|
64
|
+
You are given a Annotations which contains list of unique element id and description of the element separated by ":".
|
|
65
|
+
|
|
66
|
+
You are also given the description of the element on which the action needs to be taken. The description includes information about how the element looks, it's position etc.
|
|
67
|
+
|
|
68
|
+
Your task is to provide the annotation of the element on which the action needs to be performed based on the element description.
|
|
69
|
+
|
|
70
|
+
Follow steps to fulfil your task:
|
|
71
|
+
- Using the list of all element Ids provided to you, map all the element Ids on the annotated screen and describe each element.
|
|
72
|
+
- For describing each element Id
|
|
73
|
+
-- iterate over each element Id in annotation list
|
|
74
|
+
-- check if the description is already present for the element Id in the Annotation provided to you. If present skip describing it and use it as is.
|
|
75
|
+
-- if the description is NA, then identify the element in the annotated screenshot and describe it using the image or icon enclosed in the element.
|
|
76
|
+
- Respond with the mapped element Ids as "enriched_annotations"
|
|
77
|
+
- Based on the description provided to you and the enriched annotations, first identify the element Id whose description matches the task provided
|
|
78
|
+
|
|
79
|
+
Note:
|
|
80
|
+
- Ensure providing the description of all the elements in the list.
|
|
81
|
+
- Don't update the description if its already present in the given annotations
|
|
82
|
+
- Replace all the "NA" with description of the element. Its position, how does it look like etc.
|
|
83
|
+
- There should be no "NA" present in any of the element description
|
|
84
|
+
`,
|
|
85
|
+
};
|
|
86
|
+
const userMessage = {
|
|
87
|
+
role: "user",
|
|
88
|
+
content: [
|
|
89
|
+
{
|
|
90
|
+
type: "text",
|
|
91
|
+
text: `
|
|
92
|
+
Element description:
|
|
93
|
+
${elementDescription}
|
|
94
|
+
|
|
95
|
+
Annotations:
|
|
96
|
+
${annotations}`,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: "image_url",
|
|
100
|
+
image_url: {
|
|
101
|
+
url: (0, vision_1.imageFormatForProvider)(options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER, annotatedScreenshot),
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
const messages = [
|
|
107
|
+
systemMessage,
|
|
108
|
+
userMessage,
|
|
109
|
+
];
|
|
110
|
+
llm =
|
|
111
|
+
llm ||
|
|
112
|
+
new llm_1.LLM({
|
|
113
|
+
provider: options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
|
|
114
|
+
defaultModel: options?.model || constants_1.DEFAULT_MODEL,
|
|
115
|
+
});
|
|
116
|
+
const completion = await llm.createChatCompletion({
|
|
117
|
+
messages,
|
|
118
|
+
modelParameters: {
|
|
119
|
+
...constants_1.DEFAULT_MODEL_PARAMETERS,
|
|
120
|
+
...options?.modelParameters,
|
|
121
|
+
tool_choice: "required",
|
|
122
|
+
temperature: 1,
|
|
123
|
+
},
|
|
124
|
+
trace: annotationsSpan,
|
|
125
|
+
traceName: "get-element-from-action",
|
|
126
|
+
//@ts-ignore
|
|
127
|
+
tools: [annotationToolAction.schema],
|
|
128
|
+
});
|
|
129
|
+
const toolCall = completion?.tool_calls?.[0];
|
|
130
|
+
annotationsSpan?.end({ output: toolCall });
|
|
131
|
+
const args = JSON.parse(toolCall.function.arguments);
|
|
132
|
+
return args.element_annotation;
|
|
133
|
+
}
|
|
134
|
+
exports.getElementAnnotation = getElementAnnotation;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LLM, TraceClient } from "@empiricalrun/llm";
|
|
2
|
+
import { PlaywrightActions } from "../../actions";
|
|
3
|
+
import { BrowsingAgentOptions } from "../browsing";
|
|
4
|
+
export declare function getNextAction({ task, executedActions, failedActions, pageUrl, trace, llm, options, pageScreenshot, actions, disableSkills, useHints, }: {
|
|
5
|
+
task: string;
|
|
6
|
+
executedActions: string[];
|
|
7
|
+
failedActions: any[];
|
|
8
|
+
pageUrl: string;
|
|
9
|
+
trace?: TraceClient;
|
|
10
|
+
llm?: LLM;
|
|
11
|
+
options?: BrowsingAgentOptions;
|
|
12
|
+
pageScreenshot: string;
|
|
13
|
+
annotatedPageScreenshot?: string;
|
|
14
|
+
actions: PlaywrightActions;
|
|
15
|
+
disableSkills: boolean;
|
|
16
|
+
useHints: boolean;
|
|
17
|
+
annotations?: string[];
|
|
18
|
+
}): Promise<import("openai/resources/index.mjs").ChatCompletionMessageToolCall | undefined>;
|
|
19
|
+
//# sourceMappingURL=next-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-action.d.ts","sourceRoot":"","sources":["../../../src/agent/master/next-action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOlD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,aAAa,CAAC,EAClC,IAAI,EACJ,eAAe,EACf,aAAa,EACb,OAAO,EACP,KAAK,EACL,GAAG,EACH,OAAO,EACP,cAAc,EACd,OAAO,EACP,aAAa,EACb,QAAgB,GACjB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,GAAG,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,2FAkKA"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextAction = void 0;
|
|
4
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
+
const vision_1 = require("@empiricalrun/llm/vision");
|
|
6
|
+
const skill_1 = require("../../actions/skill");
|
|
7
|
+
const constants_1 = require("../../constants");
|
|
8
|
+
async function getNextAction({ task, executedActions, failedActions, pageUrl, trace, llm, options, pageScreenshot, actions, disableSkills, useHints = false, }) {
|
|
9
|
+
const nextActionSpan = trace?.span({
|
|
10
|
+
name: "master-agent-next-action",
|
|
11
|
+
input: {
|
|
12
|
+
task,
|
|
13
|
+
executedActions,
|
|
14
|
+
failedActions,
|
|
15
|
+
pageUrl,
|
|
16
|
+
options,
|
|
17
|
+
pageScreenshot,
|
|
18
|
+
disableSkills,
|
|
19
|
+
useHints,
|
|
20
|
+
skills: skill_1.testCaseSkills.getAvailableSkills(),
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const promptSpan = nextActionSpan?.span({
|
|
24
|
+
name: "master-agent-prompt",
|
|
25
|
+
});
|
|
26
|
+
const systemMessage = {
|
|
27
|
+
role: "system",
|
|
28
|
+
content: `You are an web automation tool which is given a task to complete. You need to execute the task provided to you with the help of web page screenshot, a browser automation tool or skills which are learnt while writing previous tests.
|
|
29
|
+
|
|
30
|
+
Browser automation tool is a tool which uses Playwright and browser to execute action using next_action tool call.
|
|
31
|
+
Skill usage is a tool which helps to execute previously known pieces of code to achieve a task.
|
|
32
|
+
|
|
33
|
+
You will be provided with a screenshot of the webpage which you will use to extract the action that needs to be taken.
|
|
34
|
+
|
|
35
|
+
You will be provided with previously executed actions by the browser automation tool and based on the current screenshot and previously executed actions, you need to predict the next action to be taken.
|
|
36
|
+
|
|
37
|
+
You will also be provided with failed next action predicted by you, so that you can avoid suggesting the same action again - which failed.
|
|
38
|
+
|
|
39
|
+
The next action should be as atomic as possible.
|
|
40
|
+
e.g: click on an element, fill an input element, assert, extract text from an element are valid next action as they are atomic in nature.
|
|
41
|
+
|
|
42
|
+
You will also be provided with skill usage tool which you can use to execute action. These skills are compound functions which helps you to complete your action.
|
|
43
|
+
|
|
44
|
+
You need to respond with either:
|
|
45
|
+
- Next action to be taken by a browser automation tool
|
|
46
|
+
- Use previously learnt skills in the form of tool call.
|
|
47
|
+
|
|
48
|
+
You need to make a decision whether the given skill can be reused if "YES" respond with the skill else respond with the next action.`,
|
|
49
|
+
};
|
|
50
|
+
const userMessage = {
|
|
51
|
+
role: "user",
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: `Task:
|
|
56
|
+
${task}
|
|
57
|
+
|
|
58
|
+
----
|
|
59
|
+
|
|
60
|
+
Previous executed actions:
|
|
61
|
+
${executedActions.map((a) => a).join("\n")}
|
|
62
|
+
|
|
63
|
+
----
|
|
64
|
+
|
|
65
|
+
Previous failed actions:
|
|
66
|
+
${failedActions.map((a) => a).join("\n")}
|
|
67
|
+
|
|
68
|
+
----
|
|
69
|
+
You are also provided with a page screenshot for you to decide the next action.
|
|
70
|
+
|
|
71
|
+
Current page URL: ${pageUrl}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Follow the instructions before responding:
|
|
75
|
+
- Divide the task into sub tasks
|
|
76
|
+
- Using previously executed actions, identify tasks are complete and which tasks needs to be executed next.
|
|
77
|
+
- You will be provided a skill usage action, if the testStep matches the next action then respond with the skill usage.
|
|
78
|
+
- If responding with next action, ensure next action to be detailed and explicit about what action needs to be done. Provide all the information which can be extracted from the screenshot as a part of next action.
|
|
79
|
+
- Mark task as complete only when executed actions provided to you indicates that the task is done.
|
|
80
|
+
- Refer to the text and references available in the screenshot to create the next action.
|
|
81
|
+
- Do not take any extra actions which are not required for the execution of the task
|
|
82
|
+
- If there are no further actions required based on the task, then respond with task as done.
|
|
83
|
+
- Do not recommend actions which are not available in the screenshot
|
|
84
|
+
`,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: "text",
|
|
88
|
+
text: "Screenshot in normal mode 👇",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: "image_url",
|
|
92
|
+
image_url: {
|
|
93
|
+
url: (0, vision_1.imageFormatForProvider)(options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER, pageScreenshot),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
const messages = [
|
|
99
|
+
systemMessage,
|
|
100
|
+
userMessage,
|
|
101
|
+
];
|
|
102
|
+
const actionSchemas = disableSkills || skill_1.testCaseSkills.getAvailableSkills().length === 0
|
|
103
|
+
? []
|
|
104
|
+
: actions.getMasterActionSchemas();
|
|
105
|
+
const actionToolCall = {
|
|
106
|
+
name: "next_task",
|
|
107
|
+
schema: {
|
|
108
|
+
type: "function",
|
|
109
|
+
function: {
|
|
110
|
+
name: "next_task",
|
|
111
|
+
description: "take the next action base on the provided task",
|
|
112
|
+
parameters: {
|
|
113
|
+
type: "object",
|
|
114
|
+
properties: {
|
|
115
|
+
reason: {
|
|
116
|
+
type: "string",
|
|
117
|
+
description: "explain how this action will help to complete the task. the reason should align with the task provided",
|
|
118
|
+
},
|
|
119
|
+
action: {
|
|
120
|
+
type: "string",
|
|
121
|
+
description: `explain the next action in natural language.
|
|
122
|
+
The next action should be as atomic as possible, precise and should contain enough details about the action to be performed.
|
|
123
|
+
E.g. each click, key press, input, assert should be a separate action.
|
|
124
|
+
Each action should take the task to completion, if not the action is invalid.`,
|
|
125
|
+
},
|
|
126
|
+
element_description: {
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "The description of the element on which action needs to be taken, including its position, appearance, etc.",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
required: ["reason", "action", "element_description"],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
const tools = [actionToolCall.schema, ...actionSchemas];
|
|
137
|
+
promptSpan?.end({ output: { messages } });
|
|
138
|
+
llm =
|
|
139
|
+
llm ||
|
|
140
|
+
new llm_1.LLM({
|
|
141
|
+
provider: options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
|
|
142
|
+
defaultModel: options?.model || constants_1.DEFAULT_MODEL,
|
|
143
|
+
});
|
|
144
|
+
const completion = await llm.createChatCompletion({
|
|
145
|
+
messages,
|
|
146
|
+
modelParameters: {
|
|
147
|
+
...constants_1.DEFAULT_MODEL_PARAMETERS,
|
|
148
|
+
...options?.modelParameters,
|
|
149
|
+
tool_choice: "required",
|
|
150
|
+
temperature: 1,
|
|
151
|
+
},
|
|
152
|
+
trace: nextActionSpan,
|
|
153
|
+
traceName: "master-agent-llm",
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
tools,
|
|
156
|
+
});
|
|
157
|
+
const toolCall = completion?.tool_calls?.[0];
|
|
158
|
+
nextActionSpan?.end({ output: toolCall });
|
|
159
|
+
return toolCall;
|
|
160
|
+
}
|
|
161
|
+
exports.getNextAction = getNextAction;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
+
import { Page } from "playwright/test";
|
|
3
|
+
export declare function runtimePlannerWithScreenshot({ trace, task, conversation, pages, page, currentPage, }: {
|
|
4
|
+
trace?: TraceClient;
|
|
5
|
+
conversation: string[];
|
|
6
|
+
task: string;
|
|
7
|
+
pages?: Record<string, any>;
|
|
8
|
+
page: Page;
|
|
9
|
+
currentPage?: string;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
pageName: string;
|
|
12
|
+
isDone: boolean;
|
|
13
|
+
reason: string;
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=planner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../../../src/agent/master/planner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAIvC,wBAAsB,4BAA4B,CAAC,EACjD,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,IAAI,EACJ,WAAW,GACZ,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;;;;GAwIA"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runtimePlannerWithScreenshot = void 0;
|
|
4
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
+
const vision_1 = require("@empiricalrun/llm/vision");
|
|
6
|
+
const constants_1 = require("../../constants");
|
|
7
|
+
async function runtimePlannerWithScreenshot({ trace, task, conversation, pages, page, currentPage, }) {
|
|
8
|
+
const buffer = await page.screenshot({
|
|
9
|
+
//This is done to improve element annotation accuracy, anyways it doesn't annotate elements which are out of viewport
|
|
10
|
+
// fullPage: true,
|
|
11
|
+
// path: `screenshots/screenshot-${screenshotIndex++}.png`, // enable this and screenshotIndex var for local debugging
|
|
12
|
+
});
|
|
13
|
+
const pageBuffer = buffer.toString("base64");
|
|
14
|
+
const runTimePlannerSpan = trace?.span({
|
|
15
|
+
name: "popup-verifier",
|
|
16
|
+
input: {
|
|
17
|
+
task,
|
|
18
|
+
conversation,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const llm = new llm_1.LLM({ provider: "openai" });
|
|
22
|
+
const prompt = [
|
|
23
|
+
{
|
|
24
|
+
role: "system",
|
|
25
|
+
content: `
|
|
26
|
+
Given a successfully executed actions that lists only the actions that were successfully executed and a task comprising multiple actions, your goal is to analyse the list and determine if the entire task is completed.
|
|
27
|
+
These actions are executed by AI agents using Playwright on a browser. These agents already have access to browser tabs to execute actions. The successfully executed actions on browser post browser has opened, is provided to you as successfully executed actions.
|
|
28
|
+
|
|
29
|
+
You are also given a screenshot of the current screen which you can also use to determine whether the entire task is completed or not.
|
|
30
|
+
|
|
31
|
+
If the task is not fully completed, identify which specific actions are missing and suggest next steps to complete the task. Assume that the conversation provided is entirely truthful and no additional actions were performed beyond those listed.
|
|
32
|
+
|
|
33
|
+
To fulfil your goal, follow these steps:
|
|
34
|
+
- Divide the task into individual actions.
|
|
35
|
+
- Compare each task action against the actions listed in the successfully executed actions list.
|
|
36
|
+
- Identify which actions have been executed and which have not.
|
|
37
|
+
- If all actions are executed, respond with the task as done.
|
|
38
|
+
- If any actions are missing, respond with the task as not done, listing all actions and specifying which are complete and which are missing.
|
|
39
|
+
- If provided with list of pages, based on the next pending action and previously executed action, identify the page on which next action needs to be taken
|
|
40
|
+
`,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
role: "user",
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: `
|
|
48
|
+
Task: ${task}
|
|
49
|
+
|
|
50
|
+
----
|
|
51
|
+
|
|
52
|
+
Following are successfully executed actions:
|
|
53
|
+
${conversation.join("\n")}
|
|
54
|
+
|
|
55
|
+
----
|
|
56
|
+
|
|
57
|
+
Current page:
|
|
58
|
+
${currentPage}
|
|
59
|
+
`,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: "text",
|
|
63
|
+
text: "Page Screenshot",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: "image_url",
|
|
67
|
+
image_url: {
|
|
68
|
+
url: (0, vision_1.imageFormatForProvider)(constants_1.DEFAULT_MODEL_PROVIDER, pageBuffer),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
const response = await llm.createChatCompletion({
|
|
75
|
+
trace: runTimePlannerSpan,
|
|
76
|
+
traceName: "runtime-planner-llm",
|
|
77
|
+
model: "gpt-4o",
|
|
78
|
+
messages: prompt,
|
|
79
|
+
tools: [
|
|
80
|
+
{
|
|
81
|
+
type: "function",
|
|
82
|
+
function: {
|
|
83
|
+
name: "task_done",
|
|
84
|
+
description: "end the task by calling this method",
|
|
85
|
+
parameters: {
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {
|
|
88
|
+
actions: {
|
|
89
|
+
type: "string",
|
|
90
|
+
description: "actions extracted from task",
|
|
91
|
+
},
|
|
92
|
+
successful_actions: {
|
|
93
|
+
type: "string",
|
|
94
|
+
description: "successful actions mentioned in the conversation",
|
|
95
|
+
},
|
|
96
|
+
reason: {
|
|
97
|
+
type: "string",
|
|
98
|
+
description: "reasoning for identification of task status",
|
|
99
|
+
},
|
|
100
|
+
isDone: {
|
|
101
|
+
type: "boolean",
|
|
102
|
+
description: "whether the task is done",
|
|
103
|
+
},
|
|
104
|
+
pageName: {
|
|
105
|
+
type: "string",
|
|
106
|
+
enum: pages ? Object.keys(pages) : [],
|
|
107
|
+
description: "page name for the next action.",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
required: ["isDone", "reason", "pageName"],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
modelParameters: {
|
|
116
|
+
tool_choice: "required",
|
|
117
|
+
temperature: 0.5,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
const toolCallResp = (response?.tool_calls || [])[0];
|
|
121
|
+
if (toolCallResp) {
|
|
122
|
+
const toolCall = JSON.parse(toolCallResp.function.arguments);
|
|
123
|
+
const output = {
|
|
124
|
+
pageName: toolCall.pageName,
|
|
125
|
+
isDone: toolCall.isDone,
|
|
126
|
+
reason: toolCall.reason,
|
|
127
|
+
};
|
|
128
|
+
runTimePlannerSpan?.end({
|
|
129
|
+
output,
|
|
130
|
+
});
|
|
131
|
+
return output;
|
|
132
|
+
}
|
|
133
|
+
const output = {
|
|
134
|
+
pageName: "",
|
|
135
|
+
isDone: false,
|
|
136
|
+
reason: "LLM failed to generate a valid response",
|
|
137
|
+
};
|
|
138
|
+
runTimePlannerSpan?.end({
|
|
139
|
+
output,
|
|
140
|
+
});
|
|
141
|
+
return output;
|
|
142
|
+
}
|
|
143
|
+
exports.runtimePlannerWithScreenshot = runtimePlannerWithScreenshot;
|
|
@@ -1,27 +1,10 @@
|
|
|
1
|
-
import { LLM, TraceClient } from "@empiricalrun/llm";
|
|
2
1
|
import { Page } from "playwright";
|
|
3
|
-
import { PlaywrightActions } from "../../actions";
|
|
4
2
|
import { ScopeVars, TestCase } from "../../types";
|
|
5
3
|
import { BrowsingAgentOptions } from "../browsing";
|
|
6
|
-
export declare function getNextAction({ task, executedActions, failedActions, pageUrl, trace, llm, options, pageScreenshot, annotatedPageScreenshot, actions, disableSkills, useHints, annotations, }: {
|
|
7
|
-
task: string;
|
|
8
|
-
executedActions: string[];
|
|
9
|
-
failedActions: any[];
|
|
10
|
-
pageUrl: string;
|
|
11
|
-
trace?: TraceClient;
|
|
12
|
-
llm?: LLM;
|
|
13
|
-
options?: BrowsingAgentOptions;
|
|
14
|
-
pageScreenshot: string;
|
|
15
|
-
annotatedPageScreenshot?: string;
|
|
16
|
-
actions: PlaywrightActions;
|
|
17
|
-
disableSkills: boolean;
|
|
18
|
-
useHints: boolean;
|
|
19
|
-
annotations?: string[];
|
|
20
|
-
}): Promise<import("openai/resources/index.mjs").ChatCompletionMessageToolCall | undefined>;
|
|
21
4
|
export declare function createTestUsingMasterAgent({ task, page, testCase, options, scopeVars, }: {
|
|
22
5
|
task: string;
|
|
23
6
|
page: Page;
|
|
24
|
-
testCase
|
|
7
|
+
testCase?: TestCase;
|
|
25
8
|
options: BrowsingAgentOptions;
|
|
26
9
|
scopeVars?: ScopeVars;
|
|
27
10
|
}): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/master/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/master/run.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAclC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,oBAAoB,EAErB,MAAM,aAAa,CAAC;AAsBrB,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;;;GAkWA"}
|