Building with agents
Choose a component. Supply typed arguments. Update a working interface.
Describe your app in the Playground to see a component or a layout configured, validated and refined. The Playground simulates the model's output in your browser; this guide covers connecting your own model and composing layouts. For a working dropdown with shared React and JSON rendering, host data, actions and persistent selections, start with React and JSON integration.
One component
Give your model the JSON Schema and allowed action names. Validate its completed output before applying it to the current component.
import { buttonDefinition } from '@uthereal/ui/button'
import { applyEdit } from '@uthereal/ui/foundations'
// Provide buttonDefinition.editJsonSchema for partial updates to your model.
// In a reducer, currentConfig is the latest committed configuration.
const result = applyEdit(buttonDefinition, currentConfig, modelOutput, ['save'])
if (result.success) setConfig(result.config)
else sendErrorsToAgent(result.errors)Every component definition carries two JSON Schemas. jsonSchema describes creation input: required arguments must be present and omitted settings receive defaults. editJsonSchema describes partial edits: omitted arguments keep their current values, and null clears a setting: it returns to its default, or is removed when it has none. Required arguments cannot be cleared. @uthereal/ui/agent offers the same calls for the dropdown menu as applyDropdownEdit, dropdownJsonSchema and dropdownEditJsonSchema.
An edit merges nested option objects, including theme tokens and motion settings. An item array replaces the previous array. Callback functions and application credentials are never part of model output.
Compose components
The optional composition catalog contains every registered component. Containers such as Card and ScrollArea arrange their children and can be nested to create larger layouts; the other components are leaves. A stable host state store associates persisted selections with component and item IDs; mounted UI state has a separate lifecycle.
'use client'
import { useReducer, useState } from 'react'
import {
createComposition,
applyCompositionUpdate,
} from '@uthereal/ui/composition'
import {
CompositionView,
createStateStore,
} from '@uthereal/ui/composition/react'
const allowedActions = ['save']
const initialDocument = createComposition(
{
root: 'toolbar',
elements: {
toolbar: {
type: 'Card',
props: {},
children: ['files'],
},
files: {
type: 'DropdownMenu',
props: {
label: 'File actions',
items: [
{ kind: 'action', id: 'save', label: 'Save', action: 'save' },
],
},
children: [],
},
},
},
allowedActions,
)
export function AgentToolbar() {
const [store] = useState(() => createStateStore({}))
const [feedback, setFeedback] = useState('Ready')
const [document, dispatch] = useReducer(
(current: typeof initialDocument, output: unknown) => {
const result = applyCompositionUpdate(current, output, allowedActions)
return result.success ? result.document : current
},
initialDocument,
)
return (
<>
<button
onClick={() =>
dispatch({
baseRevision: document.revision,
patch: [
{
op: 'replace',
path: '/elements/toolbar/props/direction',
value: 'column',
},
],
})
}
>
Arrange in a column
</button>
<CompositionView
spec={document.spec}
store={store}
actions={{
save: ({ componentId }) =>
setFeedback(`Save requested by ${componentId}`),
}}
/>
<p role="status">{feedback}</p>
</>
)
}This complete host example validates each update against the latest reducer state. The Playground's Layout mode follows the same pattern and reports invalid output without changing the current layout. Keep a createStateStore({}) instance in host state and pass it to CompositionView with the validated spec and registered action handlers. Persisted selections are stored by component and item ID. Moving a menu to another parent can remount it: persisted selections survive when the same store and IDs are retained, while open state and focus can reset.
Apply live changes
An update includes the revision it was based on, plus a complete spec or JSON Patch operations:
{
"baseRevision": 0,
"patch": [
{
"op": "replace",
"path": "/elements/files/props/label",
"value": "Project actions"
},
{
"op": "replace",
"path": "/elements/files/props/closeOnSelect",
"value": false
}
]
}Use applyCompositionUpdate(currentDocument, output, allowedActions) against the latest document, for example inside a reducer. It validates the entire candidate before committing. Invalid arguments, missing children, cycles, unregistered actions, and stale revisions leave the working interface unchanged.
Connect your model
Export compositionPrompt(allowedActions) and compositionUpdateJsonSchema from @uthereal/ui/composition. Send these with the current document to your model. Pass its completed, parsed response to your reducer, and return validation errors for a retry when needed. Adapt the JSON Schema to your provider's supported structured-output subset if required.
The library does not impose a model provider, transport, or agent framework.
State and actions
- The agent controls supported component arguments and layout structure.
- Your application owns persistent selections, fetched data, caches, loading and error state, and registered action handlers.
- Open state and keyboard focus follow the mounted component's lifecycle. Moving a component to another parent can remount it.
- Editing configuration does not execute an application action.
- Composition props are literal, schema-validated values. Expressions, API calls and arbitrary store writes are outside this contract.
See React and JSON integration for the ownership boundary and a live example. Keep the agent document separate from host data, then validate the effective props before rendering.
These exports form the default kit over every registered definition, listed in @uthereal/ui/definitions. To offer a different set of components, pass their definitions to createCompositionKit and render with a registry from createCompositionRegistry; the catalog, schemas, prompt and validation follow those definitions.
Documentation for agents
Use llms.txt to discover pages, llms-full.txt for the complete text, or Copy page on any documentation page. These are generated from the same MDX content as this website.
Theme and motion are ordinary arguments
The same theme and motionOptions objects work in React props, the composition catalog, and model-generated JSON. Agents can adjust presentation without providing CSS, callbacks, or executable code.
import { applyDropdownEdit } from '@uthereal/ui/agent'
const result = applyDropdownEdit(
current,
{
theme: { mode: 'dark', accent: 'blue', tokens: { popupRadius: 16 } },
motionOptions: {
transition: { type: 'spring', stiffness: 340, damping: 38 },
enter: { offset: 8 },
},
},
allowedActions,
)
if (result.success) setConfig(result.config)For a single component, applyDropdownEdit merges supplied object fields; item arrays replace. Changing the transition type replaces that transition variant. Omitted fields stay unchanged, and explicit zero values are preserved. Send { theme: null } or { motionOptions: null } to remove that entire override group and return to recipe or motion preset values. null is an edit operation, not a component creation argument.
Composition updates follow JSON Patch semantics: add or replace an object replaces that object. To preserve its siblings, update a specific existing token path. Create an absent theme object with add before addressing children; use remove to reset an individual token. Both update paths validate the full candidate atomically.
See Theming and Motion for the complete vocabulary, ranges, and defaults. Reduced motion and immediate keyboard feedback remain enforced regardless of agent output.