System prompts
Generate and customize the instructions that teach an LLM to emit valid OpenUI Lang for the component Library your ReactLynx client renders.
Use the CLI when the built-in Library and a static prompt file are enough. Use the programmatic API when tools, feature flags, custom components, or deployment policy must be assembled in backend code.
The contract to preserve
An OpenUI system prompt describes:
- the one-assignment-per-line language syntax;
- the required
rootentry point and top-down streaming order; - component signatures derived from ordered Zod schemas;
- reactive
$variablesand built-in functions; - Query/Mutation and Action rules;
- tool names and input/output schemas, when supplied;
- examples and hard constraints for parseable output.
The prompt-side Library and client renderer Library must agree on every component name and positional prop order. If they drift, the model can produce valid text for one side that the other side rejects.
1. CLI
Generate the default built-in OpenUI prompt to a file:
Print it to stdout:
Append deployment-specific rules:
The CLI uses the headless mirror of the built-in ReactLynx Library. Its prompt generation command accepts:
The CLI does not load a custom component directory or tool manifest. Use the programmatic API when the Agent contract contains custom components or rich tool schemas.
2. Programmatic usage
Build the default prompt in server-side TypeScript:
Add application policy and tool descriptions:
The client must expose a matching tool implementation:
Tool schemas teach the model what it may call; toolProvider is the code that
actually executes those calls. Do not put secrets or provider credentials in
the prompt or browser-side tool arguments.
Prompt options
buildOpenUiSystemPrompt accepts Library options, prompt feature flags, and an
optional appendix:
The Lynx OpenUI prompt builder enables bindings and toolCalls by default.
Disable them explicitly for a static-only product surface:
inlineMode is disabled by default. In the default mode, the model should
return raw OpenUI Lang only—no explanation and no Markdown code fence—so the
full response can go directly into <OpenUiRenderer response={...}>.
Custom component prompts
Keep shared Zod schemas in a framework-neutral module. The client wraps the
schema with the ReactLynx defineComponent; the server wraps the same schema
with the headless @openuidev/lang-core definition.
Install @openuidev/lang-core and zod as direct dependencies of the server
workspace when it owns custom headless definitions. Keeping the prompt
component renderer as () => null prevents server routes from importing
ReactLynx, Lynx UI components, or component CSS.
Other prompt exports
@lynx-js/genui/openui/prompt also exports:
Prefer buildOpenUiSystemPrompt() in application code so customization remains
explicit and testable.
Backend integration pattern
Send the generated prompt as the model's system instruction, preserve the raw text stream, and return that text to the client. The server does not need to parse the UI simply to forward it, but it should enforce its own model-output and tool policies.
On the client, append every received delta to one string. Pass that accumulated
value to response and keep isStreaming={true} until the server signals
completion. Use an AbortController to cancel an older generation before a new
turn starts.
When onError reports stable parser/runtime errors, an application may send a
compact description back to the Agent for correction. Do not automatically
retry forever; bound correction attempts and retain the original user request.
Choosing an approach
Use the CLI when:
- the built-in component contract is sufficient;
- a checked-in or generated static prompt file is convenient;
- deployment policy fits in an appendix.
Use programmatic generation when:
- tools have request- or deployment-specific schemas;
- feature flags differ between products;
- the Library contains custom or overridden components;
- examples, groups, or policy are assembled from code.
For the renderer-side contract, continue with Libraries, built-ins, and custom components.

