Best Practices

Tips

Write Clear and Concise Prompts

Clarity enables Bytebot to accurately understand your intended actions. While being concise can help, prompts should prioritize clarity over being overly-concise.

1// do:
2bytebot.browser.act({
3 sessionId: browser.sessionId,
4 prompt: 'Login with the email [email protected] and the password $securepassword'
5});
6
7// don't:
8bytebot.browser.act({
9 sessionId: browser.sessionId,
10 prompt: '[email protected]:$securepassword - login'
11});

Prompts should feel conversational, like talking to a human. They should not resemble code.

Additionally, provide clear sign-posting when locating elements tucked in a complex page.

1// poor prompt
2bytebot.browser.act({
3 sessionId: browser.sessionId,
4 prompt: 'Show notifications'
5});
6
7
8// great prompt
9bytebot.browser.act({
10 sessionId: browser.sessionId,
11 prompt: 'Show unread notifications in the header'
12});

Utilize parameters for sensitive data

Parameters are only available for local Puppeteer usage.

While models do have safety features in place, it is best to avoid sharing sensitive information with them. Use parameters to safeguard your data.

1const loginDetails = {
2 EMAIL: process.env.USER_EMAIL,
3 PASSWORD: process.env.USER_PASSWORD,
4};
5
6const actions = await bytebot.puppeteer.act({
7 prompt: 'Log into the website with email EMAIL and password PASSWORD',
8 page: page,
9 options: {
10 parameters: loginDetails
11 }
12});

Parameters can be defined as any arbitrary string. However, all capitalized parameter names is recommended for clarity.

Use error-handling

Implement robust error handling to gracefully manage failures or unexpected results from prompts. Avoid writing sequential actions without error handling.

1try {
2 const actions = await bytebot.browser.act({
3 sessionId: browser.sessionId,
4 prompt: 'Submit the form on the page',
5 });
6 // Process actions...
7} catch (error) {
8 console.error('Failed to execute prompt:', error);
9}

Use testing and validation

Thoroughly test prompts in development environments to fine-tune their accuracy. Because prompts are statistical and non-deterministic, it is important to optimize for performance under varying conditions.

1// Test the prompt with different page states
2const testPageStates = [/* Array of different page states for testing */];
3
4for (const state of testPageStates) {
5 try {
6 const actions = await bytebot.browser.act({
7 sessionId: browser.sessionId,
8 prompt: 'Click the buy button',
9 });
10 // Validate actions...
11 } catch (error) {
12 console.error(`Prompt failed for state ${state.name}:`, error);
13 }
14}