Building a 24/7 Competitor Price Monitoring Dashboard with a Multi-Agent System

    This article walks through the end-to-end design and implementation of a competitor price monitoring dashboard powered by a multi-agent system. It covers how to define verifiable requirements, architect a layered system with clearly separated agent roles, and apply the key engineering practices—task state machines, externalized context memory, checkpointing, and idempotent writes—that keep long-running tasks stable across failures and restarts. You will also find practical guidance on scheduling data collection, validating data quality, designing explainable anomaly detection rules, closing the alerting loop, and testing for long-term reliability.读完本文后,读者将获得一份构建能够连续运行、无需人工干预的价格监控系统的实用蓝图。

    Building a 24/7 Competitor Price Monitoring Dashboard with a Multi-Agent System

    1. Defining Requirements and Boundaries

    Before writing any code, break the requirements down into verifiable items. For a “competitor price monitoring dashboard,” the core requirements typically include:

    1. Adding competitor product links and maintaining a list of monitored objects.
    2. Collecting prices, original prices, discount information, and stock status on a fixed schedule.
    3. Providing price trend charts with markers for abnormal fluctuations.
    4. Proactively pushing alerts when a price drops below a threshold, changes sharply, or a product goes out of stock.
    5. Supporting export of monitoring data to standard spreadsheet files.

    During the requirements phase, several boundary questions also need to be settled: the scale of monitored objects, collection frequency, history retention length, how alert thresholds are configured, and which channels alerts are delivered through. These decisions directly affect the collection scheduler, storage design, and alerting logic. For example, monitoring 100 products versus 10,000 products calls for very different scheduling strategies and storage solutions.

    2. System Architecture

    2.1 Layered Structure

    The system can be divided into five layers:

    • Interaction layer: handles requirement input, monitored-object management, dashboard display, and data export.
    • Scheduling layer: a master control agent receives requirements, decomposes them into tasks, and dispatches them to executor agents.
    • Execution layer: consists of units for collection, cleaning and validation, anomaly analysis, alerting, and report generation.
    • Storage layer: a relational database holds monitored objects, price snapshots, task states, and alert records.
    • Notification layer: integrates with group messaging bots or messaging APIs to deliver alerts.

    The benefit of layering is clear separation of responsibilities. Each layer only cares about its own inputs and outputs, so a failure or replacement in one layer does not ripple through the whole system.

    2.2 Agent Role Division

    A common problem in multi-agent systems is overlapping roles, where multiple agents perform the same step. Fix the roles by responsibility:

    Role Responsibility Input Output
    Master control agent Decompose requirements, dispatch tasks, aggregate progress User requirement Task list and status
    Collection agent Fetch pages on schedule and parse fields Monitored objects and collection rules Price snapshots
    Analysis agent Compute trends, flag anomalies Historical snapshots Anomaly events
    Alert agent Decide whether to push, deduplicate, and send Anomaly events Push records
    Report agent Generate dashboard data and export files Query conditions Chart data or spreadsheet files

    A key principle: agents must not rely on each other’s conversation memory to pass information. All intermediate results should be persisted as structured data, with the storage layer serving as the single source of truth.

    3. Key Designs for Long-Term Stability

    The hard part of a long-running task is not whether a single inference is accurate, but whether the task can keep progressing across dozens of interactions and across process restarts. The following three designs form the foundation of stability.

    3.1 Task State Machine

    Every task should have an explicit state and transition only along predefined paths:

    1. PENDING -> RUNNING -> SUCCEEDED
    2. -> FAILED -> RETRYING -> RUNNING
    3. -> DEAD (manual intervention)

    The value of the state machine is recoverability. After a crash, the system finds all tasks in RUNNING state whose heartbeat has timed out, resets them to PENDING, and lets the scheduler re-dispatch them. This eliminates manual triage and prevents tasks from hanging indefinitely.

    3.2 Context Management

    Agent context windows are limited, and stuffing the entire conversation history into every request is both expensive and prone to diluting critical information. A more robust approach:

    1. At the end of each turn, the agent outputs a structured summary: completed steps, artifact locations, open questions, and the next action.
    2. The summary is written to a task memory table, not left in the conversation.
    3. At the start of the next turn, load only the latest summary for the current task, the necessary configuration, and a reference to the most recent artifact.
    4. When a single document is too long, summarize it in segments first, then summarize the summaries.

    An example structure:

    1. task_memory:
    2. task_id: "pm-2026-001"
    3. goal: "Competitor price monitoring dashboard"
    4. completed_steps: ["requirement decomposition", "schema design"]
    5. artifacts:
    6. schema_file: "storage/schema_v1.sql"
    7. open_questions: ["should alert thresholds differ by product category"]
    8. next_action: "implement collection task scheduling"

    3.3 Maintaining Continuity Across Turns

    Cross-turn continuity depends on three constraints:

    • Task IDs run through the entire chain: every subtask, snapshot, and alert record carries a task_id for traceability.
    • Checkpointing: record a checkpoint after each completed step. On interruption, resume from the last checkpoint instead of starting over.
    • Idempotent design: repeated execution of the same step should produce the same result. For example, the unique key of a snapshot is “product ID + capture time window,” so duplicate writes are automatically ignored.

    3.4 Failure Handling

    Instability in external pages is the norm. Common failures include timeouts, abnormal responses, page structure changes, and access restrictions. Recommended strategies:

    • Timeout and retry: set a timeout per request, retry with exponential backoff on failure, and cap the maximum retries.
    • Circuit breaking: after consecutive failures against the same site reach a threshold, pause collection for that site for a while instead of adding load.
    • Field-level alerting: when a field parses as empty several times in a row, fire a dedicated alert indicating the parsing rule may be broken.
    • Manual intervention channel: tasks that exceed the maximum retry count enter a pending queue for human review.

    4. Data Collection Design

    4.1 Scheduling Strategy

    The core of collection scheduling is rate control and spreading load over time. Do not fire requests for all products simultaneously; shard tasks by hashing product IDs across a time window. Set collection frequency based on business need—for example, price-sensitive categories can be collected hourly, while others may only need a few collections per day.

    4.2 Compliance and Access Constraints

    Collection must comply with the target site’s terms of service and robots protocol, respect rate limits, and never bypass login, CAPTCHAs, or other access controls. Pages containing personal information should be excluded outright. These constraints belong in the collection configuration, not in ad-hoc judgments made at inference time.

    4.3 Snapshot Field Specification

    A unified field definition is the foundation of later analysis. Each snapshot should include:

    1. price_snapshot:
    2. snapshot_id unique identifier
    3. product_id monitored object ID
    4. current_price current selling price, numeric, consistent unit
    5. original_price original price, nullable
    6. discount_info discount description, stored verbatim
    7. stock_status in_stock / out_of_stock / unknown
    8. captured_at capture time, stored in UTC
    9. source_url source address

    4.4 Data Quality Validation

    Basic validation should run before snapshots are persisted:

    • Price must be a positive number.
    • If the original price exists, it should not be lower than the current price.
    • Stock status must be one of the enum values; otherwise record it as unknown.
    • Deduplicate snapshots of the same product taken within a very short interval.

    Records that fail validation go into a quarantine table and are excluded from trend calculations, preventing dirty data from polluting the analysis.

    5. Anomaly Detection Rules

    Anomaly detection is where the dashboard delivers its core value. Rules should be clear, configurable, and explainable. The thresholds below are examples; set actual values based on your business scenario.

    1. function detect_events(current, previous_list, config):
    2. events = []
    3. # Low price: selling price below the configured target price
    4. if current.current_price <= config.target_price:
    5. events.append("LOW_PRICE")
    6. # Sharp change: deviation from the average of the last N collections exceeds a threshold
    7. baseline = average(previous_list.prices)
    8. change_rate = (current.current_price - baseline) / baseline
    9. if abs(change_rate) >= config.volatility_threshold:
    10. events.append("SHARP_CHANGE")
    11. # Out of stock: stock status changed from in stock to out of stock
    12. if previous_list.last.stock_status == "in_stock" and current.stock_status == "out_of_stock":
    13. events.append("OUT_OF_STOCK")
    14. return events

    Two points to keep in mind. First, volatility must be computed against the same product’s history—never compare across products. Second, distinguish “state changes” from “state persistence.” If a product stays out of stock, alert only on the first transition; otherwise you will generate a flood of duplicate notifications.

    6. Closing the Alerting Loop

    The value of an alert depends on whether it gets handled. A complete alerting loop includes:

    1. Event generation: the analysis agent outputs anomaly events.
    2. Deduplication and cooldown: for the same product and event type, push at most once per cooldown window.
    3. Prioritization: low-price and out-of-stock events can be high priority; ordinary fluctuations are normal priority.
    4. Delivery: send via a group messaging bot or messaging API, including the product name, what changed, the current price, timestamp, and the original link.
    5. Delivery records: write the result to the alert table. Failed sends are retried with backoff and their final status recorded.

    Push message templates should be structurally consistent so recipients can assess them at a glance:

    1. [HIGH] Product: Example Product A
    2. Type: Low price
    3. Current price: 199.00 (target price: 210.00)
    4. Captured at: 2026-11-24 21:00 UTC
    5. Link: (original monitored URL)

    7. Dashboard and Data Export

    7.1 Trend Chart Data

    Aggregate trend data on the server side; the frontend only renders. A common approach is to compute the daily or hourly minimum, maximum, and average prices, and attach anomaly events as markers at the corresponding timestamps. Returning raw snapshots directly leads to oversized payloads and slow page loads.

    7.2 Spreadsheet Export

    Design export as an asynchronous task: the user submits filter conditions, the system creates an export job, and a download link becomes available when the job completes. For large datasets, read in pages and write in batches to avoid excessive memory use. Exported files should include a header row describing each field for downstream processing.

    8. Testing and Acceptance

    8.1 Test Layers

    • Unit tests: cover threshold boundary conditions, such as a price exactly equal to the target price or a change rate exactly at the threshold.
    • Integration tests: use fixed page samples to simulate collection and verify the full parse-to-store-to-analyze pipeline. Structure changes should trigger field-level alerts.
    • Fault injection tests: deliberately cause timeouts, empty responses, and process restarts to verify retry, recovery, and idempotency logic.
    • Soak tests: run continuously for an extended period and watch for task backlog, memory growth, and repeated alerts.

    8.2 Acceptance Checklist

    Item Acceptance Criteria
    Link entry Valid links are saved; invalid formats are rejected
    Scheduled collection Runs at the configured frequency with no obvious missed captures
    Trend display Chart data matches snapshot records
    Anomaly flags All three event types trigger correctly
    Alert delivery Message content is complete; duplicate events are suppressed
    Data export Exported fields match the filter results
    Failure recovery Tasks resume from checkpoints after a process restart

    9. Common Pitfalls and Notes

    Page structure changes: the most common cause of collection failures. Version your parsing rules and set alert thresholds on field null rates.

    Inconsistent price definitions: “discount price,” “member price,” and “final price” may mean different things across pages. Define a unified standard in the field specification and keep the original wording for traceability.

    Timezone confusion: store capture times in UTC and convert to local timezones only for display; otherwise teams across timezones will misread the data.

    Alert fatigue: overly sensitive thresholds produce floods of useless notifications. Start with a small set of rules at launch, observe, then expand gradually.

    10. Conclusion

    The main challenges of building a competitor price monitoring dashboard are long-term stability and task continuity across turns. With a layered architecture, structured task states, externalized context memory, and idempotent writes, the system can keep making progress through failures and interruptions. The anomaly detection rules and the alerting loop determine whether the system delivers real business value. Start with a small number of monitored objects to validate the full pipeline, confirm data quality and alert effectiveness, then scale up.