# Agent installation

On-prem agent installation

## Create new agent

> **Info:** You can also use the [API](https://tray.ai/documentation/developer/platform-apis/agent-instances#endpoint-postcorev1workspacesworkspace-idon-prem-agent-groupsagent-group-idagents) to create an Agent.

Go to **Workspace** **settings** **>** **On-premise** and click the **Create On-premise connection** button.
You will see an activation code that you can use to register the agent at installation. Download the agent by following the **Download install agent** link, and copy the **Registration token**:
![download-agent](https://tray.ai/documentation/images/platform/connectivity/on-premise-systems/on-prem-agent/agent-installation/7bZILcJTo7GlyfEprSC9qu_download-agent.png)
\*\*
\*\*The **'Agent activation status'** will remain as **'Waiting for connection'** until the agent is activated on your target machine, when it will change to a green **Connected** message

> **Warning:** Key points on the agent activation code:- The registration token is only valid for **60 minutes**
> - It is **one-time use** only
> - Each agent instance requires **its own activation code**

###

## Windows machine setup

### **Running the agent in PowerShell**

1. Copy the **activation code** generated for you and execute the downloaded agent by typing the following command in your PowerShell terminal:
   `> C:\Path\to\agent-win-amd64.exe register <activation_code>`
2. Finally, once the agent has been registered, execute it by typing the following command in your PowerShell terminal:
   `> C:\Path\to\agent-win-amd64.exe run`

### **Setting up the agent as a Windows Service**

Alternatively, you can also run this as a Windows Service.

1. Type the following command in your PowerShell terminal:
   `> New-Service -Name "TrayOnPremAgent" -BinaryPathName "C:\Path\to\agent-win-amd64.exe run --registration-token=<activation_code>"`
2. Now start the service with:
   `> Start-Service -Name "TrayOnPremAgent"`

## Linux machine setup

### Running the agent in the terminal

Run the following commands (depending on your chip):
`chmod +x agent-linux-amd64`
`./agent-linux-amd64 register <activation_code>`
`./agent-linux-amd64 run`
The agent should install and run successfully and you will see requests coming in to the terminal.

### Installing the agent as a service

You can wrap up the above commands into whichever service manager (systemd, OpenRC etc.) you use and install the agent as a service.

## Deleting an agent

> **Info:** You can also use the [API](https://tray.ai/documentation/developer/platform-apis/agent-instances#endpoint-deletecorev1workspacesworkspace-idon-prem-agent-groupsagent-group-idagentsagent-id) to delete an Agent.

Agents can be deleted via the Tray UI.
A deleted agent will no longer be able to connect to Tray.
If you remove the last agent from a group, then any workflows which rely on authentications made to this agent group will fail.
Therefore it is important to edit these workflows and authentications before deletion, to ensure there is no downtime for the workflow.
