Interfaces

接口层把外部输入转成内部服务调用。它包含 Web API/静态文件、CLI、Gateway、渠道适配和 MCP server。核心原则是:入口负责协议转换,业务决策交给 Services 和 Engine。

大模块流程

外部请求HTTP / CLI / MCP / Channel
->
Schema/参数整理session、model、thinking、routing
->
调用 ServicesAgentService / CronService / SkillHubService
->
返回响应chat result、task state、skill artifacts、cron history

小模块拆分

web

Web 应用是主要产品入口,集中提供 chat、task acceptance、cron、session、skill draft/review/publish 等 API,并服务前端静态资源。

请求进入 FastAPI route,解析 body/query/path。
根据功能调用 AgentService、CronService、SkillHubService 或 SessionProcessProjector。
把内部 dataclass/model 转成 JSON payload,并在必要时补充 session/run/task 元数据。

关键文件:beaver/interfaces/web/app.pybeaver/interfaces/web/files.py

cli

CLI 入口用于本地命令行运行 Beaver。它复用同一套 AgentService/AgentLoop,因此 CLI 不是第二套 runtime,只是更薄的协议层。

读取命令行参数。
构造 session/source/model 参数。
调用 agent run,打印最终输出。

gateway 与 channels

Gateway 和 channels 是多渠道接入边界,把渠道消息抽象为统一的内部消息。当前代码中通道能力较轻,主要服务未来接入不同聊天来源。

渠道事件进入 adapter。
规范化 user_id、channel、chat_id、content。
转给 AgentService,最终仍落入同一个 session/run 体系。

mcp_servers

对外暴露 MCP server 能力,让 Beaver 的部分能力可以被其他 MCP client 调用;这和 Beaver 作为 MCP client 使用外部工具是两条边界。

MCP client 调用 server tool。
接口层解析 MCP 参数。
转调内部服务或数据访问层。

修改影响点

入口层新增字段时,要同步核对 Services 层是否需要进入 prompt:例如 thinking_enabled 会影响 router、skill assembler、provider chat kwargs;execution_context 会进入 ContextBuilder 的 system prompt。