← 返回总览

Goose DEEP

💻 Coding Agents Rust ⭐ 5k+ | GitHub → | 深度分析于 2026-05-17
RustACPExtension-SystemSecurity-LayersAuto-CompactionStreamingMCP

🏗️ 核心架构

Goose 是 Block(原 Square)开发的 Rust 编码 Agent 框架,采用 crate 模块化架构。核心设计理念:Extension 驱动 + ACP 协议 + 多层安全

架构分层

与常见认知不同,Goose 不是 Go 语言,而是纯 Rust 实现,利用 tokio 异步运行时。

♻️ 主循环(Agent Loop)

核心循环在 agent.rsreply()reply_internal() 方法:

Goose Mode

支持多种模式:Chat(纯对话)、Plan(规划不执行)、Code(自动执行)。Mode 通过 PromptManager 注入 system prompt。

🔌 ACP 协议(核心差异化)

ACP (Agent Communication Protocol) 是 Goose 的核心差异化特性,定义在 crates/goose/src/acp/,提供 agent 间标准化通信。

ACP 使得 Goose agent 可以作为独立服务运行,被其他 agent 或客户端调用——这是走向 multi-agent 编排的基础。

🔒 安全系统(多层防御)

Goose 的安全系统是其架构亮点,包含四层检测

Prompt 注入检测

  • ML 分类器扫描用户输入
  • 检测 prompt injection 攻击
  • security/ 目录下实现

权限检查

  • permission_judge.rs — LLM 判断工具读写性质
  • 自动分类 read-only vs write 操作
  • Read-only 工具自动放行

Adversary 检测

  • 对抗性输入检测
  • Egress 检查(出站流量控制)
  • 防止数据泄露

Extension 安全

  • 动态加载/卸载 extension
  • Malware 检查
  • 限制:最多 5 extensions / 50 tools

🧩 Extension 系统

Goose 的 Extension 是动态加载的工具包,类似于 OpenClaw 的 Skill:

🧠 上下文管理与 Compaction

定义在 context_mgmt/mod.rs

📝 提示词工程

System Prompt 模板

定义在 crates/goose/src/prompts/system.md(43 行 Jinja 模板):

PromptManager

prompt_manager.rs 动态构建 system prompt:

🤖 Subagent 系统

subagent_handler.rs 实现子任务委派:

📂 关键文件

🔑 核心类型

Agent AgentEvent AgentConfig SessionConfig PromptManager SubagentRunParams TaskConfig PermissionJudge ExtensionConfig Conversation Provider (trait) AcpServer

💡 架构洞察

深度分析系统生成 · 基于 source code 阅读与架构还原 · 2026-05-17