使用说明
Hermes Senpi Trader--铁路模板
一家生产就绪、持续批量第一的Hermes AI铁路贸易代理,与Senpi MCP集成。
分析优先,执行控制,双配置文件架构,用于在Hyperliquit上进行自主加密交易。
所得
- 赫尔墨斯代理 (NousResearch)-固定上游释放,无叉
- 双剖面架构 —
analysis(始终打开)和execution(手动启用)共享一个服务,但使用隔离服务HERMES_HOME目录 - 铁路运量持续状态 --配置、工作区、凭据和日志在重新部署后仍然有效
- 森皮MCP集成 —
@senpi-ai/mcp-server注册于mcp_registry.yaml,仅在执行配置文件中处于活动状态 - 多提供商支持 --OpenRouter、NVIDIA NIM、DashScope、Z.AI、Kimi、MiniMax(7个提供商,基于别名的路由)
- 风险控制执行 —
risk_policy.yaml在执行配置文件开始之前需要;allow_open_new_position: false默认情况下 - 狼战略技能 --第一技能预先配置为清单;残疾人,需要人工批准
- 引导系统 --幂等初始化、模式迁移、每个容器启动时的配置生成
- 备份和还原脚本 --便携式平台
.tar.gz出口,而不仅仅是铁路 - 安全边界 -仅限env中的机密,配置文件或日志中没有API密钥
快速入门(铁路)
1.叉接
git clone https://github.com/algorytma/hermes-senpi-railway-template
cd hermes-senpi-railway-template
2.创建铁路项目
railway login
railway init
3.添加持久卷
铁路仪表板→ 存储 → 添加音量
- 安装路径:
/data - 大小:5 GB(最小)
4.设置环境变量
铁路仪表板→ 变量 → 添加以下内容:
| 变量 | 必填 | 描述 |
|---|---|---|
OPENROUTER_API_KEY |
是 | 主要AI提供商密钥 |
SENPI_AUTH_TOKEN |
是(执行) | MCP的Senpi平台身份验证令牌 |
ACTIVE_PROFILE |
是的 | analysis (默认)或 execution |
DATA_DIR |
是 | 设置为 /data |
HERMES_VERSION |
推荐 | v0.6.0 (钉住) |
NVIDIA_API_KEY |
可选 | 用于 trade-fast 别名(NVIDIA NIM) |
DASHSCOPE_API_KEY |
可选 | 适用于Qwen/DashScope型号 |
ZAI_API_KEY / ZAI_BASE_URL |
可选 | Z.AI/GLM型号 |
KIMI_API_KEY / KIMI_BASE_URL |
可选 | Moonshot/Kimi型号 |
MINIMAX_API_KEY / MINIMAX_BASE_URL |
可选 | MiniMax型号 |
TELEGRAM_BOT_TOKEN |
可选 | 用于电报通知 |
ADMIN_SETUP_TOKEN |
可选 | 管理员端点身份验证 |
BACKUP_ENCRYPTION_PASSPHRASE |
可选 | 加密备份存档 |
重要提示: 切勿将API密钥值放入
railway.toml或任何配置文件。仅使用铁路变量。
5.部署
railway up
首次启动时,引导系统:
- 创建完整
/data目录结构 - 将默认规范配置文件复制到
/data - 运行架构迁移
- 从注册表YAML文件+环境变量生成Hermes配置
- 开始爱马仕
analysis简介
建筑
Container (hermes-agent:v0.6.0)
│
└─▶ bootstrap/prestart.sh
├── init-volume.sh # first-run /data setup
├── run-migrations.sh # schema version check
├── validate-risk.sh # execution: risk_policy.yaml required
└── scripts/render-config.py
│
├── providers/provider_registry.yaml ─┐
├── providers/model_aliases.yaml ├─▶ config.generated.yaml
├── mcp/mcp_registry.yaml (filtered) ─┘
└── mcp/mcp.generated.yaml
│
hermes runtime
两个配置文件,一个容器
| 分析 | 执行 | |
|---|---|---|
HERMES_HOME |
/data/.hermes/analysis |
/data/.hermes/execution |
| 默认模型别名 | analysis-deep |
trade-safe |
| 森皮MCP | ❌ 已禁用 | ✅ 活动 |
| 交易执行 | ❌ | ✅ (风险门控) |
| 默认情况下处于活动状态 | ✅ | ❌ — 需要 ACTIVE_PROFILE=execution |
切换到执行配置文件
⚠️ 只有在分析测试和风险政策审查之后才能这样做。
- 审查
/data/risk/risk_policy.yaml彻底地 - 集
ACTIVE_PROFILE=execution铁路变量 - 验证
SENPI_AUTH_TOKEN有效 - 重新部署--
validate-risk.sh将启动
配置系统
规范vs生成
Env vars (secrets)
+
Canonical YAML → bootstrap/render-config.py → Generated config → Hermes runtime
(you edit) (auto-produced) (reads this)
| 文件 | 类型 | 编辑方式 |
|---|---|---|
providers/provider_registry.yaml |
CANONICAL | 操作员 |
providers/model_aliases.yaml |
CANONICAL | 操作员 |
mcp/mcp_registry.yaml |
CANONICAL | 操作员 |
skills/manifests/*.yaml |
CANONICAL | 操作员 |
risk/risk_policy.yaml |
CANONICAL | 操作员 |
workspace/AGENTS.md |
CANONICAL | 操作员 |
.hermes/*/config.generated.yaml |
生成 | render-config.py |
mcp/mcp.generated.yaml |
生成 | render-config.py |
workspace/MEMORY.md |
生成 | 爱马仕代理商 |
规则: 切勿编辑生成的文件。编辑规范的YAML并重新启动容器。
模型别名系统
代理引用模型别名,从不引用原始模型ID。这使您可以在不接触提示的情况下交换提供者。
| 别名 | 用例 | 默认提供程序/模型 |
|---|---|---|
general-fast |
路由、分类 | OpenRouter/GPT-4.1-mini |
general-smart |
高理解任务 | OpenRouter/Claude Sonnet |
analysis-deep |
多步市场分析 | OpenRouter/DeepSeek-R1 |
trade-fast |
低延迟交易决策 | NVIDIA NIM/DeepSeek-R1 |
trade-safe |
安全执行默认值 | OpenRouter/Claude Sonnet |
reasoning-max |
复杂的多步骤策略 | OpenRouter/DeepSeek-R1 |
research-cheap |
新闻,数据收集 | OpenRouter/Llama 3.3免费 |
cn-research |
中文来源分析 | Kimi/Kimi最新 |
风险政策
执行概况 不会启动 没有有效 risk_policy.yaml.
默认安全值(在首次运行init时设置):
mode: copilot # human approval required for all actions
execution:
dry_run_default: true # everything is dry-run until you change this
allow_open_new_position: false # cannot open new positions by default
symbols:
allowlist: ["BTC", "ETH", "SOL"]
default_action: deny # all non-allowlist symbols rejected
trading:
max_leverage: 3
max_position_size_usd: 300
max_daily_loss_usd: 100
要启用实时交易:
- 集
allow_open_new_position: true - 集
dry_run_default: false - 改变
mode: semi-auto或mode: auto - 重新启动容器
技能
技能通过YAML清单进行管理 /data/skills/manifests/.
预配置的技能清单(默认情况下全部禁用):
| 技能 | 简介 | 风险 | 自动批准 |
|---|---|---|---|
wolf-strategy |
分析 | 高 | 否 |
senpi-market-scan |
分析 | 低 | 是 |
senpi-stop-manager |
执行 | 高 | 否 |
安装技能
railway run bash scripts/install-skill.sh /data/skills/manifests/wolf-strategy.yaml
必修的:
pinned_commit必须在清单中设置。仅分支安装被拒绝。
备份与恢复
完整备份
railway run bash scripts/backup-export.sh
# Output: /data/backups/exports/backup-YYYYMMDD-HHMMSS.tar.gz
仅配置备份(无工作区/日志):
railway run bash scripts/export-config.sh
恢复
railway run bash scripts/backup-restore.sh /data/backups/exports/backup-20260404-000000.tar.gz
railway redeploy
还原后,生成的配置将被擦除,并从规范的YAML+当前的env变量中重新生成。会话已清除。
局部烟雾测试
cp .env.example .env
# Edit .env — add at minimum OPENROUTER_API_KEY
docker build --build-arg HERMES_VERSION=v0.6.0 -t hermes-senpi-trader .
docker run --rm \
-e ACTIVE_PROFILE=analysis \
-e DATA_DIR=/data \
-e OPENROUTER_API_KEY=your-key \
-v $(pwd)/.tmpdata:/data \
hermes-senpi-trader
# Check logs — bootstrap should complete and Hermes should start
健康检查
docker run --rm ... bash scripts/healthcheck.sh
升级Hermes
# 1. Take a backup
railway run bash scripts/backup-export.sh
# 2. Update HERMES_VERSION in railway.toml and redeploy
# railway.toml → [build.args] → HERMES_VERSION = "v0.7.0"
railway up
# 3. Bootstrap auto-runs migrations and regenerates config
要回滚:铁路仪表板→ 部署→ 以前的部署→ 回降。
安全
看 安全.md 了解完整的安全模型、边界和操作员检查表。
关键保证:
- API密钥仅存在于env vars中,而不存在于配置文件、日志或工作区中
- Senpi MCP是 难以排除 从渲染器级别的分析配置文件(而不仅仅是配置)
- 执行开始于
dry_run: true和allow_open_new_position: false symbols.default_action: deny--所有未列出的符号均被拒绝- 风险策略在每次启动时验证8个字段——容器在配置错误时会快速失败
- 技能安装需要40个字符的SHA,并在结账后验证HEAD完整性
CI状态
CI通过GitHub Actions在每次推送时运行(.github/workflows/ci.yml):
| 检查 | 它验证了什么 |
|---|---|
shellcheck |
全部 .sh bootstrap/、scripts/、docker/、migrations/中的文件 |
flake8 |
scripts/*.py Python lint |
| 渲染烟雾 | 分析+执行模拟运行;API密钥泄漏检查;Senpi未纳入分析 |
| 风险测试 | 7种情况:有效、允许操作、空满列表、杠杆>10、无效模式、类型错误、丢失文件 |
| 备份/还原 | 完整往返;会话排斥;生成配置排除 |
在本地运行:
bash tests/smoke_render.sh
bash tests/smoke_backup.sh
bash tests/validate_risk_test.sh
项目结构
hermes-senpi-trader/
├── Dockerfile # hermes-agent:v0.6.0 based, pinned
├── railway.toml # Railway deploy config
├── .env.example # Environment variable template
├── CLAUDE.md # AI assistant guidance for this repo
├── SECURITY.md # Security model and operator checklist
├── LICENSE
│
├── bootstrap/ # Container lifecycle scripts
│ ├── prestart.sh # Main entrypoint (6-step boot)
│ ├── init-volume.sh # First-run /data initialization
│ ├── validate-risk.sh # Execution profile risk gate
│ └── run-migrations.sh # Schema version migrations
│
├── scripts/ # Utility scripts
│ ├── render-config.py # Canonical YAML → Hermes config (no keys on disk)
│ ├── install-skill.sh # Pinned-commit skill installer (SHA verified)
│ ├── backup-export.sh # Full volume backup (sessions excluded)
│ ├── backup-restore.sh # Restore from backup (path traversal guard)
│ ├── export-config.sh # Config-only export
│ ├── healthcheck.sh # Container health validation
│ └── lib/
│ └── redact.sh # Secret redaction helper library
│
├── config/ # Canonical config templates (.example.yaml)
│ ├── providers/
│ │ ├── provider_registry.example.yaml
│ │ └── model_aliases.example.yaml
│ ├── mcp_registry.example.yaml
│ ├── profiles.example.yaml
│ ├── risk_policy.example.yaml
│ ├── symbol_policy.example.yaml
│ └── skills/
│ ├── wolf-strategy.example.yaml
│ ├── senpi-market-scan.example.yaml
│ └── senpi-stop-manager.example.yaml
│
├── defaults/workspace/ # First-run agent workspace content
│ ├── AGENTS.md
│ ├── BOOTSTRAP.md
│ └── USER.md
│
├── templates/
│ └── hermes-config.j2 # Jinja2 template for config generation
│
├── docker/
│ └── entrypoint.sh # Docker SIGTERM handler
│
├── migrations/
│ └── 0001_initial_schema.sh
│
├── tests/
│ ├── smoke_render.sh # Config render smoke test (API key leak check)
│ ├── smoke_backup.sh # Backup/restore round-trip test
│ └── validate_risk_test.sh # Risk policy unit tests (7 cases)
│
├── .github/workflows/
│ └── ci.yml # CI: shellcheck, flake8, smoke tests
│
└── docs/
├── architecture.md
├── deployment.md
├── backup-restore.md
├── migration.md
└── security.md
生产检查表
部署前检查表
[ ] Volume mounted at /data (minimum 5 GB)
[ ] ACTIVE_PROFILE=analysis (NOT execution for first deploy)
[ ] OPENROUTER_API_KEY set in Railway Variables (not in any config file)
[ ] DATA_DIR=/data in Railway Variables
[ ] HERMES_VERSION pinned (e.g., v0.6.0) — never use 'latest'
[ ] .env file is in .gitignore and not committed to git
[ ] railway.toml contains no secret values
[ ] CI green: shellcheck, python lint, render smoke, risk tests
纸质交易清单
在启用执行配置文件之前:
[ ] At least 7 days of analysis profile without errors
[ ] risk_policy.yaml reviewed — all 8 required fields intentionally set
[ ] dry_run_default: true (YAML boolean, not string)
[ ] allow_open_new_position: false
[ ] mode: copilot
[ ] symbols.allowlist has only intended symbols
[ ] symbols.default_action: deny
[ ] max_leverage <= 3 for initial testing
[ ] max_daily_loss_usd set to acceptable ceiling
[ ] Backup taken before switching profiles
[ ] SENPI_AUTH_TOKEN valid
[ ] ACTIVE_PROFILE=execution → redeploy → logs show "Risk policy validation passed"
[ ] Healthcheck passes: bash scripts/healthcheck.sh
实时资金清单
警告:不要跳过任何项目。每个人都保护着真正的资本。
设置前 dry_run_default: false:
[ ] Paper trading tested for at least 2 weeks
[ ] Paper trade outcomes reviewed, strategy validated
[ ] max_position_size_usd <= 5% of portfolio per trade
[ ] max_daily_loss_usd < 3% of total capital
[ ] max_leverage <= 3 (only increase after proven track record)
[ ] Telegram or alert channel configured and tested
[ ] Backup taken immediately before going live
[ ] Rollback plan documented: Railway Deployments -> Rollback
[ ] Someone monitors the first 24h of live trading
[ ] dry_run_default: false — set explicitly and intentionally
[ ] allow_open_new_position: true — set explicitly and intentionally
[ ] Mode stays copilot or semi-auto — never jump directly to auto
[ ] Bootstrap logs reviewed after deploy: validate-risk passed
还原验证检查表
从备份还原后:
[ ] bash scripts/backup-restore.sh <archive.tar.gz> --yes
[ ] Railway redeploy
[ ] Bootstrap logs: "Config generation completed"
[ ] Healthcheck passes: bash scripts/healthcheck.sh
[ ] /data/providers/provider_registry.yaml exists and valid
[ ] /data/risk/risk_policy.yaml exists
[ ] /data/workspace/AGENTS.md exists
[ ] Generated configs present: ls /data/.hermes/*/config.generated.yaml
[ ] Sessions cleared: ls /data/.hermes/*/sessions/ (should be empty)
[ ] API keys valid on new host: python3 scripts/render-config.py --validate-only
[ ] ACTIVE_PROFILE=analysis tested before enabling execution
升级/回滚清单
升级前 HERMES_VERSION:
[ ] Backup taken: bash scripts/backup-export.sh
[ ] Backup downloaded and verified locally: tar -tzf backup.tar.gz
[ ] New HERMES_VERSION changelog reviewed for breaking changes
[ ] HERMES_VERSION pinned in railway.toml (never 'latest')
[ ] CI green before deploy
[ ] Bootstrap migration logs reviewed after redeploy
[ ] Healthcheck passes on new version
[ ] Analysis profile tested before enabling execution
要回滚,请执行以下操作: Railway Dashboard → Deployments → [previous] → Rollback
这
/data卷不受容器回滚的影响。规范配置和工作区得以保留。