# Deploying UAG

The following sections describe the process of creating a running instance of UAG and connecting it to a Form.io Enterprise deployment.

For documentation on deploying UAG and connecting it to a Form.io Open Source, refer to the documentation on GitHub:

{% embed url="<https://github.com/formio/uag/>" %}

## Prerequisites

The following instructions assume that Form.io Enterprise has already been deployed.  \
If there is no currently deployed instance of Form.io, refer to the appropriate deployment guide:

* [Local Deployment Guide](https://help.form.io/deployments/deployment-guide/local-deployment) - Deploy a Form.io Enterprise container on a local machine.&#x20;
* [AWS Deployment](https://help.form.io/deployments/deployment-guide/cloud-deployment/aws)
* [Azure Deployment](https://help.form.io/deployments/deployment-guide/cloud-deployment/azure)
* [Google Cloud Platform Deployment](https://help.form.io/deployments/deployment-guide/cloud-deployment/gcp-deployment)

### Preparing a Project

Deploying a UAG container requires an existing project. Remember that the [project context ](https://help.form.io/userguide/projects/understanding-the-project-context)of Form.io means the AI agent will not be able to access forms or resources outside of this project.

Before proceeding:

1. Within the Form.io Developer Portal, open the **project** the UAG will connect to.\
   Create a project if one does not already exist.
2. Note the **Project URL** at the top of the page.\
   This will be `PROJECT`environment variable required later.
3. Click **Forms** from the left-hand menu of the Developer Portal, open the **User Login Form.**
4. Click **Embed** from the top menu bar.\
   Record the embed URL, this will be the `LOGIN_FORM` environment variable.
5. Open the project **Settings** page from the left-hand menu.
6. Click **API Settings** on the left side of the Settings panel.
7. Under the **API Keys** tab, click **+ Create Another.**&#x20;
8. Give the key a descriptive name and click **Save**. \
   Record the string of characters. This will be the `PROJECT_KEY` environment variable.&#x20;

### Tag Forms and Resources

UAG will only have access to forms and resources that are tagged `UAG`. Open each form or resource that should be available to AI agents and apply the necessary tag:

1. Open the project UAG will connect to in the Developer Portal and open **Forms** on the left-hand menu.
2. Click the form name to open it, then click the **...** hotdog menu on the top bar.
3. From the dropdown, select **Form Settings**.
4. Scroll down to the **Form Tags** option and enter *UAG* in the text field.&#x20;
5. Click **Save Settings** on the form settings page to complete the process.

Repeat these steps for all forms and resources that UAG needs access to.

## Create the UAG Container

While the UAG container does not necessarily need to exist on the same host as the rest of the Form.io Platform, most users will choose to do so.

Follow the steps for the appropriate provider to deploy the UAG.

### AWS

To begin, open the `docker-compose.yml`  included in the multicontainer.zip created during the [initial deployment](https://help.form.io/deployments/deployment-guide/cloud-deployment/aws#generate-deployment-package) of Form.io in a text editor.

Add the following to the `services` section:

```docker
  formio-uag:
    image: formio/uag:rc
    restart: always
    links:
      - api-server
    depends_on:
      - api-server
    environment:
      PORT: 3200
      DEBUG: formio.*
      PROJECT: CHANGEME
      PROJECT_KEY: CHANGEME
      JWT_SECRET: CHANGEME
      JWT_EXPIRE_TIME: 525600
      LOGIN_FORM: CHANGEME
      BASE_URL: CHANGEME
      UAG_LICENSE: CHANGEME
    ports:
      - "3200:3200"
```

{% hint style="info" %}
Some environment variables may not apply to all deployments.
{% endhint %}

On the Elastic Beanstalk Console, open the environment on which Form.io is deployed.

Update the **Environment Properties** table with any environment variable that were not already included.

A reference of of all potentially applicable properties is provided:

| Variable          | Description                                                                                                                                                                                              | Default | Example                                         |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ----------------------------------------------- |
| PROJECT           | The Project URL previously recorded.                                                                                                                                                                     |         | [http://localhost:3000](http://localhost:3000/) |
| PROJECT\_KEY      | The Project API Key previously recorded.                                                                                                                                                                 |         | CHANGEME                                        |
| UAG\_LICENSE      | <p>The license to run the UAG against a Form.io Enterprise Deployment.<br>Contact <a href="mailto:support@form.io"><support@form.io></a> to purchase a license or request a trial.</p>                   |         |                                                 |
| PORT              | The port to run the UAG server on.                                                                                                                                                                       | 3200    | 3200                                            |
| DEBUG             | Variable used to perform debug logs of server activity                                                                                                                                                   |         | formio.\*                                       |
| PORTAL\_SECRET    | Allows the UAG to connect to the Form.io Enterprise Portal.                                                                                                                                              |         | CHANGEME                                        |
| JWT\_SECRET       | A secret used to generate and validate JWT tokens generated through the authentication process of the UAG. This does not need to match the JWT\_SECRET of the Enterprise Server that it is connected to. |         | CHANGEME                                        |
| JWT\_EXPIRE\_TIME | The expiration for the jwt secret.                                                                                                                                                                       | 3600    | 3600                                            |
| MONGO             | Allows the UAG to connect directly to a MongoDB database without having to redirect the submissions to the Form.io Submission API.                                                                       |         |                                                 |
| MONGO\_CONFIG     | JSON configuration for the Node.js Mongo Driver.                                                                                                                                                         |         |                                                 |
| BASE\_URL         | The public URL that the UAG is hosted on. This allows for proper OIDC authentication and allows for the authentication callbacks to point to the correct url.                                            |         | [https://ai.onform.io](https://ai.onform.io/)   |
| LOGIN\_FORM       | The public URL to the Login Form JSON endpoint.                                                                                                                                                          |         | <https://mysite.com/project/user/login>         |
| CORS              | The CORS domain, or the JSON configuration to configure the "CORS" node.js module cross domain resource sharing.                                                                                         |         | *.*                                             |
| PROJECT\_TTL      | The number of seconds that the connected project is checked for any changes. Reducing the number would allow more immediate reflection of project changes within the UAG.                                | 900     | 15                                              |
| MAX\_BODY\_SIZE   | The maximum size for the JSON body to be when an AI Agent is communicating to the UAG.  Use "kb", "mb" to denote kilobytes and megabytes respectively.                                                   | 100mb   | 200mb                                           |

After saving the modified `docker-compose.ym`l to `multicontainer.zip`, upload the new .zip and deploy it.

AWS should use the `docker compose up`  command internally when launching the UAG container. This should leave any unmodified containers operational through the process.

## Azure

Coming Soon

### GCP

Coming Soon

### Local
