agent.runBatch()
and agent.waitForAllComplete()
methods. You’ll see how the SDK handles concurrent execution, tracks progress in real time, and reports results — all with minimal code.
Run multiple tasks
Situation: I want to run multiple tasks at once, finding important information for an upcoming trip to New York, like checking the weather and finding places to visit. Manually handling each task would be slow and tedious. Problem: How can I run several tasks in parallel, track their progress, and view the results without writing repetitive code for each task? Solution: The AgP JS SDK providesagent.runBatch()
and agent.waitForAllComplete()
to simplify and automate this workflow. You can define multiple objectives, run them simultaneously, and monitor their progress using events for status, chat messages, web actions, and errors. This allows you to efficiently manage and automate multiple tasks at the same time.
Step 1: Initialize the SDK
Start by initializing the SDK and setting up authentication via Portal-H by adding the following:Step 2: Wait for completion
To be notified in real time when your task has finished executing, add the following code:Step 3: View task results
Add this code to monitor each task’s progress, messages, web actions, and errors in real time.Step 4: Put it all together and run
Here’s a complete example that includes all previous steps, assembled and ready to run:Browser example
Outcome
The AgP JS SDK, running the above code asyncronously, will follow a sequence that:- Initializes the SDK and authenticates through Portal-H.
- Provides real-time updates.
- Generates an accurate and detailed response, for example: