How It Works
- You create a UI Resource template with HTML, CSS, and Jinja2 placeholders
- You create a UI Resource Tool and link it to the template
- When an agent calls the tool, it passes data to the template
- The template renders and displays in the chat as an iframe
Creating Templates
1
Open the Template Builder
Navigate to AI Studio > UI Resources > Create Template
2
Configure Settings
3
Define the Context Schema
The context schema specifies what data your template expects. The agent and tool use this schema to know what fields to extract from the conversation.
4
Write the Template
Use Jinja2 syntax to create dynamic HTML. Include
<style> tags for CSS within the template.5
Add Preview Data
Provide sample data to test rendering in the preview pane:
Template Syntax (Jinja2)
Variables
Conditionals
Loops
loop.index (1-indexed), loop.first, loop.last, loop.length.
Filters
Conditional CSS Classes
Macros
Define reusable components within a template:⚠️ WARNING: Templates run in a sandboxed environment. Some Jinja2 features are disabled for security.
Connecting Templates to Agents
After creating a template, you need a UI Resource Tool to make it available to an agent:- Go to AI Studio > Tools > Create Tool
- Select UI Resource as the tool type
- Set the template name in Additional Info
- Define the input schema (matching the template’s context schema)
- Write a prompt describing when the agent should display this template
- Assign the tool to your agent
AI-Powered Editing
The template builder includes an AI assistant that can modify templates using natural language:- Open a template in AI Studio > UI Resources
- Go to the Template tab
- Click the AI Edit button (sparkles icon)
- Describe your changes: “Add a button”, “Make it responsive”, “Use blue tones”
Configuration Reference
Template Fields
Troubleshooting
Template not rendering
Template not rendering
- Verify the template name matches exactly in the tool’s Additional Info
- Check the template is marked as active
- Verify context data matches the schema requirements
- Review the template for Jinja2 syntax errors
Variables showing as empty
Variables showing as empty
- Check context data is being passed correctly by the tool
- Verify variable names match the schema keys exactly
- Use
{{ variable | default('N/A') }}for optional fields
Styling not applied
Styling not applied
- Include a
<style>tag within the template - Use inline styles for critical elements
- Avoid referencing external stylesheets
Content cut off
Content cut off
- Verify Auto-Resize is enabled in the tool configuration
- Avoid fixed heights in CSS
- Use flexible layouts (flexbox, grid)
Related
- UI Resource Tool — Tool configuration and input schema
- UI Resources Guide — Design patterns, accessibility, and testing
- AI Template Editor — Edit templates with natural language
