agentskit.js
Recipes

Generative UI + artifacts

A typed JSON schema the agent emits, a framework-agnostic element tree, plus rich artifacts (code, markdown, HTML, charts).

Generative UI replaces "the agent writes a paragraph" with "the agent emits a structured element tree and your renderer decides how it looks." @agentskit/core/generative-ui ships the typed schema + validators + artifact detectors so every frontend can consume the same payload.

Install

Ships as a @agentskit/core subpath.

import {
  parseUIMessage,
  validateUIMessage,
  detectCodeArtifacts,
  type UIMessage,
  type Artifact,
} from '@agentskit/core/generative-ui'

Element types

kindPurpose
textInline text, optional bold
headingLevels 1–3
listOrdered or bullet list of strings
buttonEmits an action + optional payload on click
imageImage src + alt
cardTitled container with child elements
stackRow / column layout with children
artifactEmbeds a rich artifact (code, md, html, chart)

Artifact types

typePurpose
codeLanguage + source + optional filename
markdownMarkdown source
htmlRaw HTML + sandbox hint
chartline/bar/pie/scatter/area with rows

Agent → JSON → render

const raw = await runtime.run('Show me a cost breakdown')
const ui = parseUIMessage(raw.content)
render(ui.root)

parseUIMessage tolerates fenced \``json` blocks in surrounding prose, so you don't have to wrestle the model into pure JSON output.

Extract code blocks from plain text

const artifacts = detectCodeArtifacts(raw.content)
// [ { artifact: { type: 'code', language: 'ts', source: '...' }, start, end } ]

Useful when the agent still emits prose but you want to lift code blocks into a dedicated renderer (copy button, diff viewer, run-on- click).

See also

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page