# 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.nousresearch.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.
   - For reboot/crash-proof ("set-and-forget") operation prefer a hand-written
     SYSTEM unit `/etc/systemd/system/hermes-gateway-<profile>.service`
     modeled on the primary's own unit: `Type=notify`, `WatchdogSec=120s`,
     `StartLimitIntervalSec=0`, `Restart=always`, `RestartSec=5`,
     `SuccessExitStatus=75` + `RestartForceExitStatus=75`,
     `Environment="HERMES_HOME=<profile home>"`. Then
     `loginctl enable-linger <user>` once and verify stability NOT by liveness
     alone but by a quiet interval: `systemctl show -p NRestarts` still `0`
     several minutes after start plus the connected-journal line below.
   - Admitting additional users post-go-live: rejected DMs land in the journal
     as `gateway.run: Unauthorized user: <id> on telegram` — harvest the ID
     from there, append it COMMA-separated to `TELEGRAM_ALLOWED_USERS` at BOTH
     env levels, restart the service. Messages sent while unauthorized are
     dropped permanently: the new user must write again AFTER the restart.
   - 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.

## Deploying an agent for a THIRD PARTY (colleague) — abuse isolation

When the person who will USE the remote agent is not the owner (colleague,
customer), isolate their workload so an abuse/complaint against it cannot
touch anything of value:

1. Fresh ANONYMOUS account at the hosting provider (separate email, separate
   registration) — never host their VM on an account that also carries critical
   infrastructure; provider-level sanctions hit the WHOLE account.
2. Pay that account from the operational wallet via gas-free rails (e.g.
   EnergyFather mass-pay for TRC-20 when the wallet holds no TRX); one GUID per
   payment, verify on-chain arrival + provider credit before ordering.
3. Dedicated SSH key per box; never reuse keys or secrets across the primary
   estate. Do a leak-grep over any bundle (skills, configs) transferred TO the
   isolated box before sending it.
4. Sharing the PRIMARY's LLM API key with the remote instance is an accepted
   compromise when an isolated provider account can't be registered quickly —
   flag it to the owner as residual coupling instead of silently assuming it's
   fine.
5. Their Telegram bot must be a FRESH bot (@BotFather /newbot): every existing
token is already polled by exactly one gateway, reuse silently drops updates
   on both sides.

## Tool installs on the remote box (armament pattern)

Stream a staged installer over SSH (`ssh ... 'bash -s' < install.sh`) in a
background terminal with heartbeat+notify watch patterns, and make the script
emit explicit `[STEP_n_START]` / `[STEP_n_OK|FAIL|DEFERRED]` markers — that way
a completion notification alone reconstructs the whole result report.
PASS criterion is ALWAYS a real version/help output, never exit code or absence
of errors. Treat an installer 'FAIL' verdict as UNPROVEN while the log ends in
a success banner or setup-complete text: many installers place the binary
outside the assumed PATH (vendor dirs like `~/.<tool>/bin` plus a `.bashrc`
PATH line) — grep the log tail and `find ~ -maxdepth 4 -name <tool>` before
re-running or reporting failure. Gate heavy Docker-compose stacks on measured
`free -m`, not on the plan sheet: DEFER (pre-clone the repo for later) when RAM
is below the stack's documented minimum rather than squeezing it onto the box.

Deliveries to a waiting end-user (colleague/customer demoing to others) go out
COMPLETE or not at all — partial delivery makes the owner look bad in front
of their audience. The capability checklist for a "fully live" agent box:
terminal ✔, web research ✔, vision ✔, TTS/audio ✔, skills synced ✔, AND a
real BROWSER — without it the agent is blind for logins/JS/CAPTCHA work.
Browser: install official Google Chrome via
`curl -sL -o /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && apt-get install -y /tmp/chrome.deb`
(direct URL; correct if download domain changed), prove it runs with
google-chrome --headless=new --no-sandbox --disable-gpu --dump-dom about:blank
→ `<html...>` echoed — no config needed afterwards: the agent discovers a
browser named `google-chrome`/`chromium` on PATH automatically.

## 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 NEVER arrives as plaintext when it looks like
  an API key: the gateway's secret-redaction masks it to a ⟦APIKEY…⟧/`<id>:***`
  placeholder before the model sees it, and the raw value is unrecoverable from
  state.db/WAL/vault afterwards. Capture it at the SOURCE instead: either have
  the owner send it split into two messages (part before the colon, part after)
  or read it off a screenshot/photo via vision transcription — transcribe the
  string twice for l/1/O/0 verification, then validate live
  (`https://api.telegram.org/bot<token>/getMe` → `ok:true` + expected username)
  BEFORE wiring anything. Store as a chmod-600 secret file, mirror to both .env
  levels, never echo to stdout. Always filter journal/output with
  `-viE 'token|key|secret'` before pasting anything into a report.
- Set `TELEGRAM_ALLOWED_USERS` so strangers cannot burn the owner's API
  credits; one bot token = exactly ONE poller — never reuse a token that
  another running gateway already polls (both gateways silently lose updates).
- 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.
- Do not TRUST the "linger enabled" claim of the setup: check
  `loginctl show-user <user> | grep -i linger` yourself; on a fresh box it is
  often `no` even after `hermes gateway install`. Run
  `loginctl enable-linger <user>` once BEFORE go-live so the gateway service
  actually survives reboots/logouts.
- Before declaring the remote agent ready for its owner, run ONE E2E pass from
  an INDEPENDENT vantage point (e.g. a delegate_task subagent doing raw SSH):
  real chat answer, live tool use whose output matches a direct SSH readback,
  skill file present with expected content, disk headroom. A `-q` OK from the
  deployment shell alone proves nothing about what the owner will hit.
