Declarative UI Protocol for AI Agents: From Chat to Operable Interfaces
AI agents can plan, retrieve, call tools, and remember context, but their interaction layer often remains a chat box. When a task requires multiple fields, constraint confirmation, parameter adjustment, and stepwise execution, long text forces users to map fields, infer order, and recover from errors. This article describes a declarative protocol between agents and user interfaces: the model emits structured interface intent, while a controlled renderer maps, validates, renders, and collects events. It explains why whitelisted components are safer than model-written frontend code, how the protocol stays model- and platform-agnostic, and how surface updates, user events, and data patches can be synchronized. It also covers reliable-generation practices, risk-based actions, replay testing, fallback paths, and a phased rollout plan.
In many agent projects, model capabilities are advancing quickly, but the interaction layer often remains stuck in a chat box. Planning, retrieval, tool calling, and memory can all be orchestrated, yet once a task reaches the stage where users must complete multiple pieces of information, confirm constraints, adjust parameters, and execute step by step, the system tends to fall back to long text explanations and asks people to follow them manually. The problem is not that the model cannot express itself. The problem is that the medium is wrong: natural language is suitable for explanation, not for carrying structured operations. The clearer a long paragraph is, the more users must perform field mapping, order judgment, and error recovery in their heads.
A more reliable direction is to let the agent produce “interface intent” rather than final code, and let a controlled rendering layer turn that intent into real controls. This capability can be abstracted as a declarative protocol from agents to user interfaces: the model outputs a structured description, and the frontend handles mapping, validation, rendering, and event collection.
1. From the Chat Box to an Operable Interface
Conversational interaction has the advantage of low barrier to entry. It suits open-ended Q&A, idea exploration, and lightweight instructions. But enterprise tasks usually have explicit schemas. A ticket must specify priority and impact scope. Data analysis must select a time range, dimensions, and aggregation logic. A release process must confirm the environment, approvers, and rollback strategy. If everything depends on text, at least three problems appear.
First, cognitive load is high: users must find out from paragraphs what needs to be filled in. Second, state is invisible: filled and unfilled fields, default values, and conflicting items are not presented directly. Third, execution is hard to trace: the agent may assume the user has understood, while the user may have only copied a description.
Making the interaction interface-based is not about making chat look fancy. It is about making task state explicit and reducing executable actions into buttons, forms, lists, step indicators, and confirmation overlays. The ideal closed loop is: the model infers what the next screen needs from context; the protocol describes the component tree and data bindings; the rendering layer generates native controls; user operations produce events; events return to the agent and drive the next planning step.
2. The Essence of the Protocol Is Controlled Expression
The core of this approach should not be a particular frontend framework, nor should it be tied to a particular model. It should be a neutral contract. It specifies that the agent can only say a limited set of things: create or update a UI surface, add or remove components, set properties, submit data source references, declare validation rules, and expose triggerable actions. An illustrative structure is shown below:
{"surfaceUpdate": {"surfaceId": "order-create","revision": 12,"components": [{"id": "title", "type": "Text", "props": {"value": "Create Ticket"}},{"id": "level", "type": "Select", "props": {"label": "Priority", "options": ["P0", "P1", "P2"], "required": true}},{"id": "submit", "type": "Button", "props": {"text": "Submit", "action": "create_ticket"}}],"dataModel": {"level": "P1"}}}
The key point is not what the JSON looks like, but how responsibilities are separated: the agent decides “what is needed,” the client decides “how to draw it,” and the server decides “whether the data is trustworthy.” The model no longer outputs executable scripts or directly assembles page markup. Instead, it outputs UI changes that are auditable, diffable, and rollbackable. In this way, interface generation turns from a code-generation problem into a data-validation problem, which immediately makes it more controllable from an engineering perspective.
3. Why Not Let the Model Write Frontend Code Directly?
The most direct approach is to let the model output page fragments or component code. It looks powerful, but in practice it expands the risk boundary to the entire runtime. Scripts may access sensitive context, inject external resources, bypass permissions, and trigger unexpected side effects. Even if the content is harmless, different engineering stacks, style systems, and dependency versions make generated results difficult to reuse reliably.
Whitelist rendering reduces the attack surface to a limited set of components: text, input fields, selectors, dates, tables, chart containers, buttons, pagination, step navigation, and read-only details. Each component allows only agreed properties and disables inline scripts, external resources, arbitrary style overrides, and dangerous callbacks. The renderer first performs schema validation, then type checks, enum constraints, length limits, permission filtering, and referential integrity checks, and only then enters the real control tree. For highly sensitive operations, teams can add secondary confirmation, audit logs, canary controls, and tenant-specific component downgrades. The model has expressive power, but it does not have execution power.
4. Multi-Platform Consistency and Model Decoupling
The value of declarative descriptions also lies in cross-platform consistency. The same intent—“one required input field, one optional item, and one submit button”—can map to browser controls, native mobile controls, desktop clients, or embedded terminals. Fonts, focus, accessibility, keyboard navigation, and light and dark themes are handled by the local rendering layer. The agent does not need to know which technology stack the target device uses; it only cares about information structure and interaction semantics.
Decoupling from the model is equally important. The protocol only requires the upstream to produce structured results reliably. It does not prescribe which model generates them. Teams can choose different inference sources for different tasks and use constrained decoding, function calling, template constraints, or post-processing repair to keep formats stable. The real moat lies in protocol version management, component library quality, state synchronization, and observability.
For systems deployed in enterprise cloud environments such as Baidu AI Cloud, teams can also combine general object storage, logging services, monitoring and alerting, and container platform capabilities to bring interface snapshots, event streams, model outputs, and rendering failure reasons into a unified observability pipeline. The protocol itself, however, should not be tightly bound to cloud resources or proprietary interfaces.
5. State Synchronization and Event Return
Generating an interface is easy. The hard part is ongoing collaboration. It is advisable to split interaction into three types of messages: surfaceUpdate for UI increments; userEvent for clicks, input, checkbox changes, and drag completion; and dataPatch for changes to form values or query conditions. Each message carries surfaceId, revision, traceId, and a timestamp. The client applies updates idempotently by revision, and the server links model inference, tool calls, and user operations by traceId.
For long-running tasks, optimistic rendering plus authoritative correction can be used: user input takes effect locally first, and the server then validates whether it exceeds permissions or conflicts. If the agent later provides a new suggestion, it should be shown as an explicit difference rather than silently overwriting content the user has already confirmed. Undo, redo, draft saving, offline caching, and weak-network retransmission should also fall within the protocol boundary; otherwise, the system may work smoothly in a demo but become fragile in production.
For multi-user collaboration, lock granularity must be defined: field-level locks suit forms, block-level locks suit boards, and process-level locks suit approvals. Lock state itself should also be rendered so users do not mistakenly think the system is stuck.
6. Engineering Practices for Reliable Generation
First, define a domain component vocabulary before asking the model to use it. The vocabulary should cover high-frequency business actions rather than trying to approximate general-purpose pages indefinitely.
Second, change the prompt from “please draw a page” to “based on the current task state, select the minimum components from the component catalog and output an increment that passes validation.”
Third, establish dual validation: use constrained output on the generation side to reduce the probability of invalid results, and use strict schema validation on the rendering side as a fallback.
Fourth, label each action with a risk level. Read operations can render immediately. Write operations require explicit confirmation. Actions involving funds, permissions, or releases should require human approval and audit recording.
Fifth, implement replay and regression. Record protocol messages from real sessions as test samples. When upgrading the component library or changing the model source, replay them and compare whether the render tree, event sequence, and final result remain consistent.
Sixth, keep a fallback path. When structured output fails, a component is unsupported, or validation does not pass, the system should gracefully fall back to summary text and manual entry rather than throwing error JSON at the user.
7. A Practical Rollout Path
Rollout does not need to happen all at once. In the first phase, choose a high-frequency, field-explicit, low-risk scenario, such as information completion or query configuration. Support only five to eight components and complete the closed loop of “output—validation—rendering—return.” In the second phase, add data models, conditional visibility, dynamic options, and step flow so the agent can trim follow-up questions based on what the user has already filled in. In the third phase, introduce permissions, multi-tenancy, auditing, experiment splitting, and cross-platform rendering.
Metrics should not be limited to generation success rate. They should also cover task completion time, number of manual edits, form abandonment rate, error rollback rate, invalid output interception rate, and end-to-end latency.
A truly mature system will make users feel that “the model is writing the frontend” is not happening at all; they will simply feel that the next step always appears exactly when needed. It will also keep developers from fearing model upgrades, because the protocol, components, and validation layer keep uncertainty outside the interface. Treat the UI as data to be governed, actions as events to be traced, and the model as a replaceable inference source. Only then can agent applications move from demo projects to maintainable production systems.
