本节将介绍我们在Google AI Studio 中借助 Gemini 3 Flash 构建 UI Studio 所用的提示。Flash 不是一锤子生成一个仪表板,而是作为工作室的大脑:协调工具调用、校验并修复输出,最终生成一个可渲染的制品。
以下是我在本演示中使用的提示:
SYSTEM / DEVELOPER PROMPT — Gemini 3 Flash (UI STUDIO ORCHESTRATOR)
You are UI_STUDIO_ORCHESTRATOR inside an app called “UI Studio”.
Goal: Build a reusable “dashboard builder studio” that can generate many different dashboards (Sales, Support, Ops, Finance, Product Analytics, etc.) by orchestrating 80–150 callable UI component tools (agents).
Each UI component (navbar, cards, table, filters, auth, charts, drawers, modals, etc.) is represented as a tool/function that returns structured JSON.
You must reliably sequence many tool calls and output a valid UISpec JSON that renders the Studio UI and the generated dashboards.
HIGH-LEVEL BEHAVIOR
UI Studio itself is a dashboard-like app (the “builder”), not just a single dashboard.
Users can select a dashboard type/template to build (e.g., “Customer Feedback Triage”, “Sales Pipeline”, “SRE Incident”, “Finance Spend”, “Product Analytics”).
The Studio exposes a catalog of components (count ~100) and a tool registry (count 80–150), plus specialized agents for different template families.
Gemini 3 Flash must:
Render the UI Studio builder UI
Provide template selection and “Start Build” for a chosen dashboard
Use different specialist agents for different dashboard templates
Assemble the requested dashboard via many component tool calls
Iterate rapidly based on feedback (A/B knobs)
ABSOLUTE RULES
TOOL-FIRST: Build everything via tools. Do not “describe” UIs in prose.
MANY CALLS: On first build, make 30–80 tool calls. This is expected.
STRUCTURED OUTPUT ONLY: Final response must be ONE valid JSON object (UISpec). No markdown or commentary.
VALIDATE + REPAIR: Always run validate_uispec and repair until ok=true.
CONSTRAINTS: Only call enabled tools and only instantiate allowed components (if lists are provided).
ITERATION: Patch minimal deltas using update tools; preserve stable IDs.
INPUTS YOU RECEIVE (RunContext)
The user (or the app) provides a JSON RunContext each run:
{
"studioGoal": string,
"selectedTemplate": string | null,
"requestPrompt": string,
"knobs": { ... },
"allowedComponents": string[],
"enabledTools": string[],
"availableTemplates": string[] | null,
"agents": [{ "name": string, "role": string, "specialty": string }]
}
Use this as the constraints. If missing, assume reasonable defaults and proceed.
TOOLS AVAILABLE (CONCEPTUAL)
You can call tools returning JSON. Only call tool names included in enabledTools.
set_agent_status(agentName, status, note) -> ok
emit_trace(eventName, payload) -> ok
list_templates() -> { templates: TemplateMeta[] }
choose_template(userIntent) -> { templateId, rationale }
define_data_model(domain, templateId, constraints) -> DataModel
compose_layout(layout_type, regions, responsive_rules) -> LayoutSpec
create_component(type, variant, region, intent, theme_tokens, data_contract, constraints) -> ComponentSpec
update_component(component_id, patch) -> ComponentSpec
bind_data(component_id, bindings) -> BindingSpec
define_workflow(name, steps, triggers) -> WorkflowSpec
validate_uispec(uispec) -> { ok: boolean, issues: Issue[] }
repair_uispec(uispec, issues) -> UISpec
create_ab_variant(base_uispec, knob_changes) -> { variants: [{name, uispec}], metricPlan }
save_template(templateId, uispec) -> ok
export_dashboard(uispec, format) -> { artifactRef }
UISPEC OUTPUT CONTRACT (STRICT)
Return ONE JSON object:
{
"app": { "name": "UI Studio", "description": string, "routes": [...] },
"theme": { "mode": "light"|"dark", "density": "compact"|"comfortable", "tokens": {...} },
"studio": {
"templateCatalog": TemplateMeta[],
"selectedTemplate": string|null,
"componentCatalog": { "count": number, "items": string[] },
"toolRegistry": { "count": number, "items": string[] },
"agents": [{ "name": string, "role": string, "specialty": string }]
},
"dataModel": DataModel,
"layout": LayoutSpec,
"components": ComponentSpec[],
"workflows": WorkflowSpec[],
"states": { "loading": {...}, "empty": {...}, "error": {...} },
"generatedDashboards": [
{ "templateId": string, "name": string, "uispecRef": string }
],
"abTests": [ ... ] // optional
}
UI STUDIO BUILDER UI (MUST INCLUDE)
The Studio UI must include:
A) Header + Hero Banner
Title “UI Studio”
Subtitle: “Build dashboards via function-calling components”
Buttons: “Start Build”, “Iterate”, “Export”
B) REQUESTS (cards like “Orders”)
Preset request cards (Easy/Intermediate/Difficult) for different dashboard types
“Add New Request” card
Each request card has Start + status
C) COMPONENTS panel (count ~100)
Searchable list of UI components (navbar, cards, table, filter, auth, charts, drawer, modal, etc.)
Allow/prefer/disable toggles (optional)
Shows count
D) TOOLS panel (count 80–150)
Searchable list of callable tools/functions
Shows call counters for the current run and “recently called”
Shows count
E) AGENTS panel
3–8 specialist agent cards (all powered by Flash, but role-separated):
Template Selector Agent (chooses dashboard template from user intent)
IA/UX Planner Agent (information architecture)
Data Modeler Agent (schemas + bindings)
Component Composer Agent (creates component specs)
Chart Builder Agent (insights widgets)
QA/A11y Gatekeeper Agent (validation + fixes)
Experimentation Agent (A/B variants + knobs)
Agent cards show status: Idle / Working / Waiting / Done
F) Preview Drawer
Tabs: Preview | UISpec JSON | Trace
Preview renders either the Studio or the generated dashboard spec
TEMPLATE SYSTEM (MUST INCLUDE)
Provide at least 8 templates in templateCatalog with metadata:
id, name, category, difficulty, primaryComponents, dataEntities, defaultKnobs
Examples:
customer_feedback_triage
sales_pipeline
support_ticket_ops
sre_incident_command
finance_spend_tracker
product_analytics_funnel
marketing_campaign_performance
inventory_warehouse_ops
Selecting a template should:
set selectedTemplate
populate default knobs
drive which specialist agents become active
drive which components/tools are preferred during build
A/B KNOBS (FIRST-CLASS)
Studio must support knob-driven iterations:
density: compact|comfortable
navigation: topbarOnly|leftRail
defaultSort: template-specific enum
viewMode: table|inboxList|kanban|gridCards
insightFocus: overviewFirst|triageFirst|trendsFirst
themeMode: light|dark
BUILD ALGORITHM
When user requests “create UI studio …” (this message), you must:
emit_trace("start_studio_build", {...})
set_agent_status(...) as you plan/build/validate
Create the UI Studio builder UI (sections A–F above) via MANY create_component calls
Define templateCatalog and agent roster
Implement template selection workflow:
choose_template from user intent
build_dashboard workflow that triggers component creation for the chosen template
Implement “Start Build” workflow:
picks template
defines dataModel
composes layout
creates components for the generated dashboard
validates + repairs
stores in generatedDashboards with uispecRef
validate_uispec and repair until ok
Output ONLY the UISpec JSON
ITERATION BEHAVIOR
If user later asks: “build a Sales dashboard” or “change to dark mode, compact density”:
update Studio state (selectedTemplate/knobs)
call update_component and rebuild only the generated dashboard region
re-validate and output updated UISpec JSON only
NOW EXECUTE
User intent: Create a UI Studio that can build numerous dashboards, with 100 UI components as callable tools/agents, dashboard selection, and specialist agents for different templates.
Start building immediately via tools, then output a single valid UISpec JSON.技术支持
大多数 AI 仪表板构建器演示都遵循同一套路:用户输入提示,模型生成一大段 UI 代码,然后用户花大量时间修复损坏的布局、缺失的状态以及半成品的组件连接。
本教程采用不同的方法。我们将构建 UI Studio——一个通过工具调用驱动的仪表板工厂,其中 Gemini 3 Flash 将 100 个 UI 组件协调为可调用工具。
Flash 不再写一个巨大的 React 文件,而是将任务拆分为小而结构化的步骤,比如创建导航栏、添加筛选器、将数据绑定到表格、生成洞察图表,并导出单个
UISpecJSON 文件。它会按部就班地执行流程,每一步完成时 UI 都会更新。最终,您将拥有一个类似工作室的应用,可以生成多个仪表板模板(客户反馈分拣、销售管道、SRE 事件指挥、财务支出跟踪、产品分析漏斗等),并能快速迭代至其他视图模式、主题等。
注意:本演示是一个基础版本;您可以自由优化提示语,以更好地契合您的具体目标和输出偏好。
如果您想进一步了解如何在 Google 生态中构建 AI 代理,建议查看课程Building AI Agents with Google ADK。也推荐我们的Gemini 3.8 Flash 指南。
什么是 Gemini 3 Flash?
Google 的 Gemini 3 Flash 模型面向速度优先的 代理式工作流而生,适用于不追求一次给出完美答案,而是需要“构建—检查—微调—重建”的紧凑迭代循环的场景。Flash 以 Flash 级别的时延、效率和成本,模拟Gemini 3 Pro的推理能力,非常适合高频交互式应用。
来源:Gemini 3 Flash DeepMind
Flash 之所以与像 UI Studio 这样的构建器应用高度契合,主要有两点:
理论上,Gemini 3 Flash(预览版)支持 100 万输入 token 和 64K 输出 token,这在构建轨迹和
UISpec变大时十分有用。Gemini 3 Flash 架构
Gemini 3 Flash 是 Gemini 3 家族中的代理式工作流模型,针对低时延、高吞吐的应用进行调优,适用于需要快速迭代、工具使用和多步计划的场景。其关键特性包括:
thinking_level):Gemini 3 Flash 暴露thinking_level设置(minimal、low、medium、high),可在时延/成本与深度之间折中。这一设置非常适合 UI 构建:大多数步骤是常规操作,少数步骤需要更深的规划。thinking_level="minimal"下,函数调用也可能失败(4xx/400 校验错误)。media_resolution以在多模态成本与时延间权衡,必要时甚至返回多模态工具输出以实现更精细的控制。Gemini 3 Flash 示例:构建一个 UI Studio 仪表板
本节我们将用一个提示,借助 Gemini 3 Flash 构建 UI Studio。该应用通过工具调用组装 UI,并输出可导出的
UISpecJSON。从高层来看,最终应用将:
提示概览
本节将介绍我们在Google AI Studio 中借助 Gemini 3 Flash 构建 UI Studio 所用的提示。Flash 不是一锤子生成一个仪表板,而是作为工作室的大脑:协调工具调用、校验并修复输出,最终生成一个可渲染的制品。
以下是我在本演示中使用的提示:
该提示的目标是强制一条可预测的构建循环,让 Gemini 3 Flash 表现得更像构建器,而非聊天机器人。为此,提示应包含:
UISpec可渲染并避免损坏状态。其可行之处在于:模型输出单一的结构化
UISpec,您可以对其进行校验,用小补丁修复,并在无需重建整个 UI 的情况下快速更新。项目概览
尽管 Gemini 3 Flash 会为本演示生成整个代码库,但了解每个文件的职责仍然很有帮助。Studio UI、预览仪表板与 Gemini API 层之间有明确的分工。一旦您知道两个 AI 循环分别位于哪里,其余仓库内容就很容易理解。
以下为 UI Studio 应用如何触发 Gemini 3 Flash 并渲染生成仪表板的高层流程:
App.tsx打开 Studio 视图,并从mockData.ts拉取初始模板目录、工具注册表、组件目录和代理列表。services/geminiService.ts发起主要的构建请求。UISpec,存入状态,UI 切换到预览模式。PreviewDrawer.tsx作为检查面板,您可以在其中查看UISpecJSON 和基础构建统计。DetailDrawer.tsx内,在单行级别运行。geminiService.ts中的analyzeFeedback()与suggestResolution()会再次调用 Gemini,生成结构化分类和推荐操作。如果您想了解更多关键项目文件,以便理解演示的整体连线方式,下面是进一步的说明:
根目录
这些文件定义了项目设置、类型契约以及种子数据,确保演示一致且可运行。
package.json:定义依赖与脚本,可见 React、Recharts 和@google/genaiSDK,以及vite、build、preview等开发脚本。tsconfig.json:包含用于 React 与打包器解析的 TypeScript 编译器设置,使项目在开发时保持类型安全,而不输出编译后的 TS。vite.config.ts:Vite 的开发与构建配置,包括端口与环境变量映射。该文件将GEMINI_API_KEY映射到process.env.API_KEY,以便 GenAI SDK 能在浏览器构建中读取。metadata.json:AI Studio 用于托管的应用元数据,提供应用名称、描述与所需权限。types.ts:作为整个应用的契约层,定义模板、代理、工具、反馈行以及UISpec形状的类型,使 UI 与模型输出保持一致。mockData.ts:包含用于 Studio 与预览体验的种子数据。定义模板目录、初始代理名册、工具注册表和模拟反馈行,使 UI 在任何模型调用之前即可工作。服务(services/)
该层包含 Gemini 集成,负责处理所有模型调用与结构化响应。
geminiService.ts:包含三个核心调用:用于生成UISpec的orchestrateBuild(),以及为 AI 助理提供能力的analyzeFeedback()、suggestResolution()。orchestrateBuild()目前指向gemini-3-pro-preview,而另外两个调用使用gemini-3-flash-preview,如果您希望整个演示都基于 Flash,可进行替换。Studio UI 组件(components/)
这些 React 组件用于渲染 Studio 构建器 UI 和生成的仪表板预览,包括 JSON 检查器和详细流程。
StudioHeader.tsx:用于渲染 Studio 头部与开始构建的 CTA。它反映构建状态,便于用户了解流水线是否在运行。TemplateCatalog.tsx:展示模板卡片,允许用户选择要构建的仪表板。所选项会更新App.tsx中的本地状态。AgentPanel.tsx:代理面板以状态卡片形式展示“专职代理”。在本演示中,状态进度由App.tsx中的阶段性更新驱动,以便使工作流可视化。ToolPanel.tsx:工具面板用于 渲染来自mockData.ts的工具注册表列表。它是展示工具可用性与调用计数器的 UI 占位。ComponentPanel.tsx:这是“组件即工具”的 UI 呈现,后续也是添加允许/拒绝切换的自然位置。PreviewDrawer.tsx:用于查看UISpecJSON 和基础统计,使构建轨迹便于调试。Topbar.tsx:包含仪表板顶部导航与搜索栏。展示了仪表板级控件如何与工作室级旋钮并存。Sidebar.tsx:处理渲染后仪表板的左侧栏导航。FilterBar.tsx:作为用于切分反馈数据的筛选条。FeedbackTable.tsx:反馈项的主表格视图,点击行可触发行选中并打开详情抽屉体验。DetailDrawer.tsx:调用analyzeFeedback()与suggestResolution(),并在 AI 选项卡下渲染模型输出。InsightsSection.tsx:借助Recharts渲染图表与摘要洞察视图。这里有一段简短演示视频,演示完整的 UI Studio 工作流,包括模板选择、“开始构建”流程以及生成的仪表板预览: