# Set up the VAIL agent connector

These instructions are written so that a person or a coding agent can follow
them from start to finish. Do the steps in order. Each step ends with a check:
do not go on until it passes.

The connector is a small container that runs next to an AI agent that must not
be reachable from the internet. It only makes outbound connections: to VAIL
over HTTPS, and to the agent. It forwards only the requests VAIL's probes
need, and adds the agent's own credential itself, so VAIL never sees that
credential.

## Rules

If you are a coding agent, follow these rules throughout:

1. **Never print, log, echo, or commit a credential.** That covers the
   connector token (it starts with `vct_`) and the agent's own API key. Never
   put either one in a command line, a compose file, a Kubernetes manifest,
   an ECS task definition, or a file in a repository. Pass them to the
   connector only through a secrets manager or a mounted secret file (step 3).
2. **Do not expose the agent.** Do not open ports, publish container ports,
   add load balancers, or change firewall rules. The connector needs only
   outbound HTTPS to `agents.projectvail.com` on port 443.
3. **Do not change the agent.** You only need to read its address and where
   its credential is kept.
4. **Stop and ask the person** when:
   - you cannot find where the agent listens;
   - a step needs a cloud permission you do not have, such as creating an IAM
     role or granting access to a secret;
   - the connector token is not yet in a secrets manager and you would have
     to handle its value to put it there.

## What you need

| Input | Where it comes from |
| --- | --- |
| **VAIL agent ID** (`agt_…`) | The agent's connect page in VAIL. |
| **Profile**: `langgraph`, `hermes`, or `openclaw` | The agent's platform, also shown on the connect page. |
| **Connector token** (`vct_…`) | Shown once on the connect page, under "Can't expose it? Reach it through the VAIL agent connector". The person stores it in a secrets manager (step 3) and tells you where. |
| **The agent's own credential** | Wherever the agent's API key is kept today. Leave it unset if the agent needs no key. |
| **VAIL URL** | `https://agents.projectvail.com`, unless the connect page says otherwise. |

## Step 1: Find where the agent runs, and its address from the connector

The connector must reach the agent at `AGENT_URL`. What that address is
depends on where the agent runs and where you run the connector. Find the
row that matches:

| The agent runs… | Run the connector… | `AGENT_URL` |
| --- | --- | --- |
| as a process on a Linux host | with Docker on that host, using `--network host` | `http://127.0.0.1:<port>` |
| as a process on a Mac or Windows host (Docker Desktop) | with Docker on that host, without `--network host` | `http://host.docker.internal:<port>` |
| in a Docker container, or with Docker Compose | as a service on the same Docker network | `http://<agent service or container name>:<port>` |
| in a Kubernetes pod | as a sidecar container in the same pod | `http://127.0.0.1:<port>` |
| in an Amazon ECS task | as a second container in the same task (`awsvpc`) | `http://127.0.0.1:<port>` |

To find the port the agent listens on:

```bash
# Linux
ss -ltnp | grep -i -E 'python|node|langgraph|hermes'
# macOS
lsof -nP -iTCP -sTCP:LISTEN | grep -i -E 'python|node|langgraph|hermes'
# Docker
docker ps --format '{{.Names}}\t{{.Ports}}'
# Kubernetes
kubectl get pod <agent pod> -o jsonpath='{.spec.containers[*].ports}'
```

Common defaults are listed below. Check them against what the agent actually
does.

| Agent | Default port |
| --- | --- |
| LangGraph with `langgraph dev` | `2024` |
| LangGraph with `langgraph up` | `8123` |
| Hermes API server | `8642` |
| OpenClaw Gateway | `18789` |

A Hermes server that hosts several profiles serves each one under
`/p/<profile>`. If so, include that in `AGENT_URL`, as in
`http://127.0.0.1:8642/p/research`.

**Check:** from where the connector will run, the agent answers. Any HTTP
status, even `401`, means it is reachable:

```bash
curl -s -o /dev/null -w '%{http_code}\n' "$AGENT_URL/info"     # langgraph
curl -s -o /dev/null -w '%{http_code}\n' "$AGENT_URL/health"   # hermes
```

## Step 2: Choose how the connector gets its identity

The connector reads both credentials from a secrets manager. It signs in with
the identity of wherever it runs, not with a key you give it.

| Where it runs | Its identity | What to set up |
| --- | --- | --- |
| Amazon ECS | the task role | Give the task role read access to the secrets. Nothing else is needed. |
| Amazon EKS | IRSA or EKS Pod Identity | Annotate or associate the pod's service account with a role that can read the secrets. AWS injects the rest. |
| Amazon EC2 | the instance profile | Give the instance role read access, and run the connector with `--network host` so it can reach the instance metadata service. |
| Google Cloud (GCE, GKE, Cloud Run) | the service account | Give the service account `roles/secretmanager.secretAccessor` on the secrets. On GKE, use Workload Identity. |
| Azure (VM, AKS, Container Apps) | a managed identity, or AKS workload identity | Give the identity the **Key Vault Secrets User** role on the vault. For a user-assigned identity, set `AZURE_CLIENT_ID`. |
| Anywhere, with HashiCorp Vault | Kubernetes auth, or a Vault token file | Set `VAULT_ADDR`, and either `VAULT_K8S_ROLE` or `VAULT_TOKEN_FILE`. |
| Anywhere, with Docker or Kubernetes secrets | a mounted file | Mount the secret read-only, and use the `_FILE` variables. |

The read permissions it needs:
- **AWS Secrets Manager:** `secretsmanager:GetSecretValue` on the secret, and
  `kms:Decrypt` if the secret uses a customer-managed KMS key.
- **AWS Parameter Store:** `ssm:GetParameter` on the parameter, and
  `kms:Decrypt` for a SecureString.
- **HashiCorp Vault:** a policy with `read` on the secret's path.

## Step 3: Put both credentials in the secrets manager

Store the connector token and the agent's credential as two secrets, or as two
keys of one JSON secret. Each one then goes to the connector as a
reference:

| Secrets manager | Reference |
| --- | --- |
| AWS Secrets Manager | `aws-sm:<name or ARN>`, or `aws-sm:<name>#<json key>` |
| AWS Parameter Store | `aws-ssm:<parameter name>` |
| Google Secret Manager | `gcp-sm:projects/<project>/secrets/<secret>` (the latest version), or `…/versions/<n>` |
| Azure Key Vault | `azure-kv:<vault name>/<secret name>` |
| HashiCorp Vault (KV version 2) | `vault:<mount>/<path>#<field>`, as in `vault:secret/agents/support#token` |
| A mounted file | `file:<path>`, or use `VAIL_AGENT_CONNECTOR_TOKEN_FILE` and `AGENT_TOKEN_FILE` |

If the connector token is not stored yet, the person should store it, because
it is shown only once. Read the value from a prompt, never from a command
line:

```bash
# AWS Secrets Manager
read -rs -p "Connector token: " TOKEN && \
  aws secretsmanager create-secret --name vail/agent-connector-token --secret-string "$TOKEN" && unset TOKEN
# Google Secret Manager
read -rs -p "Connector token: " TOKEN && \
  printf '%s' "$TOKEN" | gcloud secrets create vail-agent-connector-token --data-file=- && unset TOKEN
# Azure Key Vault
read -rs -p "Connector token: " TOKEN && \
  az keyvault secret set --vault-name <vault> --name vail-agent-connector-token --value "$TOKEN" -o none && unset TOKEN
```

For AWS, also set `AWS_REGION`, unless the reference is a full ARN.

**Check:** the identity from step 2 can read both secrets. For example, with
AWS run `aws secretsmanager describe-secret --secret-id <name>` as that
role. It prints metadata, not the value.

## Step 4: Run the connector

Use the template for the row you chose in step 1. Replace everything in angle
brackets. Leave out `AGENT_TOKEN_FROM` if the agent needs no key. If the
profile picks the header for the agent's key: `x-api-key` for `langgraph`, and
`Authorization: Bearer <key>` for `hermes`, which is what Hermes's
`API_SERVER_KEY` expects. Add `AGENT_AUTH_HEADER` only if the agent uses
another header.

The image is public, so pulling it needs no Google account. It is built for
`linux/amd64` and `linux/arm64`.

### Optional: verify the image

VAIL signs every release. To check that the image you pull is the one VAIL
built, save this key as `vail-agent-connector.pub`:

```text
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEQVqK2YOpu9MybqffbP5IiNIp0D6i
YXHc0ryq1aXgxQREfS8qrrQtZhQs4VZq0RlcGsHJ4H3bPrX3ylei8A1dbQ==
-----END PUBLIC KEY-----
```

Then, with [cosign](https://docs.sigstore.dev/cosign/system_config/installation/):

```bash
cosign verify --key vail-agent-connector.pub \
  us-docker.pkg.dev/vail-monitor-82825/public/vail-agent-connector:0.2.0
```

It prints the signed digest. To run exactly that image, use
`vail-agent-connector@<digest>` in place of `vail-agent-connector:0.2.0` below.

### Docker on a Linux host

```bash
docker run -d --name vail-agent-connector --restart unless-stopped --network host \
  -e VAIL_AGENT_ID=<agt_…> \
  -e AGENT_CONNECTOR_PROFILE=<langgraph|hermes> \
  -e AGENT_URL=http://127.0.0.1:<port> \
  -e VAIL_AGENT_CONNECTOR_TOKEN_FROM=<reference> \
  -e AGENT_TOKEN_FROM=<reference> \
  -e AWS_REGION=<region, for AWS> \
  us-docker.pkg.dev/vail-monitor-82825/public/vail-agent-connector:0.2.0
```

### Docker Desktop on a Mac or Windows host

The same command, but without `--network host` and with
`AGENT_URL=http://host.docker.internal:<port>`. A secrets manager on your
laptop's account is usually a mounted file instead:

```bash
docker run -d --name vail-agent-connector --restart unless-stopped \
  -e VAIL_AGENT_ID=<agt_…> \
  -e AGENT_CONNECTOR_PROFILE=<langgraph|hermes> \
  -e AGENT_URL=http://host.docker.internal:<port> \
  -e VAIL_AGENT_CONNECTOR_TOKEN_FILE=/run/secrets/vail_token \
  -e AGENT_TOKEN_FILE=/run/secrets/agent_token \
  -v <path to token file>:/run/secrets/vail_token:ro \
  -v <path to agent key file>:/run/secrets/agent_token:ro \
  us-docker.pkg.dev/vail-monitor-82825/public/vail-agent-connector:0.2.0
```

Keep those files outside any repository, readable only by you (`chmod 600`).

### Docker Compose, next to the agent's service

```yaml
services:
  vail-agent-connector:
    image: us-docker.pkg.dev/vail-monitor-82825/public/vail-agent-connector:0.2.0
    restart: unless-stopped
    environment:
      VAIL_AGENT_ID: <agt_…>
      AGENT_CONNECTOR_PROFILE: <langgraph|hermes>
      AGENT_URL: http://<agent service>:<port>
      VAIL_AGENT_CONNECTOR_TOKEN_FILE: /run/secrets/vail_agent_connector_token
      AGENT_TOKEN_FILE: /run/secrets/agent_token
    secrets: [vail_agent_connector_token, agent_token]
secrets:
  vail_agent_connector_token:
    file: <path outside the repository>
  agent_token:
    file: <path outside the repository>
```

Add it to the compose project the agent's service is in, so they share a
network. Do not add `ports:`.

### Kubernetes, as a sidecar in the agent's pod

Add this to the agent's pod spec, under `containers:`:

```yaml
- name: vail-agent-connector
  image: us-docker.pkg.dev/vail-monitor-82825/public/vail-agent-connector:0.2.0
  env:
    - {name: VAIL_AGENT_ID, value: "<agt_…>"}
    - {name: AGENT_CONNECTOR_PROFILE, value: "<langgraph|hermes>"}
    - {name: AGENT_URL, value: "http://127.0.0.1:<port>"}
    - {name: VAIL_AGENT_CONNECTOR_TOKEN_FROM, value: "<reference>"}
    - {name: AGENT_TOKEN_FROM, value: "<reference>"}
  securityContext:
    runAsNonRoot: true
    readOnlyRootFilesystem: true
    allowPrivilegeEscalation: false
  resources:
    requests: {cpu: 10m, memory: 32Mi}
    limits: {memory: 128Mi}
```

To use a Kubernetes Secret instead of a secrets manager, mount it as a volume
and set `VAIL_AGENT_CONNECTOR_TOKEN_FILE` and `AGENT_TOKEN_FILE` to the
mounted paths.

### Amazon ECS, as a second container in the agent's task

Add this to the task definition's `containerDefinitions`. The task role reads
the secrets, so nothing else is needed:

```json
{
  "name": "vail-agent-connector",
  "image": "us-docker.pkg.dev/vail-monitor-82825/public/vail-agent-connector:0.2.0",
  "essential": false,
  "environment": [
    {"name": "VAIL_AGENT_ID", "value": "<agt_…>"},
    {"name": "AGENT_CONNECTOR_PROFILE", "value": "<langgraph|hermes>"},
    {"name": "AGENT_URL", "value": "http://127.0.0.1:<port>"},
    {"name": "VAIL_AGENT_CONNECTOR_TOKEN_FROM", "value": "aws-sm:<secret ARN>"},
    {"name": "AGENT_TOKEN_FROM", "value": "aws-sm:<secret ARN>"}
  ]
}
```

**Check:** the connector started and connected. Its log, from
`docker logs vail-agent-connector` or `kubectl logs <pod> -c vail-agent-connector`,
shows a line like this:

```text
connected to https://agents.projectvail.com as agt_… (langgraph profile, agent at http://127.0.0.1:2024, reachable)
```

If it says `NOT reachable` instead of `reachable`, go back to step 1.

## Step 5: Finish on the connect page

1. On the agent's connect page in VAIL, the status changes to **Connector
   online** within a minute.
2. Choose **Test and use the connector**. VAIL sends the agent one test
   message, *"Reply with OK. This is a connection test."*, through the
   connector. From then on, every probe reaches the agent through it.

**Check:** the agent's page in VAIL shows "Through its connector" with an
**online** badge.

## What the log means

Every request VAIL sends is logged on one line:

```text
req_… forwarded POST /threads status=200 bytes=61 0.04s
req_… refused POST /store/items status=- bytes=0 0.00s (POST /store/items is not in this connector's allowlist)
```

`forwarded` means the request was sent to the agent. `refused` means it was
not, because the connector's allowlist does not include that route. Bodies
are never logged unless `AGENT_CONNECTOR_LOG_BODIES=true`.

## Troubleshooting

| The log says | Why | What to do |
| --- | --- | --- |
| `VAIL_AGENT_CONNECTOR_TOKEN is missing, or is not a connector token` | No token was given, or the reference points at the wrong secret. | Check the reference from step 3. A connector token starts with `vct_`. |
| `…: could not be read`, or `No AWS identity found` | The identity cannot read the secret. | Go back to step 2. On EC2, add `--network host`. For AWS, set `AWS_REGION`. |
| `cannot reach VAIL (…); retrying` | Outbound HTTPS is blocked. | Allow outbound 443 to `agents.projectvail.com`, or set `HTTPS_PROXY`. |
| `VAIL does not accept this connector token` | The token was revoked, or a new one was issued. | Issue a token on the connect page and update the secret. The connector reads the secret again when VAIL refuses its token, so a restart is not needed. |
| `VAIL asks for a newer connector` | This version is too old. | Pull the newest image and restart the container. |
| `could not re-read …; keeping the one in use` | The secrets manager was briefly unreachable. | Nothing, unless it keeps happening. |
| `forwarded … status=401` | The agent refused its own credential. | Check `AGENT_TOKEN_FROM` and `AGENT_AUTH_HEADER`. |
| `agent at …, NOT reachable` | `AGENT_URL` is wrong for where the connector runs. | Go back to step 1. |

The connect page in VAIL can also say:
- **"The connector is running the X profile"**: set `AGENT_CONNECTOR_PROFILE`
  to the agent's platform.
- **"has not checked in"**: the connector is not running, or cannot reach
  VAIL.

## Stopping it

`docker rm -f vail-agent-connector`, or remove the sidecar. VAIL can then no
longer reach the agent. To stop it from VAIL's side, choose **Revoke the
connector** on the connect page, which stops the token working at once.

## All settings

| Variable | Default | Meaning |
| --- | --- | --- |
| `VAIL_AGENT_ID` | required | The agent this connector serves. |
| `AGENT_CONNECTOR_PROFILE` | required | `langgraph` or `hermes`. |
| `AGENT_URL` | required | The agent's address from the connector (step 1). |
| `VAIL_AGENT_CONNECTOR_TOKEN_FROM`, `_FILE`, or `VAIL_AGENT_CONNECTOR_TOKEN` | required | The connector token, as a reference, a file, or (for a quick trial only) a value. |
| `AGENT_TOKEN_FROM`, `AGENT_TOKEN_FILE`, or `AGENT_TOKEN` | none | The agent's credential, in the same three ways. |
| `AGENT_AUTH_HEADER` | from the profile | The header for the agent's credential: `x-api-key` for `langgraph`, `Authorization` (as a bearer token) for `hermes`. |
| `AGENT_CONNECTOR_ALLOW` / `AGENT_CONNECTOR_DENY` | none | Routes added to or removed from the profile, comma-separated, such as `GET /info`. |
| `AGENT_CONNECTOR_SECRET_REFRESH_SECONDS` | `900` | How often secrets are read again, to pick up a rotation. `0` turns it off. |
| `AGENT_CONNECTOR_HEALTH_PORT` | `8790` | Loopback port for `GET /healthz`. `0` turns it off. |
| `AGENT_CONNECTOR_LOG_BODIES` | `false` | Log request and response bodies. |
| `VAIL_URL` | `https://agents.projectvail.com` | The VAIL service. |
| `HTTPS_PROXY` | none | A proxy for outbound traffic to VAIL. |
| `VAIL_INSECURE_HTTP` | `false` | Allows a plain-`http` `VAIL_URL`. Only for a local development setup; never in production. |
| `AWS_REGION`, `VAULT_ADDR`, `VAULT_K8S_ROLE`, `VAULT_TOKEN_FILE`, `AZURE_CLIENT_ID` | none | Where to find the secrets manager, for the references above. |
