Skip to content

Repository files navigation

Open Generative UI

An open-source showcase for building rich, interactive AI-generated UI with CopilotKit and LangChain Deep Agents. Ask the agent to visualize algorithms, create 3D animations, render charts, or generate interactive diagrams — all rendered as live HTML/SVG inside a sandboxed iframe.

OpenGenerativeUI.demo.mp4
3d.airplane.example.mp4

What It Does

The agent produces generative UI — not just text responses, but fully interactive visual components:

  • Algorithm visualizations — binary search, BFS vs DFS, sorting algorithms
  • 3D animations — interactive WebGL/CSS3D scenes
  • Charts & diagrams — pie charts, bar charts, network diagrams
  • Interactive widgets — forms, simulations, math plots

All visuals are rendered in sandboxed iframes with automatic light/dark theming, progressive reveal animations, and responsive sizing.

Quick Start

make setup # Install deps + create .env template# Edit apps/agent/.env with your real Anthropic API key
make dev # Start all services

Strong models required. Generative UI demands high-capability models that can produce complex, well-structured HTML/SVG in a single pass. The agent runs on Anthropic Claude — claude-fable-5 by default. Override with LLM_MODEL in your .env:

ModelNotes
claude-fable-5Default
claude-opus-4-6Strong alternative

Setting LLM_MODEL to a gpt-* name routes to OpenAI instead (requires OPENAI_API_KEY). For other providers, swap the chat model in apps/agent/src/model.py (see docs/bring-to-your-app.md). Smaller or weaker models will produce broken layouts, missing interactivity, or incomplete visualizations.

Available Commands

CommandDescription
make setupInstall all dependencies and create .env template
make devStart all services (frontend + agent + mcp)
make dev-appStart Next.js frontend only
make dev-agentStart LangGraph agent only
make dev-mcpStart MCP server only
make buildBuild all apps
make lintLint all apps
make cleanClean build artifacts
make helpShow all available commands

You can also use pnpm directly (pnpm dev, pnpm dev:app, pnpm dev:agent, etc.).

MCP Server (Self-Hosted)

The repo includes a standalone Model Context Protocol server that exposes the design system, skill instructions, and an HTML document assembler to any MCP-compatible client — including Claude Desktop, Claude Code, and Cursor.

What it provides

  • assemble_document tool — wraps HTML fragments with the full design system CSS and bridge JS, returning an iframe-ready document
  • Skill resources — browse and read skill instruction documents (skills://list, skills://{name})
  • Prompt templates — pre-composed prompts for widgets, SVG diagrams, and advanced visualizations

Claude Desktop (stdio)

Add to your Claude Desktop config (claude_desktop_config.json):

{
"mcpServers": {
"open-generative-ui": {
"command": "node",
"args": ["dist/stdio.js"],
"cwd": "/path/to/apps/mcp"
}
}
}

Claude Code / HTTP clients

# Start the HTTP servercd apps/mcp && pnpm dev

Add to .mcp.json:

{
"openGenerativeUI": {
"url": "http://localhost:3100/mcp"
}
}

See apps/mcp/README.md for full configuration, Docker deployment, and API reference.

Architecture

Turborepo monorepo with three packages:

apps/
├── app/ Next.js 16 frontend (CopilotKit v2, React 19, Tailwind 4)
├── agent/ Deep Agent (deepagents + CopilotKit middleware, skills-based)
└── mcp/ Standalone MCP server (design system + skills + document assembler)

Deep Agent + Skills

The agent backend uses LangChain Deep Agents (create_deep_agent) with a skills-based architecture. Instead of injecting all visualization instructions into the system prompt, skills are defined as SKILL.md files in apps/agent/skills/ and loaded on-demand via progressive disclosure:

apps/agent/skills/
├── advanced-visualization/SKILL.md # UI mockups, dashboards, Chart.js, generative art
├── master-playbook/SKILL.md # Response philosophy, decision trees, narration patterns
└── svg-diagrams/SKILL.md # SVG generation rules, component patterns, diagram types

Deep agents also provide built-in planning (write_todos), filesystem tools, and sub-agent support.

How It Works

  1. User sends a prompt via the CopilotKit chat UI
  2. Deep agent decides whether to respond with text, call a tool, or render a visual component — consulting relevant skills as needed
  3. generateSandboxedUi — the canonical tool the CopilotKit runtime exposes when openGenerativeUI is enabled — receives the UI as ordered streaming parameters: initialHeightplaceholderMessagescsshtmljsFunctionsjsExpressions
  4. OpenGenerativeUIMiddleware in the runtime translates the streaming tool call into open-generative-ui activity events the frontend subscribes to
  5. The demo's activity renderer (registered via renderActivityMessages) shows the html streaming in live — morphing each update into a preview iframe with Idiomorph so nothing flickers — then boots the final websandbox iframe with the shared design-system CSS and CDN importmap injected
  6. Sandbox bridge + autosize — the generated UI calls back into the host through Zod-validated sendPrompt/openLink sandbox functions, and a ResizeObserver inside the iframe continuously reports content height for seamless auto-sizing

Key CopilotKit Patterns

PatternHook / OptionExample
Open Generative UIopenGenerativeUI + renderActivityMessagesStreaming sandboxed widgets via generateSandboxedUi
Generative UIuseComponentPie charts, bar charts
Frontend toolsuseFrontendToolTheme toggle
Human-in-the-loopuseHumanInTheLoopMeeting scheduler
Default tool renderuseDefaultRenderToolTool execution status

Decision Matrix — Picking the Right Visual

User asks about...Output typeTechnology
How X works (physical)Illustrative diagramSVG
How X works (abstract)Interactive explainerHTML + inline SVG
Process / stepsFlowchartSVG
Architecture / containmentStructural diagramSVG
Database schema / ERDRelationship diagramMermaid
Trends over timeLine chartChart.js
Category comparisonBar chartChart.js
Part of wholeDoughnut chartChart.js
KPIs / metricsDashboardHTML metric cards
Design a UIMockupHTML
Choose between optionsComparison cardsHTML grid
Cyclic processStep-throughHTML stepper
Physics / mathSimulationCanvas + JS
Function / equationPlotterSVG + JS
Data explorationSortable tableHTML + JS
Creative / decorativeArt / illustrationSVG
3D visualization3D sceneThree.js
Music / audioSynthesizerTone.js
Network / graphForce layoutD3.js
Quick factual answerPlain textNone
Code solutionCode blockNone
Emotional supportWarm textNone

Tech Stack

Next.js 16, React 19, Tailwind CSS 4, LangChain Deep Agents, LangGraph, CopilotKit v2, Turborepo, Recharts

Star History

Star History Chart

License

MIT