# Creating and running workflows

As you work with your database, you might want to run repeatable tasks such as:

* Generating additional data
* Posting data to another location
* Generating unstructured files from the data
* Starting tests
* Validating data

Instead of issuing a separate prompt every time, you can have the agent create a repeatable workflow. The workflow runs the exact same way every time.

## Configuring required connections for the workflow <a href="#configure-required-connections" id="configure-required-connections"></a>

A workflow might need to connect to external domains in order to complete its tasks.

To enable these connections:

* In your account settings, you configure and then request or confirm access to the domains that workflows can connect to. For more information, go to [account-domains](https://docs.tonic.ai/fabricate/fabricate-accounts-and-users/account-domains "mention").
* In your workspace settings, configure the secrets to use to connect to the domains. For more information, go to [workspace-secrets](https://docs.tonic.ai/fabricate/workspaces/workspace-secrets "mention").

## Creating a workflow <a href="#workflow-create" id="workflow-create"></a>

To create a workflow, you issue a prompt that tells the Data Agent to create a workflow and explain what the workflow accomplishes. The workflow prompt can include parameters that you provide whenever you run the workflow.

For example:

`Create a workflow that adds records to the customers table and then adds an order for each of those new customers to the orders table. Prompt for the number of customers to add.`

If the workflow requires a connection to an external domain, then you can include the required credentials in the prompt. The domain and secret must already be configured in your account and workspace.

For example, you can provide the name of a configured secret to use.

`Create a workflow that pushes the data to the API. Use the secret my_secret_name.`

Or you can make the secret a parameter that you provide when you run the workflow.

`Create a workflow that pushes the data to the API. Prompt for the secret to use for the connection.`

The Data Agent adds the workflow to the **Workflows** list in the left panel.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FxIWzVRqLeZrpfp8d676H%2FDataAgent_WorkflowsList.png?alt=media&#x26;token=1704e84c-8408-471f-be76-ac7b3aa2bf9c" alt=""><figcaption><p>Workflows list for a Data Agent database</p></figcaption></figure>

## Running a workflow <a href="#workflow-run" id="workflow-run"></a>

To run a workflow, you can issue a prompt to run the workflow. For example:

`Run the Add Customers with Orders workflow to add 10 more customers.`

Alternatively:

1. In the **Workflows** list, click the workflow name.\
   \
   The workflow details display the required parameters for the workflow.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FaIyEcEEE0MIFQDpqj8zI%2FDataAgent_WorkflowDetails.png?alt=media&#x26;token=3afa4375-15f5-4ffa-9035-aa7201a87e76" alt=""><figcaption><p>Workflow details for a Data Agent workflow</p></figcaption></figure>

2. After you fill in the parameter fields, click **Run Workflow**.

## Viewing the workflow script <a href="#workflow-view-script" id="workflow-view-script"></a>

To create the workflow, Fabricate generates a script.

To view the script:

1. In the **Workflows** list, click the workflow name.
2. On the workflow details, click the script view icon.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FLehQ4ds9iQK6tIbW15zJ%2FDataAgent_WorkflowScript.png?alt=media&#x26;token=509710ce-2f11-49b7-86c5-7534646533c5" alt=""><figcaption><p>Script view for a Data Agent workflow</p></figcaption></figure>

## Updating a workflow <a href="#workflow-update" id="workflow-update"></a>

You can use the Data Agent to make corrections to the workflow.

For example, to update the workflow that adds customers so that it also return the number of customers that were added:

`Update the Add Customers with Orders workflow to also return the number of records that were added.`

## Deleting a workflow <a href="#workflow-delete" id="workflow-delete"></a>

To delete a workflow:

1. In the **Workflows** list, click the workflow name.
2. On the workflow details, click the delete icon.
