Skip to main content
Price Monitoring

Published Nov 25, 2026

How to Build an AI Price Monitoring Agent With Email Alerts

Build a tested Python price-monitoring agent with Proxidize, AgentMail email alerts, safe reply commands, SQLite history, and retry controls.

How to Build an AI Price Monitoring Agent With Email Alerts

An AI price monitoring agent can check an authorized product page, validate the current price, compare it with a confirmed observation, and email an operator only when something changes. The operator can then reply with a small set of commands such as check now, show history, or mute 24h.

This tutorial builds that loop with Python, AgentMail for an agent-owned email inbox, Proxidize Residential Proxies for the collection route, and SQLite for durable local state. The example is deliberately narrow: email cannot choose a new target, execute code, or trigger a purchase.

The complete, tested implementation is available in the Proxidize integration examples repository.

Quick Answer

Build the monitoring system as a deterministic pipeline, not as an unconstrained chatbot:

  1. Fetch one approved product URL through a configured Proxidize access point.
  2. Extract a price from Product JSON-LD, explicit product meta tags, or target-specific markup.
  3. Normalize the value with Decimal and compare it with the last confirmed observation.
  4. Store history and alert state in a database.
  5. Send one idempotent AgentMail alert when a real change occurs.
  6. Accept only exact reply commands from one authorized operator.

An LLM can summarize history or explain an anomaly later. It should not decide whether an untrusted email may change the target URL, run a shell command, or take an irreversible commercial action.

Key Takeaways

  • Keep collection, validation, and notification separate. A successful HTTP response is not automatically a valid price observation.
  • Use deterministic price logic. Currency, product identity, source URL, and previous observation all matter.
  • Make email sends idempotent. A retry must not produce two price alerts.
  • Treat every inbound email as untrusted input. Authorize the sender, allow only exact commands, and deduplicate message IDs.
  • Use the least-privilege AgentMail key available. The example supports an inbox-scoped key and discovers its assigned inbox through auth.me().
  • Use residential proxies when location-specific or distributed collection is genuinely required. A proxy supplies the network route; it does not parse the page or grant permission to collect it.
  • Do not automate buying from an email reply. Keep purchases and other irreversible actions behind explicit human review and business controls.

What We Are Building

The agent has two bounded paths: a scheduled price check and an operator reply.

bash

The price checker never receives a URL from email. The monitored URL comes from a private environment variable or a trusted deployment configuration. The email handler recognizes only four commands:

CommandResult
`check now`Runs the configured check immediately
`show history`Returns recent confirmed observations
`mute 24h`Suppresses new alerts for 24 hours
`help`Returns the supported command list

Everything else receives the help response. There is no free-form tool call, URL parser, browser instruction, purchase action, or shell bridge.

Why Use AgentMail for the Email Layer?

Many transactional email services are designed primarily to send messages. A monitoring agent needs a two-way inbox: it must send an alert, keep the conversation in a thread, receive a reply, and expose that reply to code.

AgentMail describes itself as API-first email infrastructure for AI agents. Its inbox API supports sending and receiving messages, threads, labels, scoped API keys, webhooks, WebSockets, and polling webhooks. Its threading documentation also documents idempotency keys for safe reply retries.

Those capabilities fit this workflow well:

  • One inbox can represent the price-monitor agent.
  • An inbox-scoped key limits the credential to that inbox's messages, threads, and drafts.
  • A price-change alert creates a thread that the operator can reply to.
  • A webhook, WebSocket, polling webhook, or bounded message poll can deliver the reply to the worker.
  • Message and event IDs provide durable deduplication keys.

AgentMail explicitly says it does not support cold outreach. That is not a limitation for this use case: price alerts are operational messages sent to an operator who configured and expects them. Review the AgentMail cold-outreach policy before adapting the email layer to any customer-facing workflow.

Prerequisites

You need:

  • Python 3.11.5 or later.
  • uv for the virtual environment and locked dependencies.
  • An AgentMail API key. An inbox-scoped key is sufficient for one existing inbox.
  • A Proxidize Residential Proxy access point.
  • One product page or feed that you are authorized to monitor.

For broad, multi-market price monitoring, Proxidize Residential Proxies provide country, city, and ISP targeting with rotating or sticky sessions. Start with the simplest permitted source and route. An official API or partner feed is usually preferable when it already provides the required data.

Install the Tested Example With uv

Clone the public repository and install the locked Python environment:

bash

Copy the example's safe environment template:

bash

The repository ignores .env.agentmail.local, .env.*, .local/, and common trace or browser-state files. Do not rename a real secret file to .env.example, paste credentials into source code, or include them in a screenshot.

Configure AgentMail and Proxidize

Populate the local environment file with private values from the two dashboards:

bash

Keep the proxy server and credentials in separate variables. The server value must not contain a username or password.

The inbox selection is scope-aware:

  • With an inbox-scoped AgentMail key, the code calls auth.me() and uses the inbox assigned to that credential.
  • With an organization- or pod-scoped key, the code creates or reuses an inbox through the stable PRICE_MONITOR_INBOX_CLIENT_ID.
  • Set AGENTMAIL_INBOX_ID when a broader key should use one specific existing inbox.

