agent.runBatch()method. You can execute a number of web-based workflows, including extracting top articles from multiple sources, organizing them in one place, and delivering relevant content quickly without manual effort.
Here’s a summary of what the AgP JS SDK empowers you to do when collecting and managing news content:
- Define a list of news sources you or your users care about.
- Use an agent to automatically extract the top articles from each source.
- Collect results in one place instead of visiting sites individually.
- Log or display the headlines and URLs for quick access and further processing.
Automate news aggregation
Situation: You want to gather the most relevant news from multiple sources quickly, but manually checking each website is time-consuming, overwhelming, and inconsistent. Problem: How can you automatically extract top articles from multiple news sources and collect them in one place, all without building complex scraping or API integrations from scratch? Solution: The AgP JS SDK lets you automate news aggregation using batch tasks. It enables you to define a list of sources, execute concurrent extraction tasks, and collect results in real time. With automated completion handling and event monitoring, you can efficiently gather and organize news content without repetitive manual work.Aggregate news
The steps below show you how to aggregate news using the AgP JS SDK:Step 1: Initialize the SDK
Start by initializing the SDK and setting up authentication via Portal-H by adding the following:Step 2: Define your sources
Add the following code, listing the websites you want to extract content from.Run limits: Currently, Agent Platform has a limit of 2 runs per minute, per user. This limit refreshes every minute. Defining more than 2 sources in a single run can return a “Usage limit exceeded” error as the platform treats each source as an individual task to execute concurrently.
Step 3: Create a task
Define the task with an objective (what you want extracted), referencing the URL so the agent knows where to navigate when initializing the run and executing the task.Step 4: Attach listeners to each task (Optional)
After creating your task, you can attach event listeners to each individual task to monitor its progress and activity in real-time. This step allows you to:- Track status changes (
pending,running,completed,failed) so you know where each task is in its workflow. - Receive chat messages or reasoning outputs from the agent (e.g., thoughts or explanations) as they happen.
- Monitor web actions the agent performs in the browser, such as clicks, typing, or navigation steps.
- Catch errors if a task fails or encounters issues.
tasks array and attaching these listeners, you can log detailed updates to the console (or handle them in your application) without waiting for the batch to complete. This gives you full visibility into how each task is performing.
Step 5: Wait for completion
The SDK runs tasks asynchronously. UsewaitForAllComplete to ensure results are ready.
Step 6: Put it all together and run
Here’s a complete example that includes all previous steps, assembled and ready to run: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:
.png)
