源码索引:按问题跳转
行号以工作区提供的
hermes-agent-main快照为准;函数名比行号更适合跨版本定位。
我想知道一次对话怎么跑
| 问题 | 首选入口 |
|---|---|
| CLI 从哪里启动 | hermes_cli/main.py:1、run_agent.py:409 |
| 一次 Agent 运行在哪里结束 | run_agent.py:7153、agent/conversation_loop.py:1142 |
| 模型请求前做了什么 | agent/conversation_loop.py 中 _apply_context_engine_selection、message repair 和 API message 组装 |
| 模型响应如何转成下一轮 | agent/conversation_loop.py、agent/turn_context.py |
| 辅助模型在哪里调用 | agent/auxiliary_client.py |
我想知道工具如何被暴露与执行
| 问题 | 首选入口 |
|---|---|
| 工具如何发现 | tools/registry.py 的 discover_builtin_tools |
| 工具 schema/handler 放哪里 | tools/registry.py 的 ToolEntry、ToolRegistry |
| 工具如何并发执行 | agent/tool_executor.py 的 execute_tool_calls_concurrent |
| 工具如何串行执行 | agent/tool_executor.py 的 execute_tool_calls_sequential |
| 工具如何被 middleware 拦截 | agent/tool_executor.py 的 _run_agent_tool_execution_middleware |
| 工具失败如何回到模型 | agent/tool_executor.py 的 result/error 路径、model_tools.py |
| 终端实际在哪里运行 | tools/environments/base.py、tools/environments/local.py 等 |
| 破坏性操作如何回滚 | tools/checkpoint_manager.py、agent/file_safety.py |
我想知道上下文如何保持连续
| 问题 | 首选入口 |
|---|---|
| system prompt 如何组装 | agent/system_prompt.py:152、:549 |
| 项目上下文文件如何扫描 | agent/prompt_builder.py:82、:2017、:2114 |
| skills 如何进入 prompt | agent/prompt_builder.py:1584 |
| memory 如何预取 | agent/memory_manager.py:525 |
| memory 如何异步写入 | agent/memory_manager.py:597、:877 |
| 压缩何时触发 | agent/context_engine.py、agent/context_compressor.py:2377、:2487 |
| 压缩如何切点 | agent/context_compressor.py 的 _align_boundary_*、_find_*_message_idx |
| 摘要如何生成/降级 | agent/context_compressor.py:3151、:3417、:5882 |
我想知道会话和 Gateway 如何工作
| 问题 | 首选入口 |
|---|---|
| session 数据结构 | gateway/session.py:149、:314、:760 |
| session 持久化 | gateway/session.py:1192 |
| Gateway 主运行时 | gateway/run.py:5432 |
| Gateway 如何执行 Agent | gateway/run.py:23100、:23253 |
| 平台适配器契约 | gateway/platforms/base.py:2626 |
| 平台如何注册 | gateway/platform_registry.py:162 |
| 流式事件如何分发 | gateway/stream_events.py、gateway/stream_dispatch.py:40 |
| profile 如何路由 | gateway/profile_routing.py、docs/profile-routing.md |
| 同一 session 如何防并发 | gateway/turn_lease.py:115 |
我想知道长期任务如何调度
| 问题 | 首选入口 |
|---|---|
| cron 何时 tick | cron/scheduler.py |
| job 如何执行 | cron/jobs.py:2753 |
| job 如何 claim/heartbeat | cron/jobs.py 中 dispatch claim/heartbeat helpers |
| 结果如何送回平台 | cron/jobs.py 中 _resolve_delivery_targets、_deliver_result |
| 子 Agent 如何创建 | tools/delegate_tool.py:2778 |
| 子 Agent 生命周期 | agent/subagent_lifecycle.py |
| 多种终端后端 | tools/environments/ |
| relay 生命周期 | agent/relay_runtime.py:407 |
我想知道前端/协议如何接入
| 表面 | 首选入口 |
|---|---|
| CLI/TUI | hermes_cli/、cli.py、ui-tui/ |
| Web | web/、hermes_cli/web_routers/、web_models.py |
| Desktop | apps/desktop/ |
| ACP | acp_adapter/entry.py、session.py、server.py |
| API Server | gateway/platforms/api_server.py |
| 上游 Docusaurus | website/ |
测试导航
# 核心 loop / 上下文 / 工具
rg -n "conversation_loop|context_compressor|tool_executor" tests
# session / gateway / delivery
rg -n "session|turn_lease|delivery|stream" tests/gateway tests/agent
# 凭证和 provider
rg -n "credential|provider|oauth|failover|transport" tests/agent tests/cli
# 记忆、技能、委托
rg -n "memory|skill|delegate|subagent|curator" tests/agent tests/tools