How somratpro/huggingmes works
1. What this repo is
HuggingMes is not the Hermes agent itself; it is a Dockerized wrapper and bootstrap layer around the external hermes-agent runtime. Its job is to turn a Hugging Face Space into a self-hosted AI gateway with auth, telemetry, persistence, Telegram connectivity, and optional network workarounds.
2. Top-level runtime boundary
The entire system runs as a single containerized service on port 7861 in Hugging Face Spaces. Inside that container, HuggingMes fronts multiple internal surfaces: the dashboard at /, the Hermes UI at /app/, the OpenAI-compatible API at /v1/*, a JupyterLab terminal at /terminal/, and a /health endpoint.
3. Bootstrap and process orchestration
start.sh is the main entrypoint and likely coordinates startup order, env normalization, process launch, and restart supervision. The README indicates the gateway, dashboard, health server, and JupyterLab are monitored and restarted automatically if they exit, so this layer is the operational control plane for the container.
4. Gateway / reverse-proxy layer
The central architectural pattern is a secure gateway in front of Hermes. It enforces GATEWAY_TOKEN on /app/ and Authorization: Bearer <token> on /v1/*, acting as the auth and routing boundary between users and the underlying agent runtime. This is the main “front door” of the system.
5. Hermes agent runtime
Hermes provides the actual agent behavior: chat, tools, memory, workflows, model selection, and provider integration. HuggingMes does not reimplement that core logic; instead it maps environment variables into Hermes at boot and then proxies access to Hermes’ UI/API. Provider setup can also happen later through Hermes-native configuration (hermes model, config.yaml).
6. Model/provider configuration flow
The repo supports two provider paths: direct startup mapping from LLM_MODEL + LLM_API_KEY, and Hermes-native providers configured after launch. The direct path translates one generic secret into provider-specific env vars such as OPENROUTER_API_KEY, ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY, and others. This means provider selection is part of startup config, not an application UI state.
7. Persistence and backup subsystem
hermes-sync.py is the persistence engine. It syncs workspace and agent state to a private Hugging Face Dataset, typically every 600 seconds, using HF_TOKEN. This creates a clear separation between ephemeral container storage and durable backup storage, and is how chat/config/session state survives rebuilds or Space restarts.
8. Connectivity repair and outbound proxying
The Cloudflare scripts are a separate infrastructure automation layer. cloudflare-proxy-setup.py provisions a Worker proxy for blocked outbound traffic, especially Telegram and some provider backends. cloudflare-keepalive-setup.py provisions a cron-triggered Worker that pings /health to reduce sleep time on free tiers. These are optional but materially affect network topology.
9. Telegram integration path
Telegram is treated as an external ingress channel into Hermes. The bot token and allowed-user list gate access, and the README suggests webhook mode by default, with Cloudflare proxy support when Hugging Face outbound restrictions interfere. This makes Telegram a secondary interface that depends on the same gateway/runtime but uses separate transport and access control.
10. Health and lifecycle management
health-server.js exposes a lightweight readiness/uptime endpoint used by Hugging Face and the keep-alive worker. This is distinct from the main agent API: it is for liveness, not conversation traffic. That separation is important for diagrams because the container has a health plane and an application plane.
11. Terminal and debugging surface
The JupyterLab terminal at /terminal/ is a privileged operational subsystem, enabled when GATEWAY_TOKEN is set and optionally disabled with DEV_MODE=false. It gives full shell access for hermes commands, package installation, and debugging, so it should be drawn as an admin-only side channel rather than part of the user-facing app flow.
12. Ephemeral customization helpers
env-builder.html and env-builder.js appear to support environment-variable setup or generation, which fits the repo’s emphasis on boot-time configuration over custom code changes. They are helper assets, not core runtime services, but they reinforce that most behavior is driven by secrets and env vars.
13. Deployment model
Dockerfile and docker-compose.yml define the local and Hugging Face deployment story. The repo is designed to be reproducible as a container image, with Space-specific secrets injected at runtime. In other words, the architecture is “container-first, config-driven, externally wired.”
14. Primary data flows
The main flows are: user/browser or Telegram request → gateway/auth → Hermes UI/API → provider backend; and container state → sync engine → Hugging Face Dataset backup. A separate operational flow is /health → keep-alive worker / platform probes, while Cloudflare automation modifies network reachability for outbound traffic and Telegram ingress.
Main entry points: start.sh Startup · hermes-sync.py State Sync · cloudflare-proxy-setup.py Proxy Setup · cloudflare-keepalive-setup.py Keepalive Setup
Components 17
Container Runtime
Main service launched inside the Hugging Face Space container.
- HuggingMes · Dockerized wrapper around the Hermes runtime running as one service on port 7861.
- Gateway · Secures the app and API, routing requests to the right internal surface.
- Dashboard · Root surface for the HuggingMes control experience.
- Hermes UI · Underlying Hermes web interface exposed under /app/.
- OpenAI API · OpenAI-compatible /v1/* interface for agent and tool access.
- Hermes Agent · External agent runtime providing chat, tools, memory, and workflows.
- Model Map · Maps startup model settings into provider-specific credentials and Hermes config.
Operations
Bootstrap, lifecycle, and admin surfaces for the container.
- Startup · Entry script that normalizes env, starts services, and supervises restarts.
start.sh - Terminal · JupyterLab terminal for privileged debugging and Hermes CLI access.
- Health Server · Lightweight readiness and uptime endpoint used by probes and keep-alive checks.
health-server.js - Container Build · Dockerfile and compose-based packaging for local and Space deployment.
Dockerfile - Env Builder · Helper assets for generating or preparing environment variables.
env-builder.html
Persistence
Durable sync and backup path for workspace and agent state.
- State Sync · Synchronizes workspace and agent state to a private Hugging Face Dataset.
hermes-sync.py - HF Dataset · Remote backup store for persisted workspace and configuration state.
Network Extensions
Optional connectivity and ingress workarounds.
- Proxy Setup · Creates Cloudflare Worker proxy support for blocked outbound traffic and Telegram paths.
cloudflare-proxy-setup.py - Keepalive Setup · Creates a cron-triggered Worker that pings health to reduce sleep on free tiers.
cloudflare-keepalive-setup.py - Telegram · Secondary user ingress channel that can route into the Hermes runtime.
Connections 20
- Container Build → HuggingMes: builds · Packages the service as a reproducible container image.
- Startup → Gateway: launches · Bootstraps the gateway and monitored services.
- Startup → Terminal: enables · Starts the admin terminal when configured.
- Startup → Health Server: starts · Brings up the liveness endpoint for probes and keep-alive traffic.
- Startup → State Sync: starts · Runs the background state synchronization worker.
- Startup → Proxy Setup: optional · Can provision Cloudflare proxy support during setup.
- Startup → Keepalive Setup: optional · Can provision keep-alive infrastructure during setup.
- Gateway → Dashboard: routes / · Serves the main dashboard at the root path.
- Gateway → Hermes UI: routes /app/ · Forwards authenticated users to the Hermes web UI.
- Gateway → OpenAI API: routes /v1/* · Exposes the OpenAI-compatible API behind bearer token auth.
- Gateway → Hermes Agent: fronts · Acts as the security boundary in front of the Hermes runtime.
- Model Map → Hermes Agent: configures · Translates generic startup model settings into Hermes/provider config.
- Hermes UI → Hermes Agent: uses · The UI is backed by the Hermes runtime.
- OpenAI API → Hermes Agent: invokes · API requests are handled by the Hermes agent runtime.
- State Sync → HF Dataset: backs up to · Persists workspace and agent state to remote durable storage.
- Proxy Setup → Telegram: unblocks · Improves outbound reachability and Telegram connectivity when needed.
- Keepalive Setup → Health Server: pings · Uses the health endpoint to keep the container warm.
- Telegram → Gateway: enters via · Telegram traffic ultimately lands in the same secured runtime boundary.
- Env Builder → Startup: prepares env · Supports boot-time secret and variable setup.
- Terminal → Hermes Agent: administers · Provides shell-level access for Hermes commands and debugging.