Design an Agentic Customer Support Automation System
Machine LearningModel answerLast updated
Design an end-to-end AI system that scrapes tickets from a browser-only UI, enriches them with user data from an API, and generates personalized support replies.
Background
Your company runs a customer support operation at scale. Two internal systems are already in place:
- Ticket dashboard: A web application that displays all incoming support tickets. It has no programmatic API — the only way to read ticket data is through its browser UI.
- Customer data service: A REST API that accepts a customer identifier and returns profile information such as subscription plan, account status, recent activity, and preferred language.
Your task is to design an AI-powered agent that monitors the ticket dashboard, reads each ticket, pulls the relevant customer profile, and produces a personalized response — either sending it automatically or routing it to a human agent for approval.
What to cover
Walk through the full system from end to end:
- Ticket discovery: How does the system find out when a new or updated ticket exists, given there is no webhook or feed?
- Content extraction: How does the agent read ticket data from a browser-rendered page reliably?
- Customer enrichment: How is the customer profile fetched, cached, and handled when the service is unavailable?
- Response generation: What is the pipeline — classification, retrieval, drafting, verification?
- Routing logic: When should a reply be sent automatically versus held for human review?
- Reliability and failure handling: Retries, idempotency, state management.
- Security and privacy: How is sensitive customer data handled throughout?
- Observability: What do you measure and how do you catch regressions?
What is expected
This is a senior-level ML system design question. A strong answer scopes requirements, makes explicit assumptions about volume, reasons about costs and latency, and discusses trade-offs rather than just listing components. Concrete numbers and justifications for design choices matter more than a complete component inventory.
Hints
Hint 1
Start by estimating volume and deriving concurrency requirements for browser workers — that number constrains most of the architecture downstream.
Hint 2
The browser-only ticket system is the most brittle component. Think about what happens when the UI updates and your selectors break: you need a fallback extraction path and a way to detect drift.
Hint 3
Automatic reply is a dial, not a switch. Think about what properties of a ticket and its draft must all be true before you skip human review, and how you'd expand that set safely over time.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and Assumptions
State these out loud before drawing any boxes.
Functional scope
- Detect new and updated tickets on a browser-only dashboard.
- Extract structured content: ticket ID, subject, thread, customer identifier, status, attachments.
- Fetch a customer profile from the REST API and attach it to the ticket context.
- Classify the ticket, retrieve relevant knowledge, and draft a reply.
- Either post the reply automatically or surface it in a human review queue.
- Posting the reply also goes through the browser (no write API either).
Non-functional targets
- Volume: ~10k tickets/day → ~7/min average, ~50/min peak.
- Draft latency: within 2 minutes of ticket creation.
- Correctness over speed: a wrong answer (hallucinated policy, incorrect refund commitment) is more damaging than a slow one.
- PII handled under least privilege; ticket text treated as untrusted input.
Back-of-envelope sizing
- A headless browser page load takes roughly 3–8 s. At 50 tickets/min you need about 10 concurrent browser workers to stay within the latency budget.
- Each ticket costs roughly 6k input + 500 output tokens. At 10k/day that is ~65M tokens/day — a real cost line, so use a smaller model for classification and a larger one only for drafting.
2. High-Level Architecture
[Discovery Workers] ──> ticket_state DB ──(new/changed)──> Work Queue
│
[Orchestrator / Agent]
├── Browser Reader (Playwright pool)
├── Customer Context (API + cache)
├── KB Retrieval (BM25 + embeddings)
└── LLM Pipeline
│
[Router]
├── Auto-send path ──> Browser Writer
└── Human review queue ──> Review UI ──> Browser Writer
│
[Observability / Audit Log]
The orchestrator is a durable state machine (Temporal, Step Functions, or equivalent), not a free-form agent loop. Every step is checkpointed and retryable. This is the most important architectural decision: an unbounded agent loop is hard to debug, hard to retry partially, and hard to audit.
3. Ticket Discovery
Since there is no feed or webhook, the system polls the ticket list view every 30–60 seconds, sorted by last-updated descending, paginating until it reaches a watermark (max(last_seen_updated_at)).
Deduplication uses a content_hash stored per ticket. A ticket is enqueued only if it is absent from ticket_state or its hash changed. This naturally handles customer replies on existing threads.
Optimization: many modern SPAs load ticket data via background XHR calls even though they expose no public API. Playwright's network interception can capture these JSON responses directly — far more reliable than DOM scraping. Worth raising as a design choice (subject to authorization and terms of service).
Run a single elected leader for discovery workers to avoid hammering the dashboard with duplicate polls.
4. Browser-Based Content Extraction
Use a pool of authenticated Playwright contexts under a dedicated service account. Persist session cookies and detect expiry so the pool can silently re-authenticate from a secrets vault.
Two-tier extraction:
- Deterministic extractor (primary): targets stable selectors —
data-*attributes and ARIA roles rather than CSS class names. Output is validated against a typed schema (Pydantic or equivalent). If required fields are missing, fall through. - Vision/LLM extractor (fallback): pass a screenshot plus accessibility tree to a multimodal model. Mark the result as lower-confidence and fire an alert indicating selector drift. This buys time for a human to fix the primary extractor without dropping tickets.
Always store raw HTML and a screenshot in object storage. This enables replay and post-hoc debugging without re-hitting the live UI.
Throttle browser workers so the automation does not degrade the dashboard for human support staff.
5. Customer Context Enrichment
Resolve the customer from the ticket's email or customer ID field. If the match is ambiguous, do not guess — route the ticket to human review with a flag explaining why.
API hygiene: wrap every call with a timeout, exponential backoff with jitter, and a circuit breaker. Put a short TTL cache (5–15 minutes) in front of the API for repeated tickets from the same customer.
Data minimization: pass only an allowlisted field set to the LLM — name, plan tier, account tenure, open orders, locale. Strip payment instruments, government IDs, and anything not needed for response generation. This is both a privacy control and a prompt-length optimization.
Graceful degradation: if the customer API is unavailable, generate a generic (non-personalized) draft, mark it as such, and force it into the human review queue.
6. Response Generation Pipeline
-
Classify (small, fast model): determine intent, urgency, sentiment, language, and whether the ticket falls into a sensitive category — legal threats, security issues, refund requests above a threshold, churn signals. These flags feed the routing decision.
-
Retrieve: hybrid search over help-center articles, internal policies, and past resolved tickets. BM25 handles keyword precision; dense embeddings handle semantic similarity. A lightweight reranker picks the top-k passages to inject into the prompt.
-
Draft (larger model): a structured prompt contains the system policy, the ticket thread, the customer profile snippet, and retrieved passages. The model outputs JSON:
{reply, cited_doc_ids, proposed_actions, confidence}. Structured output prevents the model from sneaking unsupported claims into free-form text. -
Verifier pass: a second LLM call (or a deterministic checker) confirms every factual claim in the draft has a citation from the retrieved docs or the customer profile. Uncited factual claims fail the check.
-
Policy engine (deterministic rules, highest priority): never commit to refunds above a configured limit, never provide legal advice, never echo PII back beyond what the customer already knows about themselves. These rules run after the LLM and cannot be overridden by it.
7. Routing and Auto-Send
Auto-send only when all of the following are true:
- Intent is on an approved allowlist (e.g., password reset instructions, order status lookup).
- Draft confidence exceeds a per-intent calibrated threshold.
- Verifier and policy engine both pass.
- Customer identity is unambiguously resolved.
Everything else goes to the human review UI, which shows the draft, its citations, the customer profile summary, and a diff if the reviewer edits it.
Rollout discipline: start at 0% auto-send. Promote an intent to auto-send only after its measured approval-without-edit rate exceeds ~95% over a statistically meaningful sample. This makes the expansion auditable and reversible.
Reviewer edits are labeled data. Feed them back into fine-tuning and use them to calibrate confidence thresholds.
8. Reliability
- Idempotency key on every browser write so a retry after a crash does not post a duplicate reply.
- Dead-letter queue for tickets that exhaust retries; alert on-call and surface them in a dashboard.
- State machine status field (
NEW → READING → DRAFTED → IN_REVIEW → SENT | FAILED) makes the current position of every ticket explicit and queryable. - Store the model version and prompt version alongside every draft so you can reproduce or audit any response later.
9. Observability
Track per stage: discovery lag, extraction success rate by extractor tier (primary vs. fallback), customer API p50/p95/error rate, LLM cost per ticket, verifier pass rate, policy flag rate, auto-send rate, time-to-first-draft, and reviewer edit distance.
Set alerts on extraction fallback rate (selector drift signal) and on auto-send confidence distribution shifts (model drift signal).
Common Mistakes to Avoid
- Free-form agent loop: hard to retry, audit, or explain. Use a state machine.
- Sending all data to the LLM: pass only what is necessary. More context is not always better, and it increases cost and privacy risk.
- Binary auto-send decision at launch: start conservative and expand by intent based on measured data.
- No fallback extractor: a single UI update breaks the entire pipeline. The two-tier approach buys resilience.
- Ignoring the write path: posting replies also goes through the browser. It needs the same idempotency and retry logic as the read path.