# Deploying a standalone Hermes agent on a second server

Procedure and pitfalls for running a second, independent Hermes agent (own VPS,
own profile, own Telegram bot) that must survive the primary agent going down.

## Procedure

1. Install on the target server via the official installer
   (`curl -fsSL https://hermes-agent.noussearch.com/install.sh | bash`).
   The installer uses a bundled Python under `~/.hermes/tools/` — there is NO
   `.venv` inside the source repo, so never assume `pip` paths from the repo.
   A freshly ordered VM usually AUTO-REBOOTS ~10–25 min after provisioning;
   this kills the first installer run mid-way (`✗ pm install failed`). Do
   NOT debug that as a failure: remove `~/.hermes/tools/.install.lock`, rerun
   the installer once, expect DONE_0. During the reboot window SSH shows
   "Connection refused" while the host still pings — poll instead of
   re-provisioning.
2. Create the profile (`hermes profile` or `~/.hermes/profiles/<name>/`) and
   configure its provider before any function test — but NEVER assemble a
   minimal config.yaml by hand (just model/provider/base_url). A
   hand-reconstructed config makes Hermes read keys inconsistently
   (intermittent 401s, wrong-provider fallback) even though the same key works
   via a direct `curl` from that host. Instead copy the COMPLETE, proven
   `config.yaml` AND `.env` from the live primary agent to BOTH levels:
   `~/.hermes/config.yaml` + `~/.hermes/.env` AND
   `~/.hermes/profiles/<name>/{config.yaml,.env}` (each chmod 600). Then verify
   with `<launcher> chat -q 'Antworte nur: OK'` — the PASS criterion is a real,
   returned ANSWER, never merely a zero exit code.
3. Telegram gateway for ONE profile:
   - Put `TELEGRAM_BOT_TOKEN` (and `TELEGRAM_ALLOWED_USERS` for owner-locking)
     into **`~/.hermes/profiles/<name>/.env`** — a standalone per-profile
     gateway reads the PROFILE env; writing only `~/.hermes/.env` yields
     `WARNING gateway.run: No messaging platforms enabled.` Write BOTH files
     if unsure which layout the install uses.
   - Set `gateway:
  standalone: true` in the profile's `config.yaml` BEFORE
     `hermes gateway install` — otherwise install only prints a multiplexing
     hint and no gateway runs.
   - `hermes gateway install` creates a user systemd service
     (`hermes-gateway-<profile>`) with linger enabled, so it survives logout.
   - Success check: `journalctl --user -u hermes-gateway-<profile>` shows
     `Connected to Telegram (polling mode)` — not merely an active service.
4. Auto-update: use the official `hermes update` subcommand (it completes
   source updates AND bundled-python dependencies). Do NOT hand-roll
   `git pull` + `pip install` — the venv path guess breaks and a failed
   function test forces a manual rollback. Wrap `hermes update` in a weekly
   systemd timer: pre-backup → update → `chat -q` function test → log +
   alert on failure. A first-run `hermes update` may report "an update is
   still running; run `hermes update` to finish it" — just run it again.
5. Hand the owner a self-contained access sheet (server root access incl. a
   set password, hosting panel login, provider deposit addresses, key
   commands) so the deployment works without the primary agent.

## Syncing skills from the primary agent to the remote profile

When the owner asks for a second agent to "work like the primary", copy the
relevant skills (not just instructions in chat):

1. Locally: `cd ~/.hermes/skills && tar czf /tmp/skills-sync.tar.gz
   <category>/<skill> ...` — include whole category paths so the remote
   `skills/<category>/` structure matches.
2. `scp -i <key> /tmp/skills-sync.tar.gz root@<target>:/tmp/` then extract
   on the remote into the PROFILE's skills dir:
   `cd /root/.hermes/profiles/<name>/skills && tar xzf /tmp/skills-sync.tar.gz`.
3. Verify with `ls <category>/` and `head -5 <category>/<skill>/SKILL.md` on
   the remote — a tar that never arrived (blocked/timed-out command) leaves
   the skill silently absent; re-scp and re-extract before claiming success.
4. Reload the gateway only if skills are not picked up live (most installs
   read the profile skills dir per turn): use the script-fragment trick from
   the pitfalls below, then confirm `systemctl --user is-active` AND a
   fresh log line — a restart issued from inside the primary agent's gateway
   can hang the SSH call locally while still completing remotely.

## Pitfalls

- Restarting a remote profile gateway FROM a gateway-driven agent session is
  blocked by a shell hook whenever the command text or a referenced script
  contains `restart`/`stop ... gateway` — assemble the `systemctl` command
  from shell variables inside a script on the target host instead.
- A bot token arriving via chat is a secret: write it to .env without echoing
  it to stdout, and set `TELEGRAM_ALLOWED_USERS` so strangers cannot burn the
  owner's API credits.
- One profile's standalone gateway does not serve other profiles on the same
  host (journal warns "Profiles NOT served") — that is expected, not a bug.