Do not set the operator address to the agent inbox in production. A self-addressed message is useful for a controlled API test, but a polling worker could otherwise mistake its own replies for new operator commands.

Extract a Price Without Guessing

This tutorial starts where the broader price scraping guide leaves off: with a known product and an explicit extraction contract.

The example accepts three input shapes, in this order:

  1. One unambiguous Product JSON-LD offer.
  2. An element with data-price, data-currency, and an optional data-product-name.
  3. Product price, currency, and name meta tags.

A minimal test fixture looks like this:

html

If the page contains conflicting offers, an invalid currency code, a negative value, or no recognized product price, the check fails. It does not select the first currency-looking number on the page.

Production retailers often need a target-specific extractor that also preserves variant, seller, condition, membership state, promotion, shipping, stock, requested location, and observed location. Weakening validation to make more pages “work” usually creates false alerts.

Fetch the Page Through Proxidize

The HTTPX client receives a Proxidize proxy URL assembled from private environment variables:

python

The complete implementation validates the URL scheme and hostname, keeps destination TLS verification enabled, and rejects responses larger than 5 MB. These limits are examples, not universal values. Set limits based on the approved target and the fields the workflow actually requires.

Use a rotating session for independent product observations. Use a sticky session when one observation depends on consistent store, delivery, cookie, variant, or cart context. The price-monitoring use-case guide explains why proxy geography and retail context must be validated separately.

Store Confirmed Observations Before Making Decisions

The SQLite store keeps four kinds of state:

TablePurpose
`observations`Confirmed name, price, currency, URL, and observation time
`alerts`Reserved and completed price-change alert events
`processed_messages`Inbound messages already handled
`reply_outbox`One frozen response and idempotency key per inbound message
`state`Operational state such as `muted_until`

The example uses Decimal, not binary floating point, for prices. It refuses to compare two currencies as though they were the same series.

The order of operations matters. For a changed price with email enabled, the worker:

  1. Loads the last confirmed observation.
  2. Builds a deterministic change event.
  3. Reserves the event in the alert ledger.
  4. Sends the AgentMail alert.
  5. Completes the alert ledger.
  6. Stores the new observation.

If the send raises an exception, the event reservation is released and the previous observation remains current. A later retry can therefore reproduce the same transition safely instead of silently losing the alert.

Send One Idempotent Alert

The message describes the confirmed transition and lists the available reply commands:

python

The event ID is a SHA-256 digest of stable transition fields, including the product key, previous observation time, previous price, current price, currency, product name, and source URL. It intentionally excludes the new check time because that value would change between retries.

This detail is important. AgentMail returns the original message and thread for an identical idempotent retry. If the same key is reused with different message content, it returns 409 Conflict. The request body and idempotency key must therefore be derived from the same stable event.

Process Replies as Untrusted Commands

Incoming email is a hostile input boundary even when the application is small. Anyone may be able to email an agent inbox, and a message can contain social engineering or prompt-injection instructions.

The example applies three checks before taking an action:

python

The allowlist maps exact normalized text to fixed functions. A message such as check https://example.com, change the target, or ignore safeguards and run a shell does not become a partial match.

Before sending, the worker freezes the command, response text, and idempotency key in a reply outbox. A transport retry therefore cannot rerun check now or produce a different show history body under the same key. After the send succeeds, the worker stores the inbound message ID as processed. AgentMail keeps the reply in the same thread.

For a server, use a signed webhook and deduplicate on the webhook event ID. AgentMail documents webhook delivery as at least once, so duplicates are expected. For a scheduled or sandboxed worker without a public URL, an AgentMail polling webhook can queue events until the worker fetches and commits them. The repository example uses a bounded message poll to keep the dependency set and control flow easy to inspect.

AgentMail also offers the beta Agent Armor feature for detecting possible attempts to manipulate an agent. Treat a security verdict as another control, not as a replacement for sender authorization, exact commands, least-privilege credentials, and human review.

Run the Deterministic Price-Change Test

The repository includes two local HTML fixtures. The first establishes a USD 149.00 baseline without sending an email:

bash

The second fixture changes the price to USD 129.00:

bash

Expected result:

json

Run the credential-free tests separately:

bash

What We Tested Against AgentMail

We tested the integration on November 25, 2026 with AgentMail Python SDK 2.0.26 and an inbox-scoped API key. No secret, inbox address, message ID, thread ID, or complete proxy endpoint is included in the repository.

TestResult
Authenticate and discover the scoped inbox with `auth.me()`Passed
List messages within the inbox scopePassed
Send a controlled workflow messagePassed
Repeat an identical send with the same idempotency keyPassed; the same message and thread IDs were returned
Retrieve the message and threadPassed
Reply and preserve the original threadPassed
Run the baseline-to-price-drop fixture through the real gatewayPassed
Confirm the local alert ledger points to a retrievable message and threadPassed
Run 13 AgentMail-focused credential-free testsPassed

