Skip to main content
Sorting through news articles manually can be time-consuming, overwhelming, and tedious for users. The Agent Platform Javascript SDK (AgP JS SDK) lets you automate that process using batch tasks, making it easy and simple to leverage AI agents to extract the most relevant articles from multiple sources. Here’s a summary of the real-world value this approach can bring:
  • 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.

Example

The sample below shows you how to aggregate news using batch tasks:
const sources = [
  'https://news.ycombinator.com',
  'https://techcrunch.com',
  'https://arstechnica.com'
];

// Create a batch of tasks, one per source
const tasks = await agent.runBatch(
  sources.map(url => ({
    objective: 'Extract top 5 article titles and URLs',
    startUrl: url
  }))
);

// Wait for all tasks to complete
await agent.waitForAllComplete(tasks);

// Process results
tasks.forEach((task, index) => {
  console.log(`News from ${sources[index]}:`);
  
  // Filter ChatMessageEvents to extract content
  task.events
    .filter(event => event.type === 'ChatMessageEvent')
    .forEach(event => {
      console.log('-', event.data.content);
    });
});

Aggregate news

The steps below show you how to aggregate news using the Agent Platform JavaScript SDK:

Step 1: Define your sources

List the websites you want to extract content from.
const sources = [
  'https://news.ycombinator.com',
  'https://techcrunch.com',
  'https://arstechnica.com'
];

Step 2: Create tasks

For each source, create a task with an objective (what you want extracted) and a start URL.
const tasks = await agent.runBatch(
  sources.map(url => ({
    objective: 'Extract top 5 article titles and URLs',
    startUrl: url
  }))
);

Step 3: Wait for completion

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

Step 4: Process results

Each task contains events with the extracted data. Filter for ChatMessageEvent objects and extract data.content for the headlines and URLs.
tasks.forEach((task, index) => {
  console.log(`News from ${sources[index]}:`);
  task.events
    .filter(event => event.type === 'ChatMessageEvent')
    .forEach(event => {
      console.log('-', event.data.content);
    });
});
I