Thanks to visit codestin.com
Credit goes to github.com

Skip to content

stamns/agent-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Agent Guard

🛡️ 通用 AI Agent 防护系统 —— Restic 驱动的块级去重备份 + 崩溃自动恢复 + 多 Agent 适配

License Python Restic

为什么需要 Agent Guard

自部署 AI Agent(Dify、N8N、FastGPT、OpenClaw、LobeChat、Open-WebUI……)最怕两件事:配置改崩了起不来,和数据丢了没备份

Agent Guard 在 Agent 容器之外建立独立安全网,不侵入容器、不修改镜像,通过宿主机 Sidecar 模式提供五层防护。

核心特性

  • Restic 块级去重备份:10MB 配置改 1 字节只多存几 KB,100 次快照仅占原始 1.1-1.3 倍空间
  • AES-256 加密 + SHA-256 校验:备份数据安全且可验证完整性
  • 数据库热备份:支持 PostgreSQL、MongoDB、Redis、SQLite
  • 崩溃自动恢复:配置损坏时自动回滚到 last-known-good,10 秒内恢复
  • 实时文件监控:inotify 监控配置变更,修改前自动快照
  • 多 Agent 适配:YAML 声明式配置,一份配置适配一个 Agent
  • 多渠道告警:飞书 / 钉钉 / Slack / Webhook
  • 一键安装:支持 1Panel / Docker / 裸机部署

已适配 Agent

Agent 配置文件 数据库 状态
OpenClaw agents/openclaw.yaml ✅ 已验证
Dify agents/dify.yaml PostgreSQL + Redis ✅ 预置
N8N agents/n8n.yaml PostgreSQL / SQLite ✅ 预置
FastGPT agents/fastgpt.yaml MongoDB + PostgreSQL ✅ 预置
LobeChat agents/lobechat.yaml PostgreSQL ✅ 预置
Open-WebUI agents/open-webui.yaml SQLite ✅ 预置
自定义 agents/custom.yaml.example 任意 📝 模板

快速开始

1Panel 用户(推荐)

# 1. 克隆仓库
cd /opt && git clone https://github.com/stamns/agent-guard.git

# 2. 一键安装(自动检测已安装的 Agent)
bash /opt/agent-guard/install.sh

# 3. 查看状态
agent-guard status

# 4. 查看备份列表
agent-guard snapshots

Docker / 裸机

cd /opt && git clone https://github.com/stamns/agent-guard.git
cd agent-guard
cp config/guard.yaml.example config/guard.yaml
# 编辑 guard.yaml 填入实际路径
bash install.sh

命令速查

agent-guard status                    # 查看所有 Agent 防护状态
agent-guard snapshots [agent]         # 列出快照
agent-guard backup [agent]            # 立即创建快照
agent-guard restore <agent> [id]      # 恢复到指定快照(默认最新)
agent-guard rollback <agent>          # 回滚到 last-known-good
agent-guard diff <agent> <id1> <id2>  # 对比两个快照差异
agent-guard check <agent>             # 健康检查 + 配置校验
agent-guard logs [agent]              # 查看防护日志
agent-guard add <agent-yaml>          # 添加新 Agent 适配

架构

┌─────────────────────────────────────────────────────────────┐
│  第1层:实时监控    │  inotify 文件监控 + 修改前自动快照       │
├─────────────────────────────────────────────────────────────┤
│  第2层:崩溃恢复    │  配置校验 + last-known-good 自动回滚     │
├─────────────────────────────────────────────────────────────┤
│  第3层:版本控制    │  Restic 块级去重快照 + 数据库热备份       │
├─────────────────────────────────────────────────────────────┤
│  第4层:健康检查    │  HTTP/TCP/进程 多模式检查 + 自动重启      │
├─────────────────────────────────────────────────────────────┤
│  第5层:远程容灾    │  Restic 原生 S3/R2/SFTP 远程仓库         │
└─────────────────────────────────────────────────────────────┘

目录结构

agent-guard/
├── install.sh                     # 一键安装脚本
├── uninstall.sh                   # 卸载脚本
├── bin/
│   └── agent-guard                # 主命令行入口
├── core/
│   ├── guardian.py                # 核心调度器
│   ├── backup.py                 # Restic 备份引擎
│   ├── database.py               # 数据库备份模块
│   ├── monitor.py                # inotify 文件监控
│   ├── health.py                 # 健康检查模块
│   ├── recovery.py               # 崩溃恢复模块
│   ├── alert.py                  # 告警通知模块
│   └── config.py                 # 配置加载器
├── agents/                        # Agent 适配配置
│   ├── openclaw.yaml
│   ├── dify.yaml
│   ├── n8n.yaml
│   ├── fastgpt.yaml
│   ├── lobechat.yaml
│   ├── open-webui.yaml
│   └── custom.yaml.example
├── config/
│   └── guard.yaml.example        # 全局配置模板
├── systemd/                       # systemd 服务文件
│   ├── agent-guard.service
│   ├── agent-guard-monitor.service
│   ├── agent-guard-snapshot.service
│   └── agent-guard-snapshot.timer
├── docs/
│   ├── ARCHITECTURE.md
│   ├── AGENTS.md
│   └── RECOVERY.md
├── tests/
│   └── test-all.sh
├── .gitignore
├── LICENSE
└── README.md

与 OpenClaw Guard 的对比

维度 OpenClaw Guard Agent Guard
备份引擎 rsync --link-dest(文件级) Restic(块级去重+加密)
存储效率 100次快照 ≈ 原始×2-5倍 100次快照 ≈ 原始×1.1-1.3倍
数据库支持 PostgreSQL / MongoDB / Redis / SQLite
适配范围 仅 OpenClaw 任意 Agent(YAML 声明式)
加密 AES-256
远程存储 需额外配 rclone Restic 原生支持 S3/R2/SFTP
完整性校验 SHA-256 自动校验
恢复方式 rsync 覆盖 任意快照独立恢复

许可证

MIT License

About

Universal AI Agent protection system - Restic-powered incremental backup, auto crash recovery, multi-agent support (Dify/N8N/FastGPT/OpenClaw/LobeChat/Open-WebUI)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors