# Agents

Agents play a key role in accessing private repositories for artifacts (including code) and executing related tasks.

Info

Click [**here**](https://docs.rafay.co/gitops/gitops_agent/) to learn more about Rafay Agents.

* * *

Agents can be deployed in two ways:

1. As a Kubernetes deployment within a cluster.
2. As a Docker container. In Docker mode, the container runs a lightweight K3s cluster where the agent is deployed.

All environment activities are executed on the agent.

- For container-based tasks, pods are created in the Kubernetes cluster, with logs streamed back to the workflow engine and the activity's exit status updated accordingly.
- HTTP activities are handled using an HTTP client.

Agents can be associated with:

- Environment Templates
- At environment launch or runtime
- At the resource template level

Although it is possible to associate agents with individual resource templates, this is not a common practice.

When agents are defined at multiple levels, such as both the environment template and an individual resource template, the agent specified in the higher-level environment template takes precedence.

### Docker agent

```
apiVersion: gitops.k8smgmt.io/v3
kind: Agent
metadata:
  name: dockeragent
  project: defaultproject
spec:
  active: true
  type: Docker
  version: r2.10.0
```

### Agent running on cluster

```
apiVersion: gitops.k8smgmt.io/v3
kind: Agent
metadata:
  name: k8sagent
  project: defaultproject
spec:
  active: true
  cluster:
    name: eks-agent
  type: Cluster
  version: r2.10.0
```
