Skip to main content
The Agent Platform Javascript SDK (AgP JS SDK) lets you automate news aggregation using the 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:
// npm install agp-js-sdk
import { WebAgent } from 'agp-js-sdk';

// Initialize the agent using your API key
const agent = WebAgent.fromApiKey(process.env.AGENT_API_KEY);

Step 2: Define your sources

Add the following code, listing the websites you want to extract content from.
const sources = [
  'https://news.ycombinator.com',
  'https://techcrunch.com'
];
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.
  const tasks = await agent.runBatch(
    sources.map(url => ({
      objective: `Visit ${url} and extract the top 5 article titles and URLs.`,
      startUrl: url
    }))
  );

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.
By looping through the 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.
 // Attach listeners to each task
  tasks.forEach((task) => {
    task.onUpdate((event) => {
      console.log(`Task ${task.id} update:`, event.type, event.data);
    });

    task.onStatusChange((status) => {
      console.log(`Task ${task.id} status:`, status);
    });

    task.onChatMessage((message) => {
      if (message.data.type === 'thought') {
        console.log(`Task ${task.id} thinking:`, message.data.content);
      }
    });

    task.onWebAction((action) => {
      console.log(`Task ${task.id} action:`, action.data.action.action_type);

      // Screenshots (optional, browser only)
      // const screenshot = action.data.post_action_screenshot;
      // document.querySelector('img').src = screenshot;
    });
  });

Step 5: Wait for completion

The SDK runs tasks asynchronously. Use waitForAllComplete to ensure results are ready.
await agent.waitForAllComplete(tasks);

Step 6: Put it all together and run

Here’s a complete example that includes all previous steps, assembled and ready to run:
import { WebAgent } from 'agp-js-sdk';

(async () => {
  const agent = WebAgent.fromApiKey('Your API Key');

  const sources = [
    'https://news.ycombinator.com',
    'https://techcrunch.com'
  ];

  const tasks = await agent.runBatch(
    sources.map(url => ({
      objective: `Visit ${url} and extract the top 5 article titles and URLs.`,
      startUrl: url
    }))
  );

  // Attach listeners to each task
  tasks.forEach((task) => {
    task.onUpdate((event) => {
      console.log(`Task ${task.id} update:`, event.type, event.data);
    });

    task.onStatusChange((status) => {
      console.log(`Task ${task.id} status:`, status);
    });

    task.onChatMessage((message) => {
      if (message.data.type === 'thought') {
        console.log(`Task ${task.id} thinking:`, message.data.content);
      }
    });

    task.onWebAction((action) => {
      console.log(`Task ${task.id} action:`, action.data.action.action_type);

      // Screenshots (optional, browser only)
      // const screenshot = action.data.post_action_screenshot;
      // document.querySelector('img').src = screenshot;
    });
  });

  await agent.waitForAllComplete(tasks);
  console.log('All tasks completed!');
})();

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:
Top 5 Articles on TechCrunch (as of now)
AI researchers ’embodied’ an LLM into a robot – and it started channeling Robin Williams
https://techcrunch.com/2025/11/01/ai-researchers-embodied-an-llm-into-a-robot-and-it-started-channeling-robin-williams/
Elon Musk wants you to know that Sam Altman got a refund for his Tesla Roadster
https://techcrunch.com/2025/11/01/elon-musk-wants-you-to-know-that-sam-altman-got-a-refund-for-his-tesla-roadster/

Coinbase CEO Brian Armstrong trolls the prediction markets
https://techcrunch.com/2025/11/01/coinbase-ceo-brian-armstrong-trolls-the-prediction-markets/

Bluesky hits 40 million users, introduces ‘dislikes’ beta
https://techcrunch.com/2025/10/31/bluesky-hits-40-million-users-introduces-dislikes-beta/

What is Bending Spoons? Everything to know about AOL’s acquirer
https://techcrunch.com/2025/10/31/what-is-bending-spoons-everything-to-know-about-aols-acquirer/

Source: TechCrunch