Skip to main content

最佳实践

安全性

API 密钥管理

  • 使用环境变量存储敏感信息
  • 定期轮换密钥
  • 不要在代码中硬编码密钥
# 正确做法
export OPENROUTER_API_KEY=sk_...

# 错误做法
api_key = "sk_..." # 不要这样做

权限管理

  • 最小权限原则
  • 定期审计权限
  • 限制工具访问
tools:
permissions:
terminal:
allow_sudo: false
allowed_commands:
- npm
- git

性能优化

缓存策略

cache:
enabled: true
ttl: 3600
max_size: 100MB

并发控制

hermes run --concurrency 4 "task"

资源限制

resources:
memory: 2GB
cpu: 2
timeout: 300

错误处理

重试策略

retry:
max_attempts: 3
backoff: exponential
initial_delay: 1s

日志记录

# 启用详细日志
hermes start --log-level debug

# 查看日志
hermes logs --tail 100

监控和告警

健康检查

hermes health

性能监控

hermes monitor --interval 60

告警配置

alerts:
- type: error_rate
threshold: 0.05
action: notify

- type: response_time
threshold: 5000
action: notify

备份和恢复

定期备份

hermes backup --output ~/backups/hermes-backup.tar.gz

恢复数据

hermes restore ~/backups/hermes-backup.tar.gz

更新和维护

检查更新

hermes update check

安全更新

hermes update --security-only

版本管理

hermes version
hermes version history