Skip to main content
The Agent Platform JavaScript SDK enables you to engineer prompts and generate text responses with just a few lines of code. We’ve designed the platform to make it easy and simple to execute common tasks like filling out forms, carrying out web searches, or automating e-commerce UI journeys. Here’s a simple example, included in our SDK.

Basic automation task

This section shows you how to configure and execute a basic automation task using our SDK.

Step 1: Configure the task

First, use the agent.run method to define what you want the agent to do. This method takes a natural language prompt and returns a task object you can track and manage.
// Basic task execution
const task = await agent.run(
  'Search for "TypeScript tutorials" on Google and get the top 5 results'
);

// Wait for completion
await task.waitForCompletion();
console.log('Task completed!');
Here’s a breakdown of each command.
CodeDescription
agent.run()Tells your agent what to do in natural language.
await task.waitForCompletion()Pauses execution until the task is complete.

Step 2: View task results (Optional)

You can view task results in real time or after completion by monitoring events.

Option 1: Real-time updates

task.onUpdate((event) => {
  console.log('Event:', event.type, event.data);
});

Option 2: Full event log (after completion)

await task.waitForCompletion();
console.log('All task events:', task.events);

Filling a form

This section shows you how to configure your agent to execute a more complex workflow, such as filling a form, using our SDK.

Step 1: Configure the task

Use the agent.fillForm() command with a single argument. This should be either a string URL for legacy usage or a structured object for full form automation. Structured object approach (recommended):
  • url: The web page containing the form.
  • fields: Key values descrbing the form’s data.
const task = await agent.fillForm({
  url: 'https://example.com/contact',
  fields: {
    name: 'John Doe',
    email: 'john@example.com',
    message: 'Hello! I’d like more information.'
  }
});

Step 2: Wait for completion

It may take a few moments for the task to complete
await task.waitForCompletion();
console.log('Form submission completed!');

Step 3: View task results (Optional)

You can view task results in real time or after completion by monitoring events.
const task = await agent.run('Your task');

// Listen to all updates
task.onUpdate((event) => {
  console.log('Event:', event);
});

// Listen to status changes
task.onStatusChange((status) => {
  console.log('Status:', status);
});

// Listen to chat messages
task.onChatMessage((message) => {
  console.log('Message:', message.data.content);
});

// Listen to web actions
task.onWebAction((action) => {
  console.log('Action:', action.data.action.action_type);
});
I