c0debyeric/AI-Agent-Platform
GitHub: c0debyeric/AI-Agent-Platform
基于 CrewAI 框架构建的多 Agent DevOps 自动化平台,利用专业化 AI Agent 协作完成基础设施审查、安全扫描、文档生成和事件响应等任务。
Stars: 1 | Forks: 0
# AI Agent 平台 — 多 Agent DevOps 自动化
[](https://www.python.org/downloads/)
[](https://www.crewai.com/)
[](https://www.langchain.com/)
[](https://www.docker.com/)
[](https://docs.pytest.org/)
## 这是什么?
一个**多 Agent 系统**,由专业的 AI Agent 协作自动执行 DevOps 任务:
- **基础设施审查** — 分析 Terraform/K8s 配置,检查最佳实践和配置错误
- **安全扫描** — 扫描代码中的 OWASP Top 10 漏洞、硬编码机密和不安全模式
- **文档生成** — 根据代码分析结果生成清晰的技术文档
- **事件响应** — 对告警进行分诊,确定根本原因,并建议修复步骤
每个 Agent 都有明确的角色、工具和背景故事——反映了现实工程团队中职责划分的方式。CrewAI 负责编排它们的协作,使任务按照依赖顺序流转,一个 Agent 的输出将作为下一个 Agent 的输入。
## 为什么构建这个项目
我在使用 **n8n**(低代码)构建 Agentic 工作流方面有生产环境的经验,但需要展示以下几点:
1. **Python 原生的 Agent 编排** — 可编程,而非拖拽式操作
2. **可测试的 Agent 系统** — 每个 Agent、工具和 Crew 都有单元测试
3. **可版本控制的 AI 工作流** — Git 友好的代码,而非 JSON 配置
4. **生产级模式** — 结构化日志、Pydantic 模型、错误处理、Docker 部署
这个项目证明了我能够使用业界标准的 Python 工具从头开始设计和构建多 Agent 系统。
## 系统架构
```
graph TD
CLI[CLI Entrypoint
src/main.py] --> CREW[DevOps Crew
Orchestrator] CREW --> INFRA[Infra Review Agent
Senior Infrastructure Engineer] CREW --> SEC[Security Agent
Application Security Engineer] CREW --> DOCS[Docs Agent
Technical Documentation Specialist] CREW --> INC[Incident Agent
SRE / Incident Response Engineer] INFRA -->|findings| SEC SEC -->|vulnerabilities| DOCS SEC -->|critical issues| INC INFRA -->|config analysis| DOCS INFRA --- T1[Terraform Analysis Tool
K8s Config Tool] SEC --- T2[Code Security Scan Tool
File Reader Tool] DOCS --- T3[File Writer Tool] INC --- T4[Log Analysis Tool] LLM[AWS Bedrock
Claude Sonnet] -.->|LLM calls| INFRA LLM -.-> SEC LLM -.-> DOCS LLM -.-> INC style CREW fill:#4a90d9,stroke:#333,color:#fff style INFRA fill:#50c878,stroke:#333,color:#fff style SEC fill:#ff6b6b,stroke:#333,color:#fff style DOCS fill:#ffa500,stroke:#333,color:#fff style INC fill:#9b59b6,stroke:#333,color:#fff style LLM fill:#333,stroke:#666,color:#fff ``` ### 任务依赖流程 ``` infra_review_task │ ▼ security_scan_task ──► incident_response_task │ ▼ docs_generation_task ``` ## 技术栈 | 组件 | 技术 | 用途 | |-----------|-----------|---------| | Agent 框架 | CrewAI | 具有角色、目标和委托功能的多 Agent 编排 | | LLM 提供商 | AWS Bedrock (Claude) | 用于 Agent 推理的基础模型 | | LLM 抽象层 | LangChain | 统一的 LLM 接口 + 工具集成 | | 配置管理 | Pydantic Settings | 类型安全的环境配置 | | 日志记录 | structlog | 用于可观测性的结构化 JSON 日志 | | 测试 | pytest + pytest-asyncio | 单元测试和集成测试 | | 容器化 | Docker + Compose | 可重现的部署 | | 包管理器 | uv / pip | 快速的 Python 依赖管理 | ## 项目结构 ``` AI-Agent-Platform/ ├── src/ │ ├── __init__.py │ ├── config.py # Pydantic Settings — env var loading │ ├── main.py # CLI entrypoint │ ├── agents/ │ │ ├── __init__.py │ │ ├── infra_reviewer.py # Terraform/K8s review agent │ │ ├── security_scanner.py # OWASP vulnerability scanner agent │ │ ├── docs_generator.py # Documentation generation agent │ │ └── incident_responder.py # Incident triage agent │ ├── tools/ │ │ ├── __init__.py │ │ ├── terraform_tools.py # IaC analysis tools │ │ └── code_tools.py # Code scanning tools │ └── crews/ │ ├── __init__.py │ └── devops_crew.py # Main crew definition + task wiring ├── tests/ │ ├── __init__.py │ ├── test_agents.py │ ├── test_tools.py │ └── test_crew.py ├── sample_configs/ │ ├── sample.tf # Terraform with intentional issues (demo) │ └── sample.py # Python with intentional vulns (demo) ├── docker-compose.yml ├── Dockerfile ├── Makefile ├── pyproject.toml ├── .env.example └── .gitignore ``` ## 如何在本地运行 ### 前置条件 - Python 3.12+ - 已配置 AWS 凭证(用于访问 Bedrock) - Docker(可选,用于容器化运行) ### 快速开始 ``` # 1. 克隆并安装 git clone https://github.com/yourusername/AI-Agent-Platform.git cd AI-Agent-Platform make install # 2. 配置环境 cp .env.example .env # 使用您的 AWS 凭证和 Bedrock 模型 ID 编辑 .env # 3. 使用示例配置运行(演示模式) make dev # 4. 针对您自己的代码运行 python -m src.main ./path/to/your/project # 5. 运行测试 make test ``` ### Docker ``` # 构建并运行 make docker-build make docker-run # 或使用 docker-compose docker-compose up ``` ## 示例输出 ``` $ python -m src.main ./sample_configs/ 2025-06-15 10:23:01 [info] Starting DevOps Crew analysis target=./sample_configs/ 2025-06-15 10:23:01 [info] Initializing agents count=4 ═══════════════════════════════════════════════════════════ Agent: Senior Infrastructure Engineer Task: Review infrastructure configuration ═══════════════════════════════════════════════════════════ [Infra Review Agent] Analyzing Terraform files... ⚠ WARN: S3 bucket missing server-side encryption (sample.tf:12) ⚠ WARN: Security group allows 0.0.0.0/0 on port 22 (sample.tf:24) ✓ OK: VPC has flow logging enabled ✗ FAIL: No lifecycle policy on resources ═══════════════════════════════════════════════════════════ Agent: Application Security Engineer Task: Perform security analysis ═══════════════════════════════════════════════════════════ [Security Agent] Scanning codebase... ✗ CRITICAL: Hardcoded AWS secret key detected (sample.py:5) ✗ HIGH: SQL injection via string formatting (sample.py:18) ⚠ MEDIUM: Use of eval() on user input (sample.py:25) ═══════════════════════════════════════════════════════════ Crew Result: 3 critical, 2 warnings, 1 passed ═══════════════════════════════════════════════════════════ ``` ## 关键工程决策 ### 为什么选择 CrewAI 而不是 LangGraph? CrewAI 开箱即用地提供了**基于角色的 Agent 设计**——每个 Agent 都有一个角色、目标和背景故事来塑造其行为。LangGraph 更灵活,但需要从头开始构建编排逻辑。在 DevOps 自动化场景中,Agent 映射到真实的团队角色(如 SRE、安全工程师等),CrewAI 的强约束结构更为合适,能够生成更清晰、更易于维护的代码。 ### Agent 记忆模式 Agent 使用 CrewAI 内置的**短期记忆**(Crew 运行中的对话上下文)和**长期记忆**(跨运行的持久化学习)。这意味着安全 Agent 可以从过去的扫描中学习——如果它之前将某种模式识别为误报,它会在未来的运行中记住这一点。 ### 错误处理方式 每个工具将操作封装在 try/except 中,并返回结构化的错误信息,而不是导致 Crew 崩溃。Agent 配置了 `allow_delegation=False`,以实现可预测的任务路由。Crew 使用 `max_rpm` 来限制 LLM 调用频率,避免 API 限流。 ### 结构化日志 所有组件均使用 `structlog` 生成 JSON 格式的日志。这支持在生产环境中进行日志聚合(CloudWatch、Datadog 等),并使调试 Agent 交互变得可追踪——每个 Agent 操作、工具调用和 LLM 请求都记录了相关上下文。 ## 展示技能 | 技能 | 证明 | |-------|----------| | Python AI/ML 工程 | CrewAI Agent、LangChain 工具、Pydantic 模型 | | 云平台 (AWS) | Bedrock LLM 集成、具备 IAM 意识的安全扫描 | | 基础设施即代码 | Terraform/K8s 分析工具、IaC 最佳实践检查 | | 安全工程 | 感知 OWASP 的扫描、机密检测、CVE 模式 | | DevOps / SRE | 事件响应自动化、Docker 部署、CI/CD 就绪 | | 软件工程 | 类型提示、结构化日志、pytest、整洁架构 | | 系统设计 | 多 Agent 编排、任务依赖、记忆模式 | *由 Eric Nguyen 构建 — 目标职位为 AI 平台工程师的云平台工程师。*
src/main.py] --> CREW[DevOps Crew
Orchestrator] CREW --> INFRA[Infra Review Agent
Senior Infrastructure Engineer] CREW --> SEC[Security Agent
Application Security Engineer] CREW --> DOCS[Docs Agent
Technical Documentation Specialist] CREW --> INC[Incident Agent
SRE / Incident Response Engineer] INFRA -->|findings| SEC SEC -->|vulnerabilities| DOCS SEC -->|critical issues| INC INFRA -->|config analysis| DOCS INFRA --- T1[Terraform Analysis Tool
K8s Config Tool] SEC --- T2[Code Security Scan Tool
File Reader Tool] DOCS --- T3[File Writer Tool] INC --- T4[Log Analysis Tool] LLM[AWS Bedrock
Claude Sonnet] -.->|LLM calls| INFRA LLM -.-> SEC LLM -.-> DOCS LLM -.-> INC style CREW fill:#4a90d9,stroke:#333,color:#fff style INFRA fill:#50c878,stroke:#333,color:#fff style SEC fill:#ff6b6b,stroke:#333,color:#fff style DOCS fill:#ffa500,stroke:#333,color:#fff style INC fill:#9b59b6,stroke:#333,color:#fff style LLM fill:#333,stroke:#666,color:#fff ``` ### 任务依赖流程 ``` infra_review_task │ ▼ security_scan_task ──► incident_response_task │ ▼ docs_generation_task ``` ## 技术栈 | 组件 | 技术 | 用途 | |-----------|-----------|---------| | Agent 框架 | CrewAI | 具有角色、目标和委托功能的多 Agent 编排 | | LLM 提供商 | AWS Bedrock (Claude) | 用于 Agent 推理的基础模型 | | LLM 抽象层 | LangChain | 统一的 LLM 接口 + 工具集成 | | 配置管理 | Pydantic Settings | 类型安全的环境配置 | | 日志记录 | structlog | 用于可观测性的结构化 JSON 日志 | | 测试 | pytest + pytest-asyncio | 单元测试和集成测试 | | 容器化 | Docker + Compose | 可重现的部署 | | 包管理器 | uv / pip | 快速的 Python 依赖管理 | ## 项目结构 ``` AI-Agent-Platform/ ├── src/ │ ├── __init__.py │ ├── config.py # Pydantic Settings — env var loading │ ├── main.py # CLI entrypoint │ ├── agents/ │ │ ├── __init__.py │ │ ├── infra_reviewer.py # Terraform/K8s review agent │ │ ├── security_scanner.py # OWASP vulnerability scanner agent │ │ ├── docs_generator.py # Documentation generation agent │ │ └── incident_responder.py # Incident triage agent │ ├── tools/ │ │ ├── __init__.py │ │ ├── terraform_tools.py # IaC analysis tools │ │ └── code_tools.py # Code scanning tools │ └── crews/ │ ├── __init__.py │ └── devops_crew.py # Main crew definition + task wiring ├── tests/ │ ├── __init__.py │ ├── test_agents.py │ ├── test_tools.py │ └── test_crew.py ├── sample_configs/ │ ├── sample.tf # Terraform with intentional issues (demo) │ └── sample.py # Python with intentional vulns (demo) ├── docker-compose.yml ├── Dockerfile ├── Makefile ├── pyproject.toml ├── .env.example └── .gitignore ``` ## 如何在本地运行 ### 前置条件 - Python 3.12+ - 已配置 AWS 凭证(用于访问 Bedrock) - Docker(可选,用于容器化运行) ### 快速开始 ``` # 1. 克隆并安装 git clone https://github.com/yourusername/AI-Agent-Platform.git cd AI-Agent-Platform make install # 2. 配置环境 cp .env.example .env # 使用您的 AWS 凭证和 Bedrock 模型 ID 编辑 .env # 3. 使用示例配置运行(演示模式) make dev # 4. 针对您自己的代码运行 python -m src.main ./path/to/your/project # 5. 运行测试 make test ``` ### Docker ``` # 构建并运行 make docker-build make docker-run # 或使用 docker-compose docker-compose up ``` ## 示例输出 ``` $ python -m src.main ./sample_configs/ 2025-06-15 10:23:01 [info] Starting DevOps Crew analysis target=./sample_configs/ 2025-06-15 10:23:01 [info] Initializing agents count=4 ═══════════════════════════════════════════════════════════ Agent: Senior Infrastructure Engineer Task: Review infrastructure configuration ═══════════════════════════════════════════════════════════ [Infra Review Agent] Analyzing Terraform files... ⚠ WARN: S3 bucket missing server-side encryption (sample.tf:12) ⚠ WARN: Security group allows 0.0.0.0/0 on port 22 (sample.tf:24) ✓ OK: VPC has flow logging enabled ✗ FAIL: No lifecycle policy on resources ═══════════════════════════════════════════════════════════ Agent: Application Security Engineer Task: Perform security analysis ═══════════════════════════════════════════════════════════ [Security Agent] Scanning codebase... ✗ CRITICAL: Hardcoded AWS secret key detected (sample.py:5) ✗ HIGH: SQL injection via string formatting (sample.py:18) ⚠ MEDIUM: Use of eval() on user input (sample.py:25) ═══════════════════════════════════════════════════════════ Crew Result: 3 critical, 2 warnings, 1 passed ═══════════════════════════════════════════════════════════ ``` ## 关键工程决策 ### 为什么选择 CrewAI 而不是 LangGraph? CrewAI 开箱即用地提供了**基于角色的 Agent 设计**——每个 Agent 都有一个角色、目标和背景故事来塑造其行为。LangGraph 更灵活,但需要从头开始构建编排逻辑。在 DevOps 自动化场景中,Agent 映射到真实的团队角色(如 SRE、安全工程师等),CrewAI 的强约束结构更为合适,能够生成更清晰、更易于维护的代码。 ### Agent 记忆模式 Agent 使用 CrewAI 内置的**短期记忆**(Crew 运行中的对话上下文)和**长期记忆**(跨运行的持久化学习)。这意味着安全 Agent 可以从过去的扫描中学习——如果它之前将某种模式识别为误报,它会在未来的运行中记住这一点。 ### 错误处理方式 每个工具将操作封装在 try/except 中,并返回结构化的错误信息,而不是导致 Crew 崩溃。Agent 配置了 `allow_delegation=False`,以实现可预测的任务路由。Crew 使用 `max_rpm` 来限制 LLM 调用频率,避免 API 限流。 ### 结构化日志 所有组件均使用 `structlog` 生成 JSON 格式的日志。这支持在生产环境中进行日志聚合(CloudWatch、Datadog 等),并使调试 Agent 交互变得可追踪——每个 Agent 操作、工具调用和 LLM 请求都记录了相关上下文。 ## 展示技能 | 技能 | 证明 | |-------|----------| | Python AI/ML 工程 | CrewAI Agent、LangChain 工具、Pydantic 模型 | | 云平台 (AWS) | Bedrock LLM 集成、具备 IAM 意识的安全扫描 | | 基础设施即代码 | Terraform/K8s 分析工具、IaC 最佳实践检查 | | 安全工程 | 感知 OWASP 的扫描、机密检测、CVE 模式 | | DevOps / SRE | 事件响应自动化、Docker 部署、CI/CD 就绪 | | 软件工程 | 类型提示、结构化日志、pytest、整洁架构 | | 系统设计 | 多 Agent 编排、任务依赖、记忆模式 | *由 Eric Nguyen 构建 — 目标职位为 AI 平台工程师的云平台工程师。*
标签:AIOps, AI工作流, AI智能体, CISA项目, CrewAI, DevOps自动化, DevSecOps, Docker, Kubernetes配置审查, LangChain, Pydantic, PyRIT, Pytest, Python, Python 3.12, StruQ, Terraform审查, 上游代理, 代码安全分析, 基础设施审查, 多智能体系统, 子域名变形, 安全扫描, 安全规则引擎, 安全防御评估, 容器化部署, 微服务架构, 文档自动生成, 无后门, 时序注入, 智能运维, 根本原因分析, 自动化运维, 请求拦截, 软件供应链安全, 轻量级, 远程方法调用, 逆向工具