Rebuilding a Chat Web App with an AI Agent: Engineering Workflow and Acceptance Criteria

    This article explains how to turn "generate a page with an AI agent" into a verifiable engineering deliverable. It covers defining authorization boundaries before observing a target page, writing a product report that developers can execute against, splitting implementation into an offline phase and a live-integration phase, keeping service credentials on the server, handling streaming message consistency, and running layered acceptance checks across visual fidelity, functionality, and handover readiness. It also covers how to compare agent workflows fairly and how to keep the improved version separate from the baseline. The goal is a reproducible loop in which every requirement, state transition, and delivery conclusion is backed by evidence.

    1. From “Generating a Page” to “Delivering a Verifiable System”

    Asking an AI agent to build a chat application based on an existing web page looks like a frontend task. In practice it spans product analysis, interaction design, service integration, and test verification.

    A page that renders a sidebar, an input box, and message bubbles does not yet have working chat behavior. Once a user submits a message, the app must also handle pending requests, incremental output, stopping generation, network failures, session switching, and history restoration. Missing any one of these produces the familiar outcome: “the screenshot looks close, but the app is unreliable in use.”

    The rebuild task should therefore be defined as an engineering delivery, not a one-shot UI generation. Three deliverables are worth separating:

    • Product analysis report: the target page’s features, interaction states, information structure, and open questions.
    • Baseline rebuild: within the scope of proper authorization, preserve the target page’s layout, interaction paths, and business behavior as closely as possible.
    • Improved experience version: measured against the baseline, propose improvements that can be explained and verified, rather than adding features arbitrarily.

    Each deliverable needs its own acceptance pass. A complete report does not mean a complete implementation; visual closeness does not mean correct behavior; more features do not mean a better experience.

    2. Set the Authorization Scope Before Observing the Page

    2.1 The rebuild target needs clear boundaries

    In practice, prefer your own applications, pages you are authorized to use, or test samples prepared specifically for the purpose. A page being reachable does not mean all of its content may be copied, and it certainly does not mean its branding, images, user data, or proprietary design assets may be reused.

    Confirm the following before starting:

    • Which pages and interactions are in scope for observation;
    • Whether text, icons, and assets from the page may be used;
    • Whether logged-in areas may be accessed;
    • Whether test accounts contain real personal information;
    • Which actions could produce public links, persistent records, or other side effects.

    The baseline rebuild should use its own application identity and test data to avoid implying a false source. For anything unauthorized, technical validation can be done with neutral layout descriptions and self-made assets.

    2.2 Do not observe only the default page

    A blank default page reveals very little. What actually determines implementation quality is state change:

    • How the send button changes when the input is empty versus filled;
    • How the input area expands after long text is entered;
    • Which actions remain available while a message is being generated;
    • How an in-flight request is handled when switching sessions;
    • Which state the page returns to after the current session is deleted;
    • Whether user input is preserved when the network fails;
    • How the navigation and input area adapt on small screens.

    While observing, keep an evidence record: the steps taken, screenshots, visible results, and a confidence judgment. Behavior that cannot be confirmed directly should be marked “to be verified” rather than written up as established fact.

    3. Write the Product Report as a Spec Developers Can Execute

    A high-quality report is not a list of page elements. It is a combination of features, states, rules, and acceptance conditions.

    3.1 Use a feature structure diagram to define system boundaries

    A general-purpose chat web app can be broken down as follows. Whether a given module is actually in scope still depends on requirements and what authorized observation revealed.

    1. Chat application
    2. ├─ Navigation and session management
    3. │ ├─ New session
    4. │ ├─ Session list
    5. │ ├─ Switch session
    6. │ └─ Rename and delete
    7. ├─ Message interaction
    8. │ ├─ Text input
    9. │ ├─ Send message
    10. │ ├─ Render response
    11. │ ├─ Stop generation
    12. │ └─ Copy and retry
    13. ├─ Content rendering
    14. │ ├─ Paragraphs and lists
    15. │ ├─ Code snippets
    16. │ └─ Scrolling long content
    17. ├─ Settings and adaptation
    18. │ ├─ Basic preferences
    19. │ ├─ Small-screen layout
    20. │ └─ Keyboard and assistive actions
    21. └─ Baseline safeguards
    22. ├─ Identity verification
    23. ├─ Error messaging
    24. ├─ Data persistence
    25. └─ Logging and monitoring

    The diagram describes functional relationships. It should not be read as a claim that every feature is implemented; the report must state the implementation status of each module.

    3.2 Every feature needs observable acceptance criteria

    Take “stop generation.” Writing “supports stopping” is not enough. At minimum, specify:

    • The stop control is visible while generation is in progress;
    • After the user triggers it, the UI stops appending content;
    • Whether content already received is kept;
    • Whether the input area becomes usable again;
    • How the incomplete message is marked;
    • How the request is cleaned up when leaving the page or switching sessions.

    Distinguish carefully between “stopping the UI rendering” and “canceling server-side computation.” Aborting a client connection does not necessarily mean the server task has stopped; the actual behavior depends on the API and the service implementation, and should not be inferred from page behavior.

    3.3 Map requirements to evidence

    Give each requirement its own ID, and record the observation basis, implementation location, and test result. When a feature changes, you can then quickly find the affected interactions and verification items.

    This also reduces the chance of an agent silently dropping requirements: completion no longer rests on a single “implemented” claim, but on evidence that can be checked item by item.

    4. Use Two Implementation Phases, but Never Skip Baseline Verification

    A practical structure: phase one covers requirements analysis and an offline implementation; phase two connects real services and runs integration testing.

    4.1 Phase one: establish a stable page and state model

    Before a real service is connected, use clearly labeled mock responses to validate layout, message appending, session switching, and error display.

    Cover empty content, long content, slow responses, and failed responses. The value of mock data is that boundary cases can be reproduced on demand; it does not prove the real API works.

    Make the page states explicit:

    1. Idle → Submitting → Receiving response → Complete
    2. ├→ User stopped
    3. └→ Request failed

    Each transition needs a clear trigger. Avoid handling everything with a single “loading” flag, which leads to wrong button states, duplicate sends, and cross-session stream leakage.

    4.2 Phase two: re-verify the full path after integration

    Connecting a real service is not just swapping an endpoint. Identity verification, response format, timeout behavior, and error returns may all differ from the mock environment.

    Integration testing should confirm at least:

    • Whether requests carry the correct session context;
    • Whether returned content is parsed correctly;
    • Whether a mid-stream disconnect produces a clear message;
    • Whether retrying after failure creates duplicate messages;
    • Whether a response still belongs to the original session after switching;
    • Whether the UI state returns to a consistent state when the request ends.

    Phase two therefore cannot be a single “send succeeded” smoke test. It must re-cover the critical business paths, especially asynchronous behavior and error branches.

    5. Keep Keys on the Server, Not in the Browser

    For debugging convenience, embedding a long-lived service key in frontend code is common and dangerous. A browser can read the scripts an app serves and the network requests it makes; bundling or obfuscation is not a reliable secrecy measure.

    The safer general architecture:

    1. Browser
    2. ↓ App identity verification and input checks
    3. Application server
    4. ↓ Server-side credentials and request control
    5. Model inference service

    The application server reads credentials from a controlled environment and enforces access control, request validation, timeout handling, and usage limits where needed.

    If an agent is involved in development, limit what it can access. Do not put keys into screenshots, requirements documents, public repositories, test reports, or conversation records that persist. Logs should redact sensitive fields and avoid indiscriminately recording full user messages.

    For development and acceptance environments, use separate credentials and test accounts, and scope access according to least privilege.

    6. With Streaming Output, the Hard Part Is Message Consistency

    Streaming responses let users see content sooner, but they add client-side state complexity.

    6.1 A network chunk is not a complete message

    Network data may be split into chunks of arbitrary size. A single read may contain only part of the text, or several events. Parsing logic should maintain a buffer according to the actual API protocol and update the message only after a complete event is recognized.

    Do not assume “one read yields one complete answer,” and do not treat a successful mock output as proof that real stream parsing is correct.

    6.2 Every request needs its own identity

    Separate the session ID, message ID, and request ID:

    • The session ID determines which conversation the content belongs to;
    • The message ID determines which message to update;
    • The request ID distinguishes the current execution from ones that are already stale.

    When a user retries, stops, or switches sessions, validate that an incoming chunk still belongs to a valid request so an old request cannot pollute the new UI.

    6.3 Content rendering needs its own security boundary

    Treat model output as untrusted content. Rich text rendering must restrict unsafe content and must never execute scripts or arbitrary instructions found in the returned text.

    For code snippets and very long text, also account for horizontal scrolling, copy feedback, and render frequency. Frequent appends can make the page janky; batching UI updates moderately is fine, but not to the point where output visibly stalls.

    7. Fidelity Should Be Judged by Multiple Layers of Acceptance

    7.1 Visual acceptance: control the comparison conditions

    When comparing screenshots, keep the viewport, zoom, font loading state, page content, and interaction state as consistent as possible. Otherwise even the same page can differ noticeably.

    Focus on region proportions, spacing, text wrapping, input area size, scroll position, and small-screen layout. Note that “close layout” is usually more maintainable than “every pixel identical.” If pixel-level acceptance is genuinely required, define the environment and the allowed tolerance up front.

    7.2 Functional acceptance: cover complete interaction paths

    Testing should not stop at “the button is clickable.” Cover:

    • Creating a session and sending several messages in a row;
    • Switching to a historical session and restoring its content;
    • Stopping or leaving the page during generation;
    • Deleting the current session;
    • Resubmitting after a network failure;
    • Restoring persistable state after a page refresh;
    • Completing input and reading on a small screen.

    If sharing is included, verify access permissions in a separate browser environment or while logged out. A link that opens for the current account does not mean sharing behaves as intended.

    7.3 Delivery acceptance: make sure someone else can take over

    The final result should include run instructions, configuration notes, test steps, and known limitations. A project that cannot start reliably, depends on manual patching, or lacks environment configuration is not a complete delivery, however good the demo looks.

    8. Reduce Confounding Variables When Comparing Agent Workflows

    Results from different agents depend not only on model capability but also on the execution framework, browsing permissions, context management, tool calls, human intervention, and runtime budget.

    To study general engineering capability, standardize the task materials, delivery directory, permitted tools, feedback rounds, and acceptance scripts. Also record environment failures and human edits during execution so they are not misattributed to the agent’s own capability.

    Evaluation can be split into requirement coverage, functional correctness, visual consistency, security, and maintainability. Report results item by item rather than substituting a single unsupported overall score.

    For key leakage, unauthorized access, or serious data loss, set veto conditions: visual quality must not offset a basic security defect. A single run is also not enough to prove a workflow is generally superior; more reliable conclusions come from repeated runs and consistent evidence records.

    9. The Improved Version Should Lower Operating Cost, Not Stack Features

    Keep the baseline and the improved version separate. Otherwise you cannot tell whether a difference is a fidelity failure or a deliberate design choice.

    Before improving, build a problem list: which scenario the problem occurs in, which users it affects, what evidence exists, and how it will be verified. Common improvement directions include clearer failure recovery, reading aids for long answers, comprehensible session organization, and better keyboard support.

    New features also carry costs: more interface complexity, a wider test surface, and more maintenance. Improvements should therefore target frequent, well-defined problems and be validated through observable results such as task completion rate, number of steps, and recovery paths, rather than counted as feature quantity.

    10. Close the Loop into a Reproducible Engineering Process

    The reliable workflow for rebuilding a chat web app with an AI agent reduces to:

    Confirm authorization boundaries → observe and record evidence → write an executable spec → complete the offline implementation → connect services securely → verify the real path → run layered acceptance → make experience improvements independently.

    The point is not to have the agent generate as much code as possible in one pass, but to ensure every requirement, every state change, and every delivery conclusion has a basis.

    When the product report, the UI implementation, the service integration, and the test evidence all correspond to one another, the rebuild stops being a demo and becomes an engineering result that can be handed over, maintained, and evolved.