本索引按五层架构组织,覆盖 Hermes Agent 的核心文件和关键类/函数。行号基于 v0.8.0。
| 文件 | 类/函数 | 行 | 用途 |
hermes_cli/main.py | main() | — | CLI 命令入口,解析子命令并路由 |
cli.py | run_cli() | — | 交互式 TUI 主循环,prompt_toolkit 驱动 |
cli.py | _handle_slash_command() | — | Slash command 解析与分发 |
gateway/run.py | GatewayRunner | 461 | Gateway 主类,管理多平台连接 |
gateway/run.py | handle_message() | — | 接收平台消息并路由到 AIAgent |
batch_runner.py | BatchRunner | — | 批量轨迹生成,用于 RL 训练 |
cron/scheduler.py | CronScheduler | — | croniter 驱动的定时任务调度 |
| 文件 | 类/函数 | 行 | 用途 |
run_agent.py | AIAgent | 416 | 核心编排器,9431 行,全系统心脏 |
run_agent.py | AIAgent.__init__() | 433 | 50+ 参数,七阶段初始化决策链 |
run_agent.py | AIAgent.run_conversation() | — | 主循环:构建消息 → 调用模型 → 执行工具 → 循环 |
run_agent.py | IterationBudget | 168 | 线程安全的迭代预算,防止 agent 失控 |
run_agent.py | _SafeWriter | 111 | Broken pipe 保护,包装 stdout/stderr |
run_agent.py | _spawn_background_review() | 1718 | 后台线程启动 review agent,自动审查对话 |
run_agent.py | _build_system_prompt() | — | 拼装 identity + memory + skills + context |
model_tools.py | _discover_tools() | 132 | 导入所有工具模块,触发自注册 |
model_tools.py | get_tool_definitions() | 234 | 按 enabled/disabled toolset 过滤工具 schema |
model_tools.py | handle_function_call() | 459 | 路由工具调用到具体 handler |
model_tools.py | _run_async() | 81 | async→sync 桥接 |
| 文件 | 类/函数 | 行 | 用途 |
agent/prompt_builder.py | build_system_prompt() | — | 多块拼装 system prompt(983 行) |
agent/prompt_builder.py | build_skills_system_prompt() | 529 | 扫描技能目录,生成索引列表 |
agent/prompt_builder.py | SKILLS_GUIDANCE | 164 | 引导模型自主创建和改进技能的指令 |
agent/prompt_caching.py | — | — | Prompt cache 优化策略(72 行) |
agent/memory_manager.py | MemoryManager | — | 外部 memory provider 编排器;抽象目标包含 builtin provider(367 行) |
agent/memory_provider.py | MemoryProvider | — | 记忆后端 ABC,17 个方法(231 行) |
agent/builtin_memory_provider.py | BuiltinMemoryProvider | — | 内置记忆(MEMORY.md + USER.md)(114 行) |
agent/context_compressor.py | ContextCompressor | — | 上下文压缩,保护首尾消息(696 行) |
agent/model_metadata.py | ModelMetadata | — | 模型能力探测与缓存(1001 行) |
agent/usage_pricing.py | UsagePricing | — | Token 成本追踪(656 行) |
agent/retry_utils.py | retry_with_backoff() | — | 指数退避重试策略(57 行) |
agent/skill_utils.py | parse_frontmatter() | 52 | 解析技能文件的 YAML frontmatter |
agent/skill_utils.py | get_all_skills_dirs() | 226 | 返回技能搜索路径列表 |
agent/skill_utils.py | skill_matches_platform() | 92 | 平台条件过滤 |
agent/smart_model_routing.py | — | — | 智能模型路由选择(194 行) |
agent/anthropic_adapter.py | build_anthropic_client() | — | Anthropic API 客户端构造(1373 行) |
agent/credential_pool.py | CredentialPool | — | API key 池管理与轮换(1207 行) |
agent/context_references.py | — | — | 上下文引用追踪 |
agent/redact.py | — | — | 敏感信息脱敏 |
agent/trajectory.py | — | — | 对话轨迹格式化(56 行) |
agent/title_generator.py | — | — | 会话标题自动生成(125 行) |
| 文件 | 类/函数 | 行 | 用途 |
tools/registry.py | ToolRegistry | 48 | 工具注册表单例(335 行) |
tools/registry.py | ToolEntry | 24 | 工具元数据:名称、handler、toolset、schema |
toolsets.py | — | — | 工具分组定义与可用性控制(637 行) |
| 文件 | 类/函数 | 行 | 用途 |
tools/terminal_tool.py | execute_command() | — | 命令执行,6 种后端(1627 行) |
tools/file_tools.py | read_file() / write_file() | — | 文件读写操作(835 行) |
tools/browser_tool.py | browse() | — | 浏览器自动化(2178 行) |
tools/delegate_tool.py | delegate() | — | 子代理委托(978 行) |
tools/mcp_tool.py | — | — | MCP 外部能力接入(2186 行) |
tools/skills_tool.py | skill_view() | 787 | 技能检索(1376 行) |
tools/skill_manager_tool.py | skill_manage() | 569 | 技能创建/改进/删除(742 行) |
tools/code_execution_tool.py | execute_code() | — | Python/JS 代码执行(1347 行) |
tools/session_search_tool.py | session_search() | — | 跨会话 FTS5 搜索(504 行) |
tools/memory_tool.py | MemoryStore | — | 内置记忆存储(560 行) |
tools/process_registry.py | ProcessRegistry | — | 后台进程追踪(990 行) |
| 文件 | 类/函数 | 行 | 用途 |
hermes_state.py | SessionDB | 115 | SQLite 持久化:sessions + messages + FTS5(1304 行) |
hermes_state.py | WAL 并发安全 | 164 | BEGIN IMMEDIATE + 15 次 jitter retry |
| 文件 | 类/函数 | 行 | 用途 |
gateway/platforms/base.py | BasePlatformAdapter | 470 | 平台适配器 ABC(1696 行) |
gateway/session.py | SessionStore | 503 | 会话管理(1081 行) |
gateway/config.py | — | — | Gateway 配置解析(957 行) |
| 文件 | 平台 |
gateway/platforms/telegram.py | Telegram(webhook + polling) |
gateway/platforms/discord.py | Discord(多 guild、线程) |
gateway/platforms/slack.py | Slack(多 workspace、线程) |
gateway/platforms/whatsapp.py | WhatsApp(Twilio 桥接) |
gateway/platforms/signal.py | Signal(signal-cli 桥接) |
gateway/platforms/matrix.py | Matrix(E2E、spaces) |
gateway/platforms/email.py | Email(IMAP/SMTP) |
gateway/platforms/feishu.py | 飞书 |
gateway/platforms/wecom.py | 企业微信 |
gateway/platforms/dingtalk.py | 钉钉 |
gateway/platforms/homeassistant.py | Home Assistant IoT |
gateway/platforms/mattermost.py | Mattermost |
gateway/platforms/sms.py | SMS(Twilio) |
gateway/platforms/webhook.py | 自定义 Webhook |
gateway/platforms/api_server.py | REST API 端点 |
| 文件 | 类/函数 | 行 | 用途 |
acp_adapter/entry.py | — | — | ACP 入口模块(85 行) |
acp_adapter/server.py | — | — | ACP HTTP 服务器(726 行) |
acp_adapter/session.py | — | — | ACP 会话管理(475 行) |
acp_adapter/tools.py | — | — | 工具能力暴露(214 行) |
acp_adapter/events.py | — | — | SSE 事件流(175 行) |
acp_adapter/auth.py | — | — | 认证(24 行) |
acp_adapter/permissions.py | — | — | 权限控制(77 行) |
| 文件 | 用途 |
hermes_constants.py | 全局常量(105 行) |
hermes_logging.py | 日志配置 |
hermes_time.py | 时间工具函数 |
utils.py | 通用工具函数 |
mcp_serve.py | MCP 服务器模式(Hermes 作为 MCP server) |
batch_runner.py | 批量轨迹生成(1287 行) |
trajectory_compressor.py | 轨迹压缩(训练数据处理) |
rl_cli.py | RL 训练 CLI |