///
This guide will walk you through the initial steps to install Better UI and set up your first AI-first tool. For a broader understanding of Better UI's philosophy and features, refer to the [Better UI
53 views
~53 views from guests
Guest views are estimated from total page views. These include anonymous visitors and users who weren't logged in when they viewed the page.
This guide will walk you through the initial steps to install Better UI and set up your first AI-first tool. For a broader understanding of Better UI's philosophy and features, refer to the [Better UI Overview] page.
To begin, you need to install Better UI and its peer dependency, Zod, which is used for schema definition.
Let's create a simple weather tool that can retrieve weather information for a given city and display it using a React component.
Let's break down each part of the weather tool definition:
tool({ ... }))tool({ ... }): This is the core function for creating a new tool.name: A unique identifier for your tool (e.g., weather, search, counter). This is how AI models will reference it.description: A human-readable description of what the tool does. This is crucial for AI models to understand when to use your tool.input: A Zod schema↗ defining the expected input parameters for the tool. Better UI leverages Zod for robust type-safety and validation. Here, city is a required string.output: An optional Zod schema defining the expected structure of the data returned by the tool. This also contributes to type-safety throughout your application..server()).server() method defines the actual logic that executes the tool.input schema is automatically type-safe and available as arguments to your handler (e.g., { city }).output schema..view()).view() method is Better UI's key differentiator, allowing you to define a React component that renders the tool's output.data (which conforms to your output schema) and returns a React element.useTool hook or by AI assistants that support UI rendering.With your first tool defined, you're ready to integrate it into your React application using the useTool hook or expose it to an AI model using toAITool().
For a deeper dive into using these tools in a React application and integrating with AI SDKs, refer to the other sections of the Better UI documentation.