Quick Start
Freesail is an Agent-driven UI SDK that enables AI Agents to drive user interfaces. Freesail allows agents to render interfaces remotely by streaming UI to supported clients via the A2UI Protocol, without generating framework-specific code or raw HTML.
🚀 GET STARTED
Section titled “🚀 GET STARTED”To quickly run the full example stack (Agent + Gateway + React UI):
- Download the quickstart repository from Github.
- Create a .env file in the project working directory by copying the .env.example file. The quickstart example supports Gemini (default), OpenAI, and Anthropic Claude. Set
LLM_PROVIDERand the corresponding API key in.env. - Execute the provided script from the project root:
bash ./run-all.shThis script automatically builds all packages and launches the Gateway, Agent, and React UI as three independent processes.
You can access the React app at the default url http://localhost:5173. Chat with the agent and ask it to perform various activities. The example agent has no connectivity to any other API other than the LLM and gateway. Feel free to customize the agent.
🏗️ ARCHITECTURE
Section titled “🏗️ ARCHITECTURE”The Three Nodes of Freesail
Section titled “The Three Nodes of Freesail”Freesail operates on a three-node architecture that separates agent logic from A2UI message streaming:
- Agent (Orchestrator): The intelligence layer (e.g., LangChain) decides what to show using MCP tools. It connects to the Gateway via MCP Streamable HTTP transport and generates structured JSON data, guided by the Gateway.
- Freesail Gateway (Bridge): A server acting as the translation engine that streams A2UI messages to the Frontend via Server-Sent Events (SSE). It also injects catalog definitions into the Agent’s system prompt and validates tool calls against the catalog schema.
- Frontend (Renderer): The presentation layer (e.g., React) translates incoming A2UI messages into dynamic UI statefully. It maintains the local Data Model, handles user interactions, and sends response back to the agent via the Gateway.
🧠 CONCEPTS
Section titled “🧠 CONCEPTS”Schema-First Development
Section titled “Schema-First Development”Freesail enforces a “Headless & Contract-First” philosophy.
- You must define a component’s schema in a catalog.json contract first.
- The UI Developer builds the React component and registers the catalog, making the component available to the Agent via tools.
- This strategy prevents the Agent from hallucinating invalid components and ensures the UI and Agent do not drift out of sync.
A2UI Protocol
Section titled “A2UI Protocol”The Agent-to-User Interface (A2UI) is a JSON protocol managing bi-directional communication.
- Server → Client: Uses SSE for messages like
createSurface, updateComponents, updateDataModel, and deleteSurface. - Client → Server: Uses HTTP POST for messages like
actionto report interactions and error to report runtime or validation errors.
Bi-directional State Sync
Section titled “Bi-directional State Sync”- The Client owns the state and the data model.
- Upon user actions, the Client transmits the full relevant context back to the Agent.
- The AI Agent takes further action, updates the UI components or the data model.
🛠️ HOW-TO
Section titled “🛠️ HOW-TO”1. Setting Up the Gateway
Section titled “1. Setting Up the Gateway”The Gateway runs as a standalone Node.js process exposing two interfaces:
- Agent-facing: MCP Streamable HTTP binding by default to 127.0.0.1 on Port 3000.
- UI-facing: HTTP SSE + POST binding to 0.0.0.0 on Port 3001.
Start the gateway using the Freesail CLI:
npx freesail run gatewayConfiguration can be supplied via CLI flags or a freesail.config.json file. See the Gateway CLI reference for all options.
2. Setting Up the React Application
Section titled “2. Setting Up the React Application”- Install the required packages:
npm install freesail @freesail/standard-catalog @freesail/chat-catalog- Use
FreesailProviderwith a singlegatewayURL to manage the connection and register component catalogs via thecatalogsprop. - Create designated rendering areas using
FreesailSurface.
3. Creating Custom Catalogs
Section titled “3. Creating Custom Catalogs”You can extend the UI vocabulary by bundling a custom catalog:
- Scaffold a new catalog with
npx freesail new catalog. - Declare which components and functions to import from existing packages in
catalog.include.json, then runnpx freesail include catalog --package @freesail/standard-catalog. - Define additional component schemas in
components.jsonand implement them incomponents.tsx. - Run
npx freesail prepare catalogto merge schemas and generate the resolved catalog JSON. - Pass the resulting
CatalogDefinitiontoFreesailProviderviacatalogs.
4. Building the AI Agent
Section titled “4. Building the AI Agent”- Connect the agent to the gateway’s MCP endpoint using
StreamableHTTPClientTransport. - Use
FreesailAgentRuntimefrom@freesail/agent-runtimeto manage session lifecycle and action routing. - The agent invokes tools like
create_surfaceandupdate_componentsto direct the UI. - Bind component properties to the data model using path variables and update them using
update_data_model. - The Gateway streams A2UI messages to the UI for rendering.
📚 NODE PACKAGES
Section titled “📚 NODE PACKAGES”Packages Directory
Section titled “Packages Directory”@freesail/core: Pure TypeScript logic handling protocol definitions, parser, and transport.@freesail/react: React implementation of the Renderer.@freesail/gateway: Node.js MCP bridge server.@freesail/standard-catalog: Standard UI catalog (components and functions).@freesail/chat-catalog: Chat UI components for agent-driven chat surfaces.@freesail/agent-runtime: Runtime library for building Freesail agents.