// npm install agp-js-sdk
import { WebAgent } from 'agp-js-sdk';
(async () => {
const agent = WebAgent.fromApiKey('Your API Key');
// Step 1: Configure the tasks
const tasks = await agent.runBatch([
{ objective: 'Check weather for New York', startUrl: 'https://weather.com' },
{ objective: 'Look up places to visit in New York', startUrl: 'www.google.com' }
]);
// Step 2: Attach a listener (Optional)
tasks.forEach(async (task) => {
task.onStatusChange((status) => {
console.log(`Task ${task.id} status:`, status);
});
task.onChatMessage((message) => {
console.log(`Task ${task.id} message:`, message.data.content);
});
task.onWebAction((action) => {
console.log(`Task ${task.id} action:`, action.data.action.action_type);
});
task.onError((error) => {
console.error(`Task ${task.id} error:`, error);
});
// Step 3: Wait for completion
await agent.waitForAllComplete(tasks);
console.log('All tasks completed!');
});
})();