Es777777/aegis-code-repo-agent
GitHub: Es777777/aegis-code-repo-agent
AEGIS 2.0 是一个多 Agent 代码仓库分析系统,通过 CodeGraph 和源码 RAG 将代码库转化为可复用的机器可读知识层,供下游 Agent 低成本地理解和问答。
Stars: 0 | Forks: 0
# AEGIS 2.0
AEGIS 是一个为火山杯智能体竞赛构建的多 Agent 仓库分析系统。

它将代码仓库转化为可复用的机器可读知识层,然后通过以下方式暴露该层:
- `CodeGraph` 用于结构、路由和依赖追踪
- 基于源码的 `RAG` 用于仓库问答
- 紧凑的 `handoff_card.json` 和 `run_summary.json` 产物供下游 Agent 使用
- `status`、`handoff`、`eval`、`ready` 和 HTTP API 入口,适用于 Coze 等编排系统
`handoff_card.json` 是供下游 Agent 使用的默认机器接口,并且
`primary_task.recommended_command_line` 在存在时是首选的下一步指引。
## 快速链接
- [竞赛演示](docs/DEMO.md)
- [发布检查清单](docs/RELEASE_CHECKLIST.md)
- [演示结果](docs/DEMO_RESULTS.md)
- [架构](docs/ARCHITECTURE.md)
- [公开仓库副本](docs/PUBLIC_REPO_COPY.md)
- [技能入口](skills/aegis-repo-analyst/SKILL.md)
## AEGIS 擅长的领域
- 比普通文件搜索具有更好的泛化能力:
检索会扩展仓库概念,如架构、路由、时序、布局、设备资源和入口点。
- 降低 Agent 工作流的 token 成本:
下游 Agent 可以获取紧凑的简报、模块图、概念图和建议的下一步操作,而无需重新阅读整个仓库。
- 更强的抽象能力:
系统会生成仓库摘要、图追踪、调查简报和可复用的 handoff payload。
- 更好的展示和报告:
它会生成 Markdown、HTML、Mermaid、JSON 产物以及对机器友好的 Agent 简报。
- 对 Coze 友好的集成:
使用 HTTP JSON API,而不是依赖 Agent 平台内部的 shell 命令执行。
## 快速开始
## 3 条命令演示
```
python main.py examples\sample_repo --doctor --json
python main.py examples\sample_repo --max-files 100 --no-cache --ready --ready-fail-under 1.0 --ready-ask "POST /users call chain" --json
python main.py --from-output output\aegis\sample_repo --handoff --json
```
## 快速开始
运行完整的仓库分析:
```
python main.py examples\sample_repo
```
提出仓库问题:
```
python main.py examples\sample_repo --ask "Where is user creation implemented?" --json
```
复用现有的分析输出:
```
python main.py --from-output output\aegis\sample_repo --handoff --json
python main.py --from-output output\aegis\sample_repo --status --json
```
## Coze / HTTP API
启动 API 服务:
```
python main.py --api --host 127.0.0.1 --port 8766
```
端点:
- `GET /health`
- `GET /status?output_dir=...`
- `GET /handoff?output_dir=...`
- `POST /analyze`
- `POST /ask`
- `POST /doctor`
示例 `POST /ask` body:
```
{
"repo": "examples/eda_repo",
"out": "output/aegis",
"max_files": 100,
"no_cache": true,
"question": "它的布线算法原理是什么",
"top_k": 8,
"context_chars": 48000,
"llm": false
}
```
## 环境配置
AEGIS 在启动时会自动读取 `.env`。
复制模板:
```
Copy-Item .env.example .env
```
核心变量:
```
AEGIS_REPO_PATH=examples/sample_repo
AEGIS_OUTPUT_DIR=output/aegis
AEGIS_MAX_FILES=1500
AEGIS_RAG_CONTEXT_CHARS=48000
AEGIS_USE_CACHE=true
AEGIS_INCLUDE=
AEGIS_EXCLUDE=
AEGIS_SERVE_DIR=
AEGIS_SERVE_HOST=127.0.0.1
AEGIS_SERVE_PORT=8765
```
可选的 OpenAI 兼容 LLM 变量:
```
AEGIS_LLM_ENABLED=false
AEGIS_LLM_API_KEY=
AEGIS_LLM_BASE_URL=https://api.openai.com/v1
AEGIS_LLM_MODEL=gpt-4o-mini
AEGIS_LLM_TIMEOUT_SECONDS=120
AEGIS_LLM_MAX_CONTEXT_CHARS=14000
```
## 主要输出
分析完成后,AEGIS 会写入:
- `knowledge.json`
- `findings.json`
- `rag_index.json`
- `report.md`
- `report.html`
- `architecture.mmd`
- `manifest.json`
- `run_summary.json`
- `handoff_card.json`
在执行 `--ask` 后,它还会写入:
- `qa_answer.json`
- `context_pack.md`
- `llm_prompt.md`
## 为什么架构以 Agent 为核心
AEGIS 不再围绕“即使没有强上下文也要给出答案”进行优化。
它围绕为 Agent 提供更好的输入进行了优化:
- `CodeGraph` 提供结构基础。
- `RAG` 在可能的情况下将真实的、带有行号的源文件打包到上下文中。
- `required_context_paths` 和 `target_context_paths` 保护 LLM 安全。
- `briefings`、`module_map` 和 `concept_map` 减少了重复的 token 开销。
- `handoff_card.json` 直接为下一个 Agent 提供下一步指引,而不是让它重新发现工作流状态。
## 验证
运行测试套件:
```
python -m unittest discover -s tests -v
```
或者运行专注的质量路径:
```
python main.py examples\sample_repo --doctor --json
python main.py examples\sample_repo --max-files 100 --no-cache --ready --ready-fail-under 1.0 --ready-ask "POST /users call chain" --json
python main.py --from-output output\aegis\sample_repo --handoff --json
```
标签:AI智能体, Python脚本, RAG, 代码分析, 凭证管理, 多智能体协作, 逆向工具