# Operating Mechanism
The operating mechanism of the Mini-Program AI development mode involves the interaction among three parties: the Host-App Runtime, the Mini-Program AI backend, and third-party services. Their respective responsibilities are as follows:
- Client Runtime: An independent code execution environment provided by the Host-App, used to execute the atomic interfaces provided by developers and render atomic components to display GUI cards for users;
- Mini-Program AI Backend: Based on the SKILLs encapsulated by developers and combined with user requests, initiates necessary atomic interface calls or atomic component rendering instructions;
- Third-Party Services: Developers call their own services within the implementation of atomic interfaces to complete data interaction, and return the necessary data to the Mini-Program AI for it to understand and fulfill user requests.
The Host-App and the Mini-Program AI backend interact based on the Mini-Program MCP protocol. Developers do not need to understand the details of the interaction protocol; they only need to provide a complete SKILL implementation according to the framework design, and the Mini-Program AI will correctly reason and execute the corresponding atomic interfaces.
# Runtime Environment
The atomic interfaces and atomic components provided by developers run in an independent environment created by the Host-App, which is different from the Mini-Program runtime environment. The logic related to atomic components runs in an independent environment.
# Rendering Environment
Atomic components are rendered using the WebView engine, and the component framework maintains a consistent coding approach with Mini-Program Custom Components.
# Lifecycle
When a user starts a conversation with the Mini-Program AI, the Host-App creates a new session to carry it. The chat history within the session remains visible to both the user and the Mini-Program AI until the Client Runtime ends and the session terminates; when the user re-enters next time, it will be a brand-new session.
The Client Runtime will end in the following situations:
- After the Mini-Program AI has been in the background for a period of time (consistent with the Mini-Program background keep-alive duration), the client will proactively end the runtime;
- After the Mini-Program AI goes to the background, if the system experiences a memory warning, the client may clean up the runtime;
- The user restarts the Mini-Program AI.
# Interaction Flow
Taking a simplified ordering scenario as an example, the interaction flow is as follows:
sequenceDiagram
participant U as User
participant C as Client Runtime
participant A as Mini-Program AI Backend
participant T as Third-Party Service
U->>A: Uplink message: Order a latte, less sugar
A->>A: Load SKILL
A->>C: Send interface call: confirmOrder
C->>C: Start runtime environment, download subpackage
C->>C: Execute atomic interface, obtain user identity via ft.login
C->>T: Create order
T-->>C: Return order information
C-->>A: Return execution result
A->>C: Send rendering instruction
C->>U: Render atomic component, display order
U->>A: Uplink message: Confirm payment
A->>C: Send interface call: payOrder
C->>T: Request payment parameters / create pre-payment order
T-->>C: Return payment parameters
C->>U: Invoke payment checkout, user completes payment
C->>T: Query payment status
T-->>C: Return payment result
C-->>A: Return execution result
A->>C: Send rendering instruction
C->>U: Render atomic component, display payment result
From the above flow, it can be seen that:
- Each atomic interface call corresponds to a round trip of "model decision → client-side execution → result feedback → re-reasoning";
- The input parameters of atomic interfaces are produced by model reasoning, and the returned results will participate in the next round of reasoning as context;
- The display of GUI cards is accomplished by the model sending rendering instructions, and user operations within the card will trigger the next round of the flow as new messages.
Therefore, the design granularity of atomic interfaces will directly affect response latency and call effectiveness. For specific optimization methods, please refer to Performance Optimization Recommendations.