Skip to content

Commit 2d7ec7b

Browse files
committed
make browser messages clearer to the LLM via described/non-ambiguous parameters.
1 parent b246b12 commit 2d7ec7b

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

packages/agent/src/tools/browser/browseMessage.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@ import { browserSessions, type BrowserAction, SelectorType } from './types.js';
99
// Schema for browser action
1010
const browserActionSchema = z
1111
.object({
12-
type: z.enum(['goto', 'click', 'type', 'wait', 'content', 'close']),
13-
url: z.string().url().optional(),
14-
selector: z.string().optional(),
15-
selectorType: z.nativeEnum(SelectorType).optional(),
16-
text: z.string().optional(),
17-
options: z.object({}).optional(),
12+
actionType: z.enum(['goto', 'click', 'type', 'wait', 'content', 'close']),
13+
url: z
14+
.string()
15+
.url()
16+
.optional()
17+
.describe('URL to navigate to if "goto" actionType'),
18+
selector: z
19+
.string()
20+
.optional()
21+
.describe('Selector to click if "click" actionType'),
22+
selectorType: z
23+
.nativeEnum(SelectorType)
24+
.optional()
25+
.describe('Type of selector if "click" actionType'),
26+
text: z
27+
.string()
28+
.optional()
29+
.describe(
30+
'Text to type if "type" actionType, for other actionType, this is ignored',
31+
),
1832
})
1933
.describe('Browser action to perform');
2034

@@ -57,7 +71,7 @@ export const browseMessageTool: Tool<Parameters, ReturnType> = {
5771
returns: zodToJsonSchema(returnSchema),
5872

5973
execute: async ({ instanceId, action }, { logger }): Promise<ReturnType> => {
60-
logger.verbose(`Executing browser action: ${action.type}`);
74+
logger.verbose(`Executing browser action: ${action.actionType}`);
6175

6276
try {
6377
const session = browserSessions.get(instanceId);
@@ -67,7 +81,7 @@ export const browseMessageTool: Tool<Parameters, ReturnType> = {
6781

6882
const { page } = session;
6983

70-
switch (action.type) {
84+
switch (action.actionType) {
7185
case 'goto': {
7286
if (!action.url) {
7387
throw new Error('URL required for goto action');
@@ -136,7 +150,7 @@ export const browseMessageTool: Tool<Parameters, ReturnType> = {
136150

137151
default: {
138152
throw new Error(
139-
`Unsupported action type: ${(action as BrowserAction).type}`,
153+
`Unsupported action type: ${(action as BrowserAction).actionType}`,
140154
);
141155
}
142156
}
@@ -150,7 +164,9 @@ export const browseMessageTool: Tool<Parameters, ReturnType> = {
150164
},
151165

152166
logParameters: ({ action, description }, { logger }) => {
153-
logger.info(`Performing browser action: ${action.type}, ${description}`);
167+
logger.info(
168+
`Performing browser action: ${action.actionType}, ${description}`,
169+
);
154170
},
155171

156172
logReturns: (output, { logger }) => {

packages/agent/src/tools/browser/browseStart.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import { browserSessions } from './types.js';
1010

1111
const parameterSchema = z.object({
1212
url: z.string().url().optional().describe('Initial URL to navigate to'),
13-
headless: z
14-
.boolean()
15-
.optional()
16-
.describe('Run browser in headless mode (default: true)'),
13+
1714
timeout: z
1815
.number()
1916
.optional()
@@ -41,8 +38,8 @@ export const browseStartTool: Tool<Parameters, ReturnType> = {
4138
returns: zodToJsonSchema(returnSchema),
4239

4340
execute: async (
44-
{ url, headless = true, timeout = 30000 },
45-
{ logger },
41+
{ url, timeout = 30000 },
42+
{ logger, headless = true },
4643
): Promise<ReturnType> => {
4744
logger.verbose(`Starting browser session${url ? ` at ${url}` : ''}`);
4845

packages/agent/src/tools/browser/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ export const browserSessions: Map<string, BrowserSession> = new Map();
5858

5959
// Browser action types
6060
export type BrowserAction =
61-
| { type: 'goto'; url: string }
62-
| { type: 'click'; selector: string; selectorType?: SelectorType }
61+
| { actionType: 'goto'; url: string }
62+
| { actionType: 'click'; selector: string; selectorType?: SelectorType }
6363
| {
64-
type: 'type';
64+
actionType: 'type';
6565
selector: string;
6666
text: string;
6767
selectorType?: SelectorType;
6868
}
69-
| { type: 'wait'; selector: string; selectorType?: SelectorType }
70-
| { type: 'content' }
71-
| { type: 'close' };
69+
| { actionType: 'wait'; selector: string; selectorType?: SelectorType }
70+
| { actionType: 'content' }
71+
| { actionType: 'close' };

0 commit comments

Comments
 (0)