nanobot 源码与测试索引

本表按“学习问题”组织,不按目录机械罗列。路径相对于 example/nanobot/code-EN。

入口与核心 Turn

问题源码锚点优先测试对应讲解
CLI 如何启动一次聊天?nanobot/cli/commands.py::agenttests/cli/test_commands.py五个入口与运行边界
Gateway 如何组装常驻服务?nanobot/cli/gateway.py、nanobot/gateway/runtime.pytests/gateway/test_runtime.py、tests/cli/test_gateway_commands.pyChannel 与 Gateway
HTTP API 如何进入 Agent?nanobot/api/server.py::create_app、handle_chat_completionstests/test_openai_api.py、tests/test_api_stream.pyHTTP API 与 Python SDK
Python SDK 如何建 runtime?nanobot/nanobot.py::Nanobot、nanobot/sdk/runtime.pytests/test_nanobot_facade.py同上
WebSocket 如何接收/发送?nanobot/channels/websocket.py::WebSocketChanneltests/channels/test_websocket_integration.pyWebSocket 与 WebUI
一次 Turn 的状态怎样推进?nanobot/agent/loop.py::AgentLoop._process_messagetests/agent/test_loop_runner_integration.py、test_loop_save_turn.pyAgentLoop 状态机
模型—工具循环如何结束?nanobot/agent/runner.py::AgentRunner.runtests/agent/test_runner_core.py、test_runner_tool_execution.pyAgentRunner 的模型—工具循环
system prompt 与历史怎样组成?nanobot/agent/context.py::ContextBuildertests/agent/test_context_builder.py、test_context_prompt_cache.pyContextBuilder 与模型上下文

消息、事件与状态

问题源码锚点优先测试对应讲解
入站/出站消息有哪些字段?nanobot/bus/events.pytests/bus/、Channel tests消息、SessionKey 与入口
消息如何排队?nanobot/bus/queue.py::MessageBus相邻 AgentLoop/Channel integration tests同上
Runtime Event 有哪些精确类型?nanobot/bus/runtime_events.pytests/bus/test_runtime_events.py保存、响应与 RuntimeEvent
Session 如何保存、加载、锁定?nanobot/session/manager.py::SessionManagertests/agent/test_session_atomic.py、test_session_manager_history.pySession 文件与回放边界
session key 如何规范化?nanobot/session/keys.pytests/agent/test_unified_session.py消息、SessionKey 与入口
历史何时压缩?nanobot/agent/memory.py::Consolidator、nanobot/agent/autocompact.pytests/agent/test_auto_compact.py、test_consolidator.pyCompaction、Memory 与 Dream
持续目标怎样继续?nanobot/session/goal_state.py、turn_continuation.pytests/agent/test_runner_goal_continue.py、test_loop_goal_wall_timeout.pyGoal 与 Continuation
Subagent 怎样创建和清理?nanobot/agent/subagent.py、agent/tools/spawn.pytests/agent/test_subagent_lifecycle.pySubagent 生命周期

Provider、Tool 与扩展

问题源码锚点优先测试对应讲解
Provider 的统一契约是什么?nanobot/providers/base.py::LLMProvidertests/providers/Provider 解析与 Fallback
Provider 如何选择和实例化?nanobot/providers/registry.py、factory.pytests/cli/test_commands.py、tests/agent/test_runtime_refresh.py同上
fallback 如何串联?nanobot/providers/fallback_provider.pytests/agent/test_runner_fallback.py同上
Tool 契约是什么?nanobot/agent/tools/base.py::Tooltests/tools/test_tool_validation.py新增 Tool
Tool 如何注册、校验、执行?nanobot/agent/tools/registry.py::ToolRegistrytests/agent/test_runner_tool_execution.pyTool 注册、校验与执行
外部 Tool 插件如何发现?nanobot/agent/tools/loader.pytests/agent/test_tool_loader_entrypoints.py、test_tool_loader_scopes.py新增 Tool
Skill 如何发现和筛选?nanobot/agent/skills.py::SkillsLoadertests/agent/test_skills_loader.py新增 Skill
MCP 如何连接和包装工具?nanobot/agent/tools/mcp.pytests/agent/test_mcp_connection.py、test_mcp_transient_retry.py接入 MCP
Channel 如何发现?nanobot/channels/registry.pytests/channels/test_channel_plugins.py新增 Channel
Channel 如何统一发送?nanobot/channels/base.py、manager.pytests/channels/test_base_channel.py、test_channel_manager_delta_coalescing.pyChannel 与 Gateway

自动化、工程与安全

问题源码锚点优先测试对应讲解
Cron 如何持久化和触发?nanobot/cron/service.py、types.pytests/cron/Cron 与 Heartbeat
Heartbeat 如何接到 Cron?nanobot/cli/commands.py 中的 heartbeat job 组装、nanobot/cron/service.pytests/agent/test_loop_cron_timezone.py、相邻 Cron tests同上
取消后怎样保护上下文?nanobot/agent/runner.py::_emit_checkpoint、nanobot/agent/loop.py::_restore_runtime_checkpointtests/agent/test_task_cancel.py、test_stop_preserves_context.pyasyncio 并发、取消与资源清理
workspace 路径怎样限制?nanobot/security/workspace_policy.py、workspace_access.pytests/agent/test_workspace_scope.py、tests/security/Workspace、Shell 与 SSRF 安全边界
SSRF 怎样判断?nanobot/security/network.pytests/security/ 与 web tool tests同上
WebUI 怎样进入 Python 包?pyproject.toml、webui/、构建脚本packaging/build tests打包、WebUI 构建与跨平台

先读测试名,再读测试体

测试名通常直接表达维护者承诺的行为。先看 fixture、触发动作和断言,再回到实现,能显著减少从函数名猜设计的情况。

索引边界

  • 这里不列出每个 Provider、Channel 或配置字段;完整清单见官方文档;
  • 测试文件若随源码重组,应以当前 tests/ 目录和 rg --files tests 为准;
  • “相邻测试”表示行为可能跨多个测试层,不能只依赖一个文件证明全部边界。

返回:速查参考