UI2 Docs
Quick Start

Thinking in UI2

Learn how the UI2 API is structured.

UI2 is built around "intents," which can be thought of as possible user actions. As UI2 developers, you are responsible for defining these intents and their associated actions. The UI2 API will handle the rest, including prompting the AI, parsing output, and more.

The Structure of an Intent

Each intent has a name, an optional description, as well as a list of parameters.

Furthermore, each intent has 2 main "lifecycle" events:

  • onIntent (Required): A function that is called when the intent is identified
  • onCleanup (Optional): A cleanup function that is called when the intent is no longer relevant

For this demo, we don't have to worry about the cleanup. You can learn more about cleanup in the documentation, or in the React Quick Start. It's relevant when there is an actual frontend tethered to UI2.

Choosing Our Intents

For our "Sum and Square" app, we'll make 2 key intents:

  • sum
    • Parameters: 2 numbers to sum
    • onIntent: Logs their sum
  • square
    • Parameters: Which todo to mark as complete
    • onIntent: Show a preview of the todo to be marked as complete

As you can see, all of these intents have a very similar lifecycle. As such, UI2 is designed to be compatible with a wide variety of different applications.

Now, let's see how we can set this up in code.

On this page