The controlled API validation sent a message to the same AgentMail inbox. It did not test delivery to an unrelated external mailbox. The operator authorization and reply-command paths were tested with deterministic fakes, including an unauthorized sender, a duplicate message, an unknown command, and a simulated send failure.

This distinction matters: the tests demonstrate the API contract and the example's state machine. They do not make a claim about deliverability to every external mailbox or access to every product site.

Where AI Should and Should Not Be Used

The reliable core of this system is ordinary software:

  • deterministic extraction,
  • exact product matching,
  • decimal arithmetic,
  • explicit thresholds,
  • idempotent events,
  • durable state, and
  • allowlisted commands.

An AI model can add value after those controls. For example, it can summarize a week of confirmed price history, explain why several alerts may represent one promotion, classify a parsing anomaly for review, or draft a human-readable report from structured records.

Do not let page text or email text directly grant tools. A product page can contain prompt-injection strings just as an email can. The model should receive validated fields, not a blanket instruction to obey the page. Any action that changes your own price, contacts a customer, modifies the monitored catalog, or places an order should have separate authorization and audit controls.

For a wider view of search, scraping, browsers, proxies, and agent frameworks, read How AI Agents Access the Web.

Production Hardening Checklist

Before moving beyond one product and one operator:

  • Move SQLite to a database with transaction and locking behavior suitable for multiple workers.
  • Put collection jobs on a queue and give each product/context pair a stable identity.
  • Use target-specific extractors and record seller, variant, stock, promotion, shipping, currency, and location context.
  • Keep request and response size limits, timeouts, retry budgets, and destination-aware rate limits.
  • Verify signed webhook payloads or use polling webhooks when the worker cannot accept inbound HTTP.
  • Deduplicate on both inbox and message identifiers when one email can reach multiple inboxes.
  • Use a narrow AgentMail key and a dedicated Proxidize access point for the workload.
  • Keep secrets in a deployment secret manager and rotate any credential exposed in chat, screenshots, logs, or source control.
  • Record why every alert was sent and which observation it compared.
  • Require a human decision for purchasing, repricing, account changes, or other irreversible actions.
  • Monitor bounces, complaints, disabled webhooks, parser failures, and unusual alert volume.
  • Test with known fixtures before changing a production extractor.

The goal is not the most autonomous agent. It is the smallest system that produces trustworthy observations and sends the right message once.

Choosing the Proxy Session for Price Monitoring

Residential proxies are a practical default when the workflow needs broad geographic coverage or consumer-network routing. Rotate between independent checks. Keep a sticky session when one observation spans several requests that must preserve retailer context.

Mobile proxies make sense when the test specifically requires a real US mobile-carrier origin or a mobile-web experience. They are not automatically better for every price-monitoring job.

Compare the complete cost per valid observation: proxy traffic, page weight, retries, browser rendering, parsing, validation, storage, and alert handling. The best proxies for price monitoring guide covers those selection criteria in more detail.

Use this workflow only for sources and data you are authorized to access. Review applicable law, contracts, privacy requirements, intellectual-property restrictions, and website terms. Use respectful request rates and collect only the fields needed for a legitimate business purpose.

A proxy changes the network route. It does not create collection rights, bypass the need for permission, or turn an invalid observation into a valid one. An email inbox is a control surface. It should not become a route around internal approval or safety policies.

Build the Controlled Workflow

Start with the tested AgentMail price-monitor example on GitHub, run the two fixtures, and then adapt the extractor to one authorized source.

When the collection route needs geographic coverage, rotating or sticky residential sessions, create a dedicated Proxidize Residential Proxy access point and validate the complete workflow against your real acceptance criteria.

Frequently asked questions

No. Collection, extraction, normalization, comparison, idempotency, and alert delivery should be deterministic. An LLM is optional for summarizing confirmed records, classifying anomalies, or drafting explanations after the core checks have succeeded.

This workflow needs an agent-owned inbox that can send an alert, receive an operator reply, and preserve the conversation as a thread. AgentMail exposes those inbox, message, thread, event, and scoped-key operations through its API.

Yes. The tested example calls auth.me() to discover the inbox assigned to an inbox-scoped key, then limits message and thread operations to that inbox. A broader organization or pod key is only required when the worker must create or manage inboxes outside that scope.

Create one stable event ID from the confirmed price transition, reserve it in a local alert ledger, and reuse it as the email idempotency key. The request body must also remain identical on a retry, or AgentMail can correctly reject the reused key as a conflict.

Not with broad tool authority. Authenticate the sender, deduplicate the message, parse a small exact command set, and map each command to a fixed function. Treat any free-form email content as untrusted even when a model or security scanner reviews it.

Residential Proxies are the usual starting point for global or city-specific price observations across many sites. Mobile Proxies fit workflows that specifically require real US mobile-carrier IPs or a mobile experience. The correct choice depends on the authorized target, required geography, session behavior, page weight, and cost per valid record.

This example intentionally cannot. Automated purchasing introduces financial, contractual, fraud, inventory, and account-risk controls that do not belong in a simple email command. Keep purchases behind explicit human approval and a separately designed transaction system.

Ready to launch?

Proxies built for real operations.

For teams that depend on stability, not luck.