@empiricalrun/test-gen 0.38.27 → 0.38.29

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.38.29
4
+
5
+ ### Patch Changes
6
+
7
+ - 32ef92e: fix: removed master agent v1
8
+
9
+ ## 0.38.28
10
+
11
+ ### Patch Changes
12
+
13
+ - dc8d538: fix: ordering of npm install
14
+
3
15
  ## 0.38.27
4
16
 
5
17
  ### Patch Changes
@@ -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;
@@ -1,23 +1,6 @@
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;
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/master/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,GAAG,EACH,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAclD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,oBAAoB,EAErB,MAAM,aAAa,CAAC;AAoBrB,wBAAsB,aAAa,CAAC,EAClC,IAAI,EACJ,eAAe,EACf,aAAa,EACb,OAAO,EACP,KAAK,EACL,GAAG,EACH,OAAO,EACP,cAAc,EACd,uBAAuB,EACvB,OAAO,EACP,aAAa,EACb,QAAgB,EAChB,WAAW,GACZ,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,2FA2FA;AAGD,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,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;;;GAuTA"}
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,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;;;GA6VA"}