架构
Anyy 是 local-first、resident 的多 surface 个人助理。产品 runtime 拥有 sessions、memory、 tools、skills、providers、channels、cron、background jobs、approvals、audit 和 delivery surfaces。
内层 agent loop 要保持很小。大多数产品行为在它外面,而不是在它里面。
Product Runtime
Resident runtime 由 internal/gateway、internal/runtime、internal/state、internal/llm、
internal/tools、internal/channels、internal/mcp 和 internal/skills 等包组装。
它在调用 loop 前解析 active profile、config、role、provider/model、toolsets、skills、context、 approvals、audit sinks 和 repositories。
Agent Loop Kernel
internal/agent 拥有 Run、Continue、provider streaming、tool-call iteration、tool-result
messages、budget warnings、cancellation 和 event emission。
它消费接口:LLMProvider 和 AgentTool。它不能 import gateway、RPC、state、config、channels、
skills、approvals、audit、cron、TUI 或 provider implementations。
Gateway Boundary
internal/gateway.Service 是 resident session owner。它创建 sessions、排队 turns、构建 prompt
context、选择 tools、运行 agent loop、持久化 records、发布 events,并处理 subagents/background jobs。
Gateway code 拥有 orchestration。Channel adapters、dashboard pages、TUI clients 和一次性 CLI commands 应调用 gateway/RPC contracts,而不是拥有 agent-loop behavior。
RPC Boundary
internal/rpc 提供 JSON request/response dispatch 和 event subscription。共享 method names 与
payload shapes 位于 internal/protocol。
添加 public method 意味着更新 protocol constants、注册 gateway 或 runtime handler、添加 tests, 并在 reference 中记录该 method。
State Boundary
internal/state 是 SQLite repository layer。它存储 sessions、turns、messages、tool calls/results、
roles、memory metadata、cron、channels、approvals、ChangePlans、audit、artifacts 和 background jobs。
Raw session detail 也可能镜像到 raw/YYYY/MM/DD/。当 payload 太大不适合 inline storage 时,blob bytes
会放在 SQLite 外部。
Channel Boundary
Channels 是 internal/channels 下的 adapters。它们把平台事件转换成 protocol.ChannelInbound,
并把 gateway output 转成平台消息。
Adapters 不拥有 model selection、prompt assembly、memory、tool policy 或 session persistence。它们 把 inbound work 提交给 gateway,并从 gateway 接收 outbound delivery。