AIUIHost
The generated UI of one conversation: the renderers of the formats it reads, the app's components and tools, each reply's state, and where what the person does in it goes.
A reply carries its UI as an AIUIDocument, which shows in place of its text when one of the host's renderers reads its format. Keep one host for as long as its conversation shows, such as in a ViewModel, so each reply's UI keeps its state across scrolling and configuration changes. It is confined to the main thread.
val ui = AIUIHost(
renderers = listOf(OpenUIRenderer()),
components = listOf(placeCard),
) { action ->
viewModelScope.launch {
channel.sendMessage(Message(text = action.label, extraData = action.customData)).await()
}
}
AIConversation(messages = messages, ui = ui)Parameters
The renderer of each format the agent writes, the first one listed asked first.
The app's views the agent can place.
The app's tools a reply's UI can run on this device, which the agent's instructions list. They run without asking the person. One that is AIClientTool.isReadOnly runs whenever the UI asks, such as to load data while it shows; any other only when the person does something that runs it.
The kinds of link a reply's UI may open: web and email links by default (http, https and mailto). The agent writes every link, so add another scheme only when the app wants it.
Sends what the person did to the agent, as their next message.
Constructors
Properties
What the agent's backend needs to write UI this app shows, as plain Kotlin values: each format it reads, with what its renderer adds, such as the instructions that list the app's tools, and the app's components.
The app's views the agent can place.
The renderer of each format the agent writes, the first one listed asked first.
Functions
The app's component the agent places by name.
Opens a link from a reply's UI with uriHandler, when canOpen lets it.
Gives its renderers the UI of the conversation's replies, oldest first, as each arrives or changes, whether or not the reply is on screen, so a format whose later replies change an earlier one's UI follows them all. It also tells them when a reply leaves the conversation, or its UI does, such as when it is deleted. AIConversation does it: call it with the conversation's messages when you show replies yourself with AIUIView.
Sends what the person did to the agent.