OpenUIRenderer

class OpenUIRenderer(val library: Library = openuiChatLibrary, instructions: String? = null, onError: (error: OpenUIError, messageId: String) -> Unit? = null) : AIUIRenderer

Shows the replies an agent writes in OpenUI Lang in the generative UI of stream-chat-android-ai-compose, with the app's components placeable wherever OpenUI's own content goes.

val ui = AIUIHost(renderers = listOf(OpenUIRenderer()), components = listOf(placeCard)) { action ->
viewModelScope.launch {
channel.sendMessage(Message(text = action.label, extraData = action.customData)).await()
}
}

Each reply keeps its own runtime while the host is kept, so its forms and the state of its $variables survive scrolling. What the person does that is for the agent, such as a follow-up or a form's submit button, reaches the host as an AIUIAction named after OpenUI's action, with the action's context, its other params, the form and the form's values in its payload. A Query or Mutation runs one of the host's tools, on the device, and the model's instructions describe each of the host's tools: what it does, its arguments, and whether it only reads. A Query runs by itself as the reply shows, so it runs only a read-only tool; a tool that changes something runs only from a Mutation the person starts with a tap. Links open through the host, which decides the kinds of link that open.

An app component joins the library under its OpenUI name, its name in PascalCase (place_card is PlaceCard). One whose name the library already has, or that can't be called in a program, is left out of both the instructions and the UI, so it never replaces one of OpenUI's own.

Parameters

library

The library the agent writes with, the chat library by default. Restyle or drop its components with Library.replacingView and Library.removing.

instructions

What the agent's model is told before OpenUI's own instructions, such as which answers to write as UI and when to use the app's components.

onError

Receives each problem with a reply's program, such as one the parser can't read or a tool that failed, with the reply's message id, once the reply is complete. Without it, the problems go to the log.

Constructors

Link copied to clipboard
constructor(library: Library = openuiChatLibrary, instructions: String? = null, onError: (error: OpenUIError, messageId: String) -> Unit? = null)

Properties

Link copied to clipboard
open override val format: AIUIFormat
Link copied to clipboard

Functions

Link copied to clipboard
open override fun capabilities(components: List<AIUIComponent>, tools: List<AIClientTool>): Map<String, Any?>

The fence the agent writes its program in (openui-lang), and the instructions its model needs to write one with the library and components, and to run tools from Query() and Mutation().

Link copied to clipboard
open override fun makeEngine(host: AIUIHost): AIUIEngine
Link copied to clipboard
open fun supports(version: String?): Boolean