MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

CopilotKit/OpenIntelligentUI 深度拆解:当生成式 UI 成为一种协议

项目背景与痛点

LLM 应用走到 2024 年之后,几乎所有人都撞上了同一堵墙:对话界面容不下真实业务。

一个客服 Copilot 能写出一段漂亮的退款说明,却无法在对话框里直接弹出一张可勾选的订单列表;一个数据分析 Agent 能口算出"本月转化率下降 3 个点",却没法顺手渲染一张折线图让用户点开下钻。结果就是——模型在说,用户在抄,前后端在二次开发。每接入一个新场景,工程师就得手写一套卡片组件、写一套意图识别分支、维护一套状态同步逻辑。

更根本的问题不在组件,而在协议。模型输出的是 token,前端需要的是结构化指令;两者之间缺少一层稳定的、可流式解析的、带状态的通信约定。绝大多数团队在这一层各自造轮子,造出来的东西既不可复用,也没法跨模型迁移。

OpenIntelligentUI 就是冲着这层空白来的。它的项目定位是 Open-Source Generative UI Framework——不是又一个聊天组件库,而是想把"AI 输出什么、前端渲染什么"这件事标准化。

核心技术揭秘

CopilotKit 生态的整体设计思路可以概括为:把前端能力注册成模型的可调用资源,把模型输出降级成可验证的指令流。从公开的 API 形态推断,其数据流大致如下。

graph TD A[用户在对话中提问] --> B[Copilot Runtime 服务端] B --> C[LLM 推理与 Tool 调用] C --> D{"输出类型判定"} D -->|"纯文本"| E[按 Markdown 渲染消息流] D -->|"结构化指令"| F[生成式 UI 指令流] F --> G[前端协议解析器] G --> H[组件注册表匹配] H --> I[实例化 React 组件] I --> J[组件内部状态回写] J --> K[useCopilotReadable 上下文注册] K --> B E --> B

几个关键技术点值得展开:

1. UI 即工具(UI as Tool)。 框架把前端已注册的组件描述成 function schema 注入到模型的 tool 列表里。模型决定"要不要渲染这张卡片"时,实际是在做一次 tool call。这带来一个隐性好处:组件是否可用、参数长什么样,全部由前端声明,模型没有自由发挥空间,幻觉被压缩在参数填充层面而非组件层面。

2. 可读上下文的反向注入。 useCopilotReadable 这类钩子把前端状态(当前选中的订单、正在编辑的表单)序列化后挂进上下文。这是生成式 UI 真正难的地方——不是渲染一次,而是渲染后用户的操作能回到模型视野里,形成闭环。设计上它更像一个"前端状态总线",而不是简单的 prompt 拼接。

3. 流式增量渲染。 结构化输出的 JSON 是逐 chunk 到达的,框架必须在 JSON 尚未闭合时就开始尝试解码、渐进挂载组件。这要求解析器容忍不完整片段、做 schema 校验与降级,否则一个畸形 token 就能让整棵 React 树崩掉。这是工程实现上最容易翻车的一环。

4. Runtime 作为协议中转。 服务端承担鉴权、模型适配、消息路由与工具调度,前端只依赖一个稳定的通信契约。这种分层让"换模型"和"换前端框架"解耦——代价是 Runtime 成为必须自托管的中间件。

功能亮点与差异

与 Vercel AI SDK 的生成式 UI 相比,二者的哲学不同:AI SDK 更偏"渲染器",给你一套 RSC 流式渲染原语,怎么接业务自己决定;OpenIntelligentUI 更偏"交互协议",强调双向——不仅模型能渲染,用户操作也能回流。与 LangChain 系的 Agent 框架相比,它不试图接管编排逻辑,只专注 Agent 与 UI 之间的那一段链路。

真正的差异化在于开放协议这件事本身。一旦指令格式、上下文注册、工具描述被标准化,组件库就可以跨项目复用,多模型切换也只是换一层适配器。这是从"框架"走向"生态"的关键一步。

应用场景与落地建议

适合的场景很明确:需要模型参与操作、而非仅提供答案的业务界面——智能 CRM、运维控制台、数据分析工作台、低代码配置面板。反过来,纯问答客服、内容生成类应用用它属于杀鸡用牛刀。

