Skip to content

源码导航地图

快速定位关键文件,按功能模块分类。

核心循环

文件职责行数(约)
run_agent.pyAIAgent 类 — 核心对话循环、工具调度、会话持久化9000+
cli.pyHermesCLI 类 — 交互式 CLI、prompt_toolkit 集成3000+
model_tools.py工具编排层 — schema 收集、函数调用分发、async 桥接1500+
toolsets.py工具集定义与解析500+

Agent 内部 (agent/)

文件职责
prompt_builder.py系统提示词组装 — 10+ 个注入源
context_compressor.py上下文压缩 — 三区策略
context_engine.py上下文引擎 — 插件化架构
memory_manager.py记忆管理器 — 多 Provider 协调
memory_provider.py记忆 Provider 抽象基类
prompt_caching.pyAnthropic Prompt Caching
display.pyKawaiiSpinner、工具预览格式化
model_metadata.py模型上下文长度、token 估算
models_dev.pymodels.dev 注册表集成
skill_commands.py技能斜杠命令(CLI/Gateway 共享)
skill_utils.py技能工具函数
title_generator.py对话标题生成
trajectory.py轨迹保存辅助
anthropic_adapter.pyAnthropic 模型适配器
gemini_native_adapter.pyGemini REST API 适配器
gemini_cloudcode_adapter.pyGemini Cloud Code 适配器
bedrock_adapter.pyAWS Bedrock 适配器
codex_responses_adapter.pyCodex Responses API 适配器
transports/传输层抽象(统一响应格式)

工具系统 (tools/)

文件职责
registry.py中央工具注册中心(无依赖,所有工具文件导入)
terminal_tool.py终端执行 — 6 种后端环境
file_tools.py文件读写搜索补丁
file_operations.py文件操作辅助
web_tools.pyWeb 搜索/提取/爬取
browser_tool.pyBrowserbase 浏览器自动化
delegate_tool.py子 Agent 委托派遣
mcp_tool.pyMCP 客户端协议集成
mcp_oauth.pyMCP OAuth 认证
mcp_oauth_manager.pyMCP OAuth 令牌管理
code_execution_tool.pyexecute_code 沙箱
memory_tool.py记忆读写工具
todo_tool.pyTodo 列表工具
clarify_tool.py澄清问题工具
send_message_tool.py消息发送工具
skill_manager_tool.py技能管理工具
skills_tool.py技能查看/执行工具
skills_hub.pySkills Hub 集成
skills_sync.py技能同步
skills_guard.py技能安全守卫
cronjob_tools.py定时任务工具
tts_tool.py文本转语音
vision_tools.py视觉分析
image_generation_tool.py图片生成
approval.py危险命令检测
process_registry.py后台进程管理
environments/终端后端实现(local, docker, modal, ssh, daytona, singularity)

网关 (gateway/)

文件职责
run.py网关主循环 — 消息路由、斜杠命令、事件分发
session.pySessionStore — 会话持久化
config.py网关配置
delivery.py消息投递
hooks.py网关钩子
mirror.py跨平台消息镜像
pairing.pyDM 配对
platforms/base.py平台适配器基类
platforms/telegram.pyTelegram 适配器
platforms/discord.pyDiscord 适配器
platforms/slack.pySlack 适配器
platforms/whatsapp.pyWhatsApp 适配器
platforms/signal.pySignal 适配器
platforms/matrix.pyMatrix 适配器
platforms/dingtalk.py钉钉适配器
platforms/feishu.py飞书适配器
platforms/wecom.py企业微信适配器
platforms/weixin.py微信适配器
platforms/email.pyEmail 适配器
platforms/sms.pySMS 适配器

TUI (ui-tui/ + tui_gateway/)

文件职责
ui-tui/src/app.tsx主状态机和 UI
ui-tui/src/gatewayClient.tsJSON-RPC 客户端
ui-tui/src/entry.tsxTTY 检测 + render()
tui_gateway/server.pyPython RPC 服务
tui_gateway/entry.pystdio 入口
tui_gateway/slash_worker.py斜杠命令工作进程

CLI 子命令 (hermes_cli/)

文件职责
main.py入口 — 所有 hermes 子命令
config.pyDEFAULT_CONFIG、OPTIONAL_ENV_VARS、迁移
commands.pyCOMMAND_REGISTRY — 斜杠命令定义
callbacks.py终端回调(clarify、sudo、approval)
setup.py交互式设置向导
skin_engine.py皮肤/主题引擎
skills_config.pyhermes skills 子命令
tools_config.pyhermes tools 子命令
models.py模型目录、Provider 模型列表
model_switch.py/model 切换管线
auth.pyProvider 凭证解析

配置与基础设施

文件职责
hermes_state.pySessionDB — SQLite 会话存储
hermes_constants.py全局常量、get_hermes_home()
hermes_logging.py日志配置
hermes_time.py时间工具
cron/scheduler.pyCron 调度器
cron/jobs.pyCron 作业定义

按功能查找

"我想了解..."
├── 对话是怎么循环的      → run_agent.py → run_conversation()
├── 工具是怎么注册的      → tools/registry.py → register()
├── 工具是怎么被调用的    → model_tools.py → handle_function_call()
├── 系统提示词怎么组装的  → agent/prompt_builder.py → build_system_prompt()
├── 上下文是怎么压缩的    → agent/context_compressor.py → compress()
├── 记忆是怎么存储的      → agent/memory_manager.py + hermes_state.py
├── 技能是怎么加载的      → agent/skill_commands.py → scan skills/
├── 消息平台怎么对接的    → gateway/platforms/base.py → BasePlatformAdapter
├── 子Agent怎么创建的     → tools/delegate_tool.py → delegate_task()
├── 模型是怎么切换的      → hermes_cli/model_switch.py + agent/transports/
├── 配置怎么管理的        → hermes_cli/config.py → DEFAULT_CONFIG
├── 斜杠命令怎么注册的    → hermes_cli/commands.py → COMMAND_REGISTRY
└── 定时任务怎么执行的    → cron/scheduler.py → tick()

基于 MIT 许可发布