Hermes 源码全景
目录结构
hermes-agent/
├── run_agent.py # AIAgent 核心类(5,568 行)
├── model_tools.py # 工具发现和分发
├── toolsets.py # Toolset 定义
├── cli.py # prompt_toolkit CLI(15,197 行)
├── hermes_state.py # SQLite session store(5,103 行)
├── agent/ # Agent 核心模块(117 文件,75K 行)
│ ├── agent_init.py # AIAgent.__init__ 实现
│ ├── conversation_loop.py # 核心对话循环
│ ├── turn_context.py # 每轮 prologue
│ ├── tool_executor.py # 工具执行器
│ ├── chat_completion_helpers.py # API 调用
│ ├── transports/ # Provider transport 抽象
│ ├── memory_manager.py # 记忆管理
│ ├── context_compressor.py # 上下文压缩
│ └── ...
├── tools/ # 工具实现(106 文件,83K 行)
│ └── registry.py # 工具注册中心
├── gateway/ # 消息平台 gateway(62 文件,69K 行)
│ ├── run.py # GatewayRunner(17,851 行)
│ └── platforms/ # Telegram/Discord/Slack/... adapter
├── hermes_cli/ # CLI 子命令(184 文件,143K 行)
│ ├── main.py # CLI 总入口(13,191 行)
│ ├── commands.py # Slash command 注册
│ ├── config.py # 配置管理
│ ├── plugins.py # 插件系统
│ └── ...
├── cron/ # 定时任务系统(9 文件)
│ ├── jobs.py # Job 存储管理
│ └── scheduler.py # 调度器
├── acp_adapter/ # ACP server(11 文件)
│ └── server.py # IDE 集成
├── ui-tui/ # TypeScript Ink TUI
├── apps/desktop/ # Electron Desktop
├── plugins/ # 内置和社区插件(172 文件)
├── skills/ # 内置 skills
└── tests/ # 测试(1,700 文件,612K 行)核心入口
CLI
text
hermes_cli/main.py → argparse → cli.py(HermesCLI) / gateway / setup / cron / ...Gateway
text
gateway/run.py → GatewayRunner.start() → platform adapters → AIAgentCron
text
cron/scheduler.py → cron/jobs.py → AIAgentACP
text
acp_adapter/server.py → ThreadPoolExecutor → AIAgentGod Files
Hermes 有几个很大的文件,正在逐步拆分:
| 文件 | 行数 | 状态 |
|---|---|---|
gateway/run.py | 17,851 | 待拆分 |
cli.py | 15,197 | 已抽 mixin |
hermes_cli/main.py | 13,191 | 已拆 subcommands |
run_agent.py | 5,568 | agent_init 已抽 |
hermes_state.py | 5,103 | 相对独立 |