生产落地有几点必须提前想清楚:

  • 安全边界。 允许模型触发 tool call 意味着它可能触达真实写操作。务必把"读"和"写"的工具分离,写操作加人工确认环节,别让模型一句话就直接扣款。
  • 降级设计。 流式 JSON 解析失败、组件未注册、模型返回了不在白名单里的组件名——这些都必须有兜底 UI,而不是白屏。
  • 上下文体积。 useCopilotReadable 注册的状态会随对话累积,不做裁剪很快会撞上 token 上限。建议按会话阶段动态注册、及时释放。
  • 可观测性。 生成式 UI 的调试远比普通前端痛苦,务必在 Runtime 层埋好指令流的原始日志。

综合评价

优点:方向踩在了正确的位置上——把生成式 UI 当作协议而非组件库来解决,这是少数派但更可能长出生态的路径;双向上下文的设计比单向渲染方案更贴近真实业务;React 生态的接入成本较低,钩子式 API 上手快。

短板:Runtime 的存在提高了部署复杂度,自托管对中小团队是额外负担;流式结构化输出的稳定性极度依赖模型能力,弱模型下体验断崖式下跌;生成式 UI 的调试、测试、快照对比目前整个行业都缺成熟工具链,这个项目也不例外。

一句话总结:它试图定义的是"AI 与界面之间怎么说话",而不是"界面长什么样"。前者更难,但一旦成立,价值也高一个量级。 现阶段建议在非关键路径上先试水,把协议跑通、把降级做扎实,再谈规模化。

关于

GitHub 原始描述(英文)

Open-Source Generative UI Framework

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

CSS
Dockerfile
JavaScript
Makefile
Python
TypeScript

README

Open Intelligent UI

Answers you can interact with.

An open-source chat interface that turns questions into explanations, comparisons, and working tools.

Built with CopilotKit and AG-UI. · Get started · Overview · Demos · Architecture · Contributing

CI License: MIT

GitHub Trending: #5 Repository Of The Day Trendshift: #3 TypeScript Repository Of The Day

Clone the project, connect your model and visualization router, and adapt the interface and agent to your own workflows.

Building with Open Intelligent UI? Talk to an engineer →


The 54-second launch film: ask, explore a 3D explanation, compare options, use a calculator, and follow a coastal itinerary. These are rendered launch scenes; the app runs the agent for each request.

Overview

Ask a question, explore an idea, compare your options, or make a tool for the moment. The agent chooses a direct text answer, a native component, or a custom interactive UI based on what helps you accomplish the task.

  • Understand — explore a mechanism, step through an explanation, or change a variable.
  • Compare — examine criteria, assumptions, and tradeoffs side by side.
  • Make a tool — use a calculator, planner, or interactive model with working controls.

The interface opens directly to chat. Type your request or choose a starter suggestion to begin an agent run. Text, native components, and generated interactive answers appear in the conversation. Sample numbers are illustrations, not live business or weather data.

Demo scenes

From the launch film: explanations, comparisons, working tools, and maps in one conversation.

Explore in 3D

Rotate an airplane with labeled pitch, roll, and yaw axes. Change the angles, play a smooth demonstration, or reset the view.

3D plane · 4 seconds.

Turn comparisons into charts

Compare exact values in a table, then ask a follow-up to visualize the differences. Jev selects A2UI for basic tables and Open Generative UI for charts and more complex visuals.

Tables and charts · 8 seconds. Plan names and prices are illustrative.

Make a tool for the moment

Split a bill with controls for the total, tip, and group size. Calculations update as you change the inputs.

Bill splitter · 5 seconds.

Follow a trip on the map

Explore a coastal itinerary with numbered pins and destination photos. The app uses live USGS tiles, credits its photos, and lets you pause, replay, or select a stop. Connections illustrate the itinerary; they are not verified driving directions.

Coastal map · 4 seconds.

Scene gallery
3D explanations Tables → charts
3D airplane with pitch, roll, and yaw controls A plan comparison becomes a cost-per-seat chart
Explore aircraft rotation with labeled axes and sliders. Compare exact values, then visualize them with a follow-up.
Interactive tools Maps
Bill splitter recalculating the share per person California coastal itinerary with numbered map pins and photo cards
Change the group size and tip; the calculation updates. Follow a coastal itinerary with map pins and destination photos.

Try it

  • Animate a coastal trip — a real USGS map with numbered pins, credited destination photos, and a six-second pin-drop sequence. Pause, replay, or select a stop. Connections are illustrative, not verified driving directions.
  • Pitch, Roll & Yaw — rotate a 3D airplane with labeled axes, angle controls, smooth demonstrations, and reset.
  • Find your kind of weekend — compare trip ideas and adjust your preferences.
  • Split the bill fairly — change the total, tip, and group size in a working calculator.

These starters run the agent; they are not prerecorded responses. Jev chooses the presentation, so outputs can vary. Map tiles and destination photos require network access. Streaming answers preserve your reading position, reveal text as it enters view, and show the copy action on hover or keyboard focus (always available on touch).

Get started

Prerequisites: Node.js 22+, pnpm 9+, Python 3.12+, and uv.

git clone https://github.com/CopilotKit/OpenIntelligentUI.git
cd OpenIntelligentUI
make setup
# Optional: set shared OPENAI_API_KEY and TYPESAFE_API_KEY in apps/agent/.env
# Or use API keys in the chat header after starting the app
make dev

Open the app. The agent health endpoint confirms the agent service is running. See Getting started for configuration and verification.

The default model is chat-latest, OpenAI’s documented alias for the latest ChatGPT Instant model, requiring OPENAI_API_KEY. Jev (jev-latest, requiring TYPESAFE_API_KEY) selects the renderer and visualization for each user turn. Basic tables use A2UI; charts, diagrams, calculators, and maps use Open Generative UI. Provider failures are surfaced instead of silently substituting another router or model. See Visualization routing.

Use your own API keys

The chat asks for both keys before sending your first message or example prompt and keeps your draft while you set them up. Open API keys in the chat header, enter an OpenAI key and a Jev key, then choose Test connection and Save keys. The connection test makes a small request to each provider. Your keys use chat-latest for answers and jev-latest for visualization routing, with usage billed to your provider accounts.

Keys stay in browser memory until refresh or Clear keys; the app does not save them in browser storage. Requests send them through the application server to their respective providers. They are kept out of chat state and checkpoints, and hosted LangSmith tracing is disabled for requests using your keys. Only use this feature on a deployment whose operator you trust. Saving or clearing keys starts a new chat; New chat keeps your keys for the current session.

The agent can run without shared provider keys. Visitors must then supply both keys before chatting. Configured server credentials remain available to direct API clients that omit visitor keys; the chat interface requires visitors to add their own keys.

How it works

The Python Deep Agent uses a task-first system prompt and focused skills. CopilotKit carries the agent stream to the Next.js app. Native components handle supported structured tasks; generateSandboxedUi streams custom HTML, CSS, and JavaScript into an isolated iframe.

Custom UI parameters must arrive in this order:

initialHeight → placeholderMessages → css → html → jsFunctions → jsExpressions

Local controls run inside the sandbox. A user-clicked follow-up can send selected values through the validated host bridge and start another agent turn. Prior outputs remain separate conversation artifacts; there is no cross-call patch API. See Product and agent behavior and Architecture.

apps/app/                Next.js + CopilotKit frontend
apps/agent/              Python Deep Agent + FastAPI
apps/mcp/                Optional standalone MCP server
packages/design-system/  Shared theme, SVG, and form styles

Development

make dev-app     # Frontend
make dev-agent   # Agent
make dev-mcp     # Optional MCP server
pnpm test       # JavaScript workspace tests
uv run --directory apps/agent pytest
make lint
make build

The launch workflow includes browser checks and a real provider smoke test. Tests and builds alone do not verify model access or a deployment.

Standalone MCP

The optional MCP server exposes skill resources, prompt templates, and assemble_document. The assembler returns an HTML document as text; a compatible host must render it and implement its bridge. It is distinct from the web app’s streaming Websandbox integration.

See the MCP server guide for HTTP, stdio, and Docker configuration.

Compatibility and documentation

Built with CopilotKit. The openGenerativeUI runtime API and generateSandboxedUi tool power the streaming experience.

Contributing

See Contributing for the development workflow and the documentation index for guides to the agent, rendering, and deployment.

License

MIT.

评论

暂无评论