From Page Replication to Experience Optimization: A Practical Guide to Agent Development
This article explains how to use AI agents to turn an existing conversational web page into a new application through a structured engineering workflow. It covers building a product model before coding, separating visual fidelity from functional verification, handling API trust boundaries and streaming message parsing, defining a distinct optimization phase, designing fair and reproducible evaluations, and closing the loop with layered testing and explicit deliverables. Readers will learn how to distinguish observed behavior from assumptions, model session state explicitly, avoid leaking credentials into browser code, and evaluate delivery evidence rather than relying on a single demo.
1. What Really Needs Verification Is Not Whether It “Looks the Same”
Asking an agent to generate a new application from an existing conversational web page may look like a frontend development task, but it actually involves product analysis, interaction modeling, API integration, quality verification, and several other stages.
A page screenshot shows only the interface at a single point in time; it cannot fully express product behavior. For example: after a message is entered, does the send button switch to a stop button? Can the user switch conversations while generation is in progress? After a page refresh, how is an unfinished request presented? Does a shared link allow unauthenticated users to access it? These details often determine whether an application is actually usable.
Therefore, this type of task should be split into three interrelated deliverables with different acceptance goals:
- Product functional documentation and structure diagram: describe which features were observed, how they relate to one another, and which capabilities remain unverified.
- Faithful replication version: implement the page against an explicit functional and visual baseline, minimizing unrequested design changes.
- Independent optimization version: beyond the baseline version, propose improvements around usability, reliability, and efficiency, and explain the rationale for each change.
Here, “replication” should be limited to the interface and functionality within the authorized scope; it does not mean copying trademarks, proprietary assets, private code, or internal implementations. Public APIs, open code, and web products are also different layers: even with access to some code or API documentation, you still need to confirm the scope of permission, service dependencies, and runtime conditions.
2. Build a Product Model Before Writing Code
1. Turn Page Observations into a Feature List
Agents tend to prioritize visible areas while overlooking features hidden in menus, empty states, and error paths. A more reliable approach is to organize the page by user tasks.
A general conversational application can be structured as follows:
Conversational application├── Session navigation│ ├── New conversation│ ├── History conversation list│ ├── Switch conversation│ └── Rename and delete├── Message interaction│ ├── Text input│ ├── Send and stop│ ├── Reply display│ └── Retry on failure├── Content operations│ ├── Copy content│ ├── Regenerate│ └── Share and access control└── General experience├── Responsive layout├── Keyboard operation├── Loading and error prompts└── Data persistence
This structure diagram is only a candidate set of capabilities; it should not be treated as evidence that the target page already supports all of them. The product report needs to mark each item as “observed,” “verified,” “to be confirmed,” or “out of scope for this task,” to avoid presenting assumptions as facts.
2. Define Behavior for Each Feature
“Supports conversation history” is not an actionable development requirement. At minimum, it still needs to answer:
- Is history stored locally or on the server?
- Is the conversation name entered by the user or generated from the first message?
- Does deletion require confirmation?
- When switching conversations, how is an in-progress reply handled?
- What is displayed when data is empty, loading fails, or permissions are insufficient?
It is recommended to describe features using “entry point, preconditions, action, expected result, and exception handling.” This both guides development and can be directly converted into test cases.
3. Establish Traceability from Requirements to Acceptance
Each requirement should be linked to an implementation location and acceptance evidence. For example, “the mobile input area is not obscured” requires corresponding layout rules, as well as verification results across different viewports, soft keyboard pop-up, and multi-line input.
This traceability reduces a common risk: the report is thorough, but the code implements only part of it. In the final delivery, it should be possible to clearly distinguish what is implemented, partially implemented, and not implemented.
3. Verify Visual Replication and Functional Replication Separately
1. Visual Consistency Requires a Fixed Baseline
Visual replication should not rely only on “it looks about right.” Viewport size, page state, message content, and scroll position should be fixed, and then the following dimensions should be compared:
- The width and alignment of the main content area;
- The expanded and collapsed states of the navigation area;
- The position, minimum height, and maximum height of the input area;
- Font size, line height, spacing, and border hierarchy;
- How long text, code blocks, and empty states are displayed;
- Layout changes on narrow-screen devices.
Dynamic content, time fields, and generating animations may interfere with screenshot comparison; test data should be standardized, or unstable regions should be evaluated separately.
At the same time, visual replication does not mean copying the defects of the reference page. If the reference page has insufficient contrast, keyboard inaccessibility, or obvious usability problems, these should be noted in the replication report and fixed in the optimization version rather than quietly changing the baseline.
2. Functional Consistency Requires Coverage of Complete Paths
A page being able to send a request does not mean the conversation feature is complete. The minimum usable loop includes at least:
- The user enters content and sends it;
- The application immediately displays the user message;
- The system enters a waiting or generating state;
- The reply is presented progressively or all at once upon completion;
- After successful completion, input capability is restored;
- On failure, the reason is explained and a recovery entry point is provided.
In addition, edge cases such as repeated clicks, rapid conversation switching, request timeouts, and page refreshes need to be verified. These paths are more likely than static layouts to expose engineering problems.
4. API Integration: Handle Trust Boundaries Before Presentation Effects
1. Keys Should Not Enter Browser Code
During development, API credentials may be provided only after the main page is complete. Once credentials arrive, they should not simply be written into frontend files.
Code, network requests, and build artifacts in the browser may all be inspected, so long-lived server-side keys should be stored in a controlled server environment. The recommended data flow is:
Browser→ Application server: verify identity, check input, enforce rate limiting→ Model service: submit request and read response→ Application server: organize results, record necessary diagnostic information→ Browser: update message state
The server also needs to limit input length, control request frequency, and handle error messages as necessary to avoid exposing keys, internal addresses, or full diagnostic content to users.
Test credentials should use least privilege and a limited validity period. Logs should also not record full conversations by default; the fields to retain and the retention period should be determined based on privacy requirements.
2. Streaming Must Consider Message Boundaries
Streaming replies can improve the waiting experience, but network chunks do not necessarily align with business message boundaries. A chunk may contain multiple events, or only part of a single event.
Therefore, the parser should retain buffered content that has not yet been fully parsed and identify event boundaries according to the actual API protocol, rather than treating each received data chunk as a complete message. Specific fields and end markers must be based on the API documentation and must not be invented from experience.
It is also necessary to distinguish connection interruption, user-initiated stop, and normal server completion. All three may appear as “no more data,” but the corresponding message states and prompts should differ.
3. Session State Should Be Explicitly Modeled
The following illustrative state model can be used:
Idle → Submitting → Receiving reply → Completed├→ User stopped└→ Request failed
Each message should also have a stable identifier, an owning conversation, a role, content, and state. Asynchronously returned data must update the corresponding conversation, not just “the currently open page”; otherwise, after the user switches conversations, the reply may end up in the wrong place.
Cancellation also needs clear semantics: the browser stopping reception does not necessarily mean the upstream service has stopped processing. Implementations should pass cancellation signals according to the capabilities actually supported by the server and API, and should avoid promising resource cleanup effects that cannot be guaranteed.
5. The Optimization Version Should Solve Problems, Not Stack Features
Adding many new features before the replication version is complete can easily cause goal drift. A more reasonable order is to establish a verifiable baseline first, then form a separate improvement list.
Each improvement should answer four questions:
- Which type of user encountered what problem?
- In what scenario did the problem occur?
- Why can the existing flow not solve it?
- How can the improvement be verified as effective?
For example, if long replies make it difficult for users to find key conclusions, content navigation or collapsible sections could be considered; if long input is prone to accidental sending, multi-line input and send prompts could be optimized; if users need to re-enter content after a network failure, drafts could be preserved and a retry entry point provided.
These improvements should all retain clear boundaries. Automatically generating summaries may introduce extra requests and content deviation; saving drafts involves data retention; sharing features involve access permissions. New features should not be evaluated only by interface benefits but also by cost, privacy, and failure paths.
Priority can be judged from four dimensions: user value, implementation cost, maintenance burden, and security risk. For early-stage applications, clear error prompts, reliable state management, and mobile usability are usually more worth prioritizing than complex personalization features.
6. Establish a Fair and Reproducible Method for Evaluating Agent Development
The results of agent development depend not only on the model but also on browsing capability, file operation permissions, testing tools, runtime environment, and task orchestration. Therefore, a single delivery result should not be directly attributed to model capability.
If different execution strategies are to be studied, the following should be kept as consistent as possible:
- The same requirement description and acceptance criteria;
- The same reference page and observation conditions;
- The same initial project and dependency scope;
- The same timing for providing credentials;
- The same execution time and resource limits;
- The same permitted external capabilities;
- The same human intervention rules.
Among these, “providing credentials in the second stage” can serve as a process checkpoint: observe whether the agent re-examines the integration method, executes real requests, handles exceptions, and adds regression tests. However, credentials being available does not mean all features have been verified; the test report still needs to state the coverage scope.
Evaluation can be divided into five dimensions:
- Product understanding: whether the main flows, hidden states, and items to be confirmed are identified.
- Visual and interaction: whether the baseline is met and whether different viewports and keyboard operations are covered.
- Functional completeness: whether normal paths and key exception paths are completed.
- Engineering quality: whether code responsibilities are clear and whether state management and error handling are reliable.
- Delivery credibility: whether the report is consistent with the actual implementation and whether inspectable evidence is provided.
If scoring is used, metrics and weights should be defined in advance, distinguishing automated checks from human judgment. A general capability ranking should not be inferred from “it runs successfully,” “the page looks good,” or a single demo.
7. A Test Loop Matters More Than One-Shot Generation
1. Basic Checks
First confirm that the project can start, the main pages can be accessed, and there are no runtime errors that block operation. Then check basic behaviors such as input validation, message conversion, state transitions, and storage logic.
These checks can quickly reveal obvious defects, but they cannot replace real interaction testing.
2. Integration and Interaction Checks
Focus on verifying:
- Whether successful responses are displayed correctly;
- Whether invalid credentials produce safe and clear prompts;
- Whether recovery is possible after timeouts and interruptions;
- Whether consecutive sends produce duplicate messages;
- Whether reply ownership is correct after switching conversations;
- How late responses are handled after a conversation is deleted;
- Whether regeneration preserves or replaces old content according to the agreed behavior.
For sharing features, permission boundaries should also be verified in an unauthenticated environment. Being able to open a link while logged in only proves that the current user can access it; it does not prove that external access logic is correct.
3. Visual and Accessibility Checks
In addition to conventional desktop layouts, narrow screens, long messages, multi-line input, soft keyboard pop-up, and text zoom should also be covered. Buttons should have clear accessible names, focus order should be reasonable, and focus should return to an appropriate position after a dialog closes.
Streaming content should also not trigger assistive reading prompts without restraint; a balance should be struck between timely notification and avoidance of interruption.
4. Regression Checks After Fixes
After a problem is found, do not verify only the fix point. For example, adjusting the height of the input area may change the scroll space of the message list; modifying the conversation cache may affect deletion behavior. Each fix should re-check affected adjacent features and record remaining limitations.
8. Close the Development Process with Explicit Deliverables
A complete delivery should ideally include the following:
- Feature description and structure diagram;
- Mapping between requirements and acceptance items;
- Explanation of differences between the baseline version and the optimization version;
- Local run and deployment requirements;
- Credential configuration and security considerations;
- Test environment, test results, and uncovered scope;
- Known issues and suggestions for subsequent improvements.
In particular, distinguish “implemented,” “tested,” and “accepted.” These are not the same state: code existing does not mean it has been executed, and execution does not mean it meets requirements.
Conclusion
When using agents to build conversational web pages, what is truly worth reusing is an engineering loop: understand the product first, then define boundaries, then complete implementation, real integration, and layered verification, and finally optimize based on evidence.
Models can improve analysis and coding efficiency, but they cannot replace clear requirements, secure architecture, and reliable acceptance. Only when visuals, functionality, state, security, and delivery evidence are placed in the same process can page replication move from a one-time demo to a maintainable and extensible application development practice.
