Build a chat widget with a three-layer answering strategy: scripted, retrieved, human. The order matters and each layer must know when to give up. Stack: your choice with websockets, Postgres with pgvector, Docker Compose, a domain with TLS. Layer 1 — scripted flows, kept tiny. A flow is a decision tree of at most three levels with buttons, not free text. Ship exactly the cases where a script beats a model: order status by number, opening hours, and how to reach a human. If the visitor types free text at any point, abandon the flow immediately rather than repeating the menu — flows that trap people are why chat widgets get closed. Layer 2 — retrieval answering. Ingest your docs or site, chunk with overlap, embed into pgvector. On a question, retrieve and check the best similarity score against a configurable floor. Below the floor, hand over without calling the model at all. Above it, call the model with a prompt that must either answer with a link to a retrieved source or emit the handover token. Render sources as clickable links under every answer. Layer 3 — human. A simple agent inbox with assignment and canned replies. Once a human joins a conversation, both automated layers are permanently off for it. Measure what matters: for every conversation record which layer resolved it, and whether the visitor pressed "this did not help". The report is resolution share by layer and the top ten questions that reached a human, which is the list that tells you what to write next. Cost control: a per-conversation and per-day token budget. Exceeding it hands over rather than truncating an answer mid-sentence. After hours, skip layer 3 and collect an email address, saying so plainly. Write tests for the retrieval floor triggering handover, for the model never returning an answer without a source, and for free text aborting a flow. Do not build a visual flow builder, mobile apps, or e-commerce integrations.