Generative UI
Generative UI lets your LangGraph agent return structured JSON specs that render as Angular components in the chat. The ChatComponent auto-detects JSON specs in AI messages and renders them โ no manual wiring needed.
How It Works
When AI messages stream token-by-token, the ChatComponent classifies each message's content automatically:
The JSON path uses @ngaf/partial-json to parse incomplete JSON character-by-character, producing a live Spec signal with structural sharing โ unchanged elements keep the same object reference so Angular skips re-rendering them.
Setup
Pass a ViewRegistry via the [views] input on ChatComponent:
That's it. When the agent returns a JSON spec as a message, ChatComponent detects it and renders through your view registry.
Creating View Components
Each view component receives its props as Angular inputs. The component name in the spec's type field maps to the key in your views() call.
When the agent returns:
The render pipeline instantiates WeatherCardComponent with those props.
Streaming Behavior
Because the JSON is parsed character-by-character as tokens arrive:
- Components render as soon as enough of the spec is available
- String props grow visibly as tokens stream (e.g., a title filling in letter by letter)
- Completed elements keep their object reference โ only the currently-streaming element triggers re-renders
- The
loadinginput istruewhile the agent is still streaming
State Store
For interactive generative UI (forms, selections), pass a StateStore via the [store] input:
The store enables two-way data binding between generative UI components and your application via $state and $bindState prop expressions in specs.
A2UI Protocol
For agents that implement Google's A2UI v0.9 protocol, ChatComponent auto-detects A2UI payloads (prefixed with ---a2ui_JSON---) and renders them using the built-in A2UI catalog. See the A2UI guide for details.