Skip to main content
The Agent Platform Javascript SDK (AgP JS SDK) lets you monitor e-commerce prices using the agent.shopFor() command. You can execute a number of web-based workflows, including tracking e-commerce prices across multiple retailers, aggregating product deals in real time, and automating price comparisons to help users make informed purchasing decisions. Here’s a summary of what the AgP JS SDK empowers you to do when monitoring prices across e-commerce websites or carrying our other shopping-related tasks:
  • Define a list of products to monitor.
  • Use an agent to search for each product across e-commerce websites.
  • Receive real-time updates when information is available.
  • Log the prices or messages to the console.
In this example, we’ll explore how to monitor e-commerce prices using the agent.shopFor() method. You’ll see how the AgP JS SDK uses agents to scan the web and extract information, track progress in real time, and report results — all with minimal code.

Monitor e-commerce prices

Situation: You want to track product prices across multiple online retailers — for example, to find the best deal on the latest iPhone, MacBook, or AirPods — but manually checking websites is slow and inconsistent. You need a way to automate these searches and collect real-time updates efficiently. Problem: How can you automatically search for multiple products across e-commerce sites, monitor price changes, and receive live updates — all without building complex scraping or API integrations from scratch? Solution: The AgP JS SDK lets you automate price tracking using the agent.shopFor() command. It enables you to define a list of products, execute concurrent search tasks across multiple retailers, and receive live updates as new pricing data or deals are found. With real-time event monitoring and automated completion handling, you can seamlessly aggregate and compare e-commerce data without writing repetitive code.

Step 1: Initialize the SDK

Start by initializing the SDK and authenticating. This ensures that your agent can securely access the web and run shopping tasks.
// npm install agp-js-sdk
import { WebAgent } from 'agp-js-sdk';

(async () => {
  const agent = WebAgent.fromApiKey(process.env.AGENT_API_KEY);
})();

Step 2: Define the products

Create a list of product names that you want to track. Each product in this array will become a separate shopping task.
  const products = [
    'iPhone 15 Pro',
    'MacBook Pro M3',
    'AirPods Pro'
  ];

Step 3: Start shopping tasks

Use the agent.shopFor() command to search for each product online. The SDK will handle the browsing and information gathering automatically.
  for (const product of products) {
    const task = await agent.shopFor(product);

Step 4: Attach a listener (Optional)

You can see updates from the agent in real time as it works. In this example, the listener attached logs any chat messages the agent sends about the current product, so you can track its findings live in the console.
    task.onUpdate((event) => {
      if (event.type === 'ChatMessageEvent') {
        console.log(`${product} update:`, event.data.content);
      }
    });

Step 5: Wait for completion

Ensure each task completes before moving to the next one.
await task.waitForCompletion();

Step 6: Put it all together and run

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

(async () => {
  const agent = WebAgent.fromApiKey(process.env.AGENT_API_KEY);

  const products = [
    'iPhone 15 Pro',
    'MacBook Pro M3',
    'AirPods Pro'
  ];

  for (const product of products) {
    const task = await agent.shopFor(product);

    task.onUpdate((event) => {
      if (event.type === 'ChatMessageEvent') {
        console.log(`${product} update:`, event.data.content);
      }
    });

    await task.waitForCompletion();
  }
})();

Outcome

The AgP JS SDK, running the above code asyncronously, will follow a sequence that:
  • Initializes the SDK and authenticates through Portal-H.
  • Provides live updates from the agent while it runs, logging messages such as findings.
  • Generates an accurate and detailed response, for example:
iPhone 15 Pro Price Comparison


Model/Condition	Seller	Price	Storage	Notes
iPhone 15 Pro, 128GB, Blue (used)	Amazon.com	$499.99	128GB	4.5★ (84 ratings)
iPhone 15 Pro, 512GB, White	Amazon.com	$659.00	512GB	4.5★ (2 ratings)
iPhone 15 Pro Max, 1TB, Black Titan	Amazon.com	$769.00	1TB	4.5★ (5 ratings)
Pre-Owned iPhone 15 Pro, 128GB	Best Buy	$729.99	128GB	Free shipping
iPhone 15 Pro, 256GB, Black (refurb)	Amazon.com	$679.00	256GB	Free shipping
iPhone 15 Pro, 128GB, Natural	Visible	$899.00	128GB	
iPhone 15 Pro, 128GB, Natural (ref.)	Amazon.com	$529.94	128GB	Free shipping
iPhone 15 Pro Max, 1TB, White (ref.)	Amazon.com	$802.54	1TB	4.0★ (75 ratings)
Lowest price (used): $499.99 (Amazon, 128GB, Blue)

Lowest price (refurbished): $529.94 (Amazon, 128GB, Natural)

New/retail pricing: $899.00 (Visible, 128GB)

Other options: Pre-owned and refurbished available from $499.99–$802.54, depending on seller and storage size.

Source: Bing Shopping