goose 可复用会话配方(Recipe)完整指南:把当前会话一键沉淀为可共享、可调度的 Agent 配置

发布时间:2026/9/10 13:35:15
goose 可复用会话配方(Recipe)完整指南:把当前会话一键沉淀为可共享、可调度的 Agent 配置 goose 可复用会话配方Recipe完整指南把当前会话一键沉淀为可共享、可调度的 Agent 配置【免费下载链接】goosean open source, extensible AI agent that goes beyond code suggestions - install, execute, edit, and test with any LLM项目地址: https://gitcode.com/GitHub_Trending/goose3/goose导读当你花心思为 goose 打磨好一组工具组合、明确的目标与提示词并顺利完成某个任务后这套会话配置往往值得复用——无论是未来的自己还是团队里的其他人。本文基于 goose 官方文档 Reusable Recipes 展开系统讲解如何把当前 goose 会话封装成包含工具、目标与指令的可复用 Recipe配方支持一键启动、链接分享、定时调度与自动化输出。读完本文你将掌握在 goose Desktop 与 goose CLI 中创建、编辑、校验、运行、分享与调度 Recipe 的完整工作流并理解其底层 Recipe 文件结构与源码级实现原理。什么是可复用的会话 Recipe在 goose 中Recipe 是一种把Agent 会话初始配置打包成可复用文件YAML 或 JSON的机制。它捕获的内容包括AI 指令目标 / 用途建议活动可点击的示例提示词启用的扩展Extensions及其配置项目文件夹或文件上下文初始设置但不包含完整对话历史运行该 Recipe 时使用的模型与提供商可选重试逻辑与成功校验配置若已配置为了保障隐私与系统完整性goose 在生成 Recipe 时会主动排除以下内容全局与本地记忆MemoryAPI Key 与个人凭据系统级 goose 设置也就是说如果别人复用了你的 Recipe 且其依赖你的凭据或记忆那么对方需要自行补充这些要素。上述清单与源码中 Recipe 结构定义 一一对应version、title、description为必填instructions、prompt、extensions、settings、activities、parameters、response、sub_recipes、retry均为可选字段且源码通过RecipeBuilder::build()强制校验 instructions与prompt至少提供一个。创建 Recipe你可以从当前会话或模板两种途径创建 Recipe界面因 Desktop 与 CLI 而异。goose Desktop 中创建从当前会话创建停留在想要保存为 Recipe 的会话中点击底部工具栏的菜谱ChefHat按钮在弹出的对话框中按需检查并编辑 Recipe 字段标题、描述、指令、活动、参数等完成后可以选择点击Create Recipe将 Recipe 保存到 Recipe Library点击Create Run Recipe保存并立即在新会话中运行。从模板创建点击左上角侧边栏按钮PanelLeft打开侧边栏点击侧边栏中的Recipes点击Create Recipe在对话框中填写 Recipe 字段完成后可以复制 Recipe 链接分享给他人、点击Save Recipe保存到 Recipe Library、或点击Save Run Recipe立即运行。注意无法从已经由 Recipe 启动的会话中再次创建 Recipe但你可以查看或编辑该 Recipe。goose CLI 中创建Recipe 文件可以是 JSON.json或 YAML.yaml。在某个会话中运行如下命令即可在当前目录生成recipe.yaml/recipe如需指定不同文件名可传入参数/recipe my-custom-recipe.yamlrecipe 文件结构示例# Required fields version: 1.0.0 title: $title description: $description instructions: $instructions # Define the models behavior # Optional fields prompt: $prompt # Initial message to start with extensions: # Tools the recipe needs - $extensions activities: # Example prompts to display in the Desktop app - $activities settings: # Additional settings goose_provider: $provider # Provider to use for this recipe goose_model: $model # Specific model to use for this recipe temperature: $temperature # Model temperature setting for this recipe (0.0 to 1.0) retry: # Automated retry logic with success validation max_retries: $max_retries # Maximum number of retry attempts checks: # Success validation checks - type: shell command: $validation_command on_failure: $cleanup_command # Optional cleanup command on failure所有字段的详细说明与配置示例见 Recipe Reference Guide。注意同样地在已由 Recipe 启动的会话中/recipe命令不会生效。建议创建后应使用goose recipe validate校验 Recipe 格式与完整性见下文校验 Recipe。从源码层面看/recipe斜杠命令会借助 LLM 依据内置提示词模板生成 recipe 文件。默认模板位于 crates/goose/src/prompts/recipe.md它要求基于当前对话生成 5-10 个词的标题、1-2 句描述、1-2 段可复用的泛化指令以及 3-5 个示例活动并以title、description、instructions、activities四个键的 JSON 返回。这意味着指令被刻意泛化、高层化从而能在相似任务间复现。提示你可以通过编辑recipe.md这个提示词模板自定义 goose 生成 Recipe 的方式。可选参数Parameters让 Recipe 变得可定制你可以在 Recipe 任意部分instructions、prompt、activities 等加入参数占位符运行/使用时由用户填写。使用步骤在 Recipe 内容中使用{{ variable_name }}语法添加模板变量在 YAML 文件的parameters段中逐一声明每个参数。带参数的 Recipe 示例version: 1.0.0 title: {{ project_name }} Code Review # Wrap the value in quotes if it starts with template syntax to avoid YAML parsing errors description: Automated code review for {{ project_name }} with {{ language }} focus instructions: You are a code reviewer specialized in {{ language }} development. prompt: | Apply the following standards: - Complexity threshold: {{ complexity_threshold }} - Required test coverage: {{ test_coverage }}% - Style guide: {{ style_guide }} activities: - Review {{ language }} code for complexity - Check test coverage against {{ test_coverage }}% requirement - Verify {{ style_guide }} compliance settings: goose_provider: anthropic goose_model: claude-3-7-sonnet-latest temperature: 0.7 parameters: - key: project_name input_type: string requirement: required # could be required, optional or user_prompt description: name of the project - key: language input_type: string requirement: required description: language of the code - key: complexity_threshold input_type: number requirement: optional default: 20 # default is required for optional parameters description: a threshold that defines the maximum allowed complexity - key: test_coverage input_type: number requirement: optional default: 80 description: the minimum test coverage threshold in percentage - key: style_guide input_type: string description: style guide name requirement: user_prompt # If style_guide param value is not specified in the command, user will be prompted to provide a value, even in non-interactive mode关于参数化 Recipe 的更多字段说明见 Recipe Reference Guide。在源码中参数类型与要求被建模为枚举RecipeParameterInputTypestring、number、boolean、date、file、select与RecipeParameterRequirementrequired、optional、user_prompt见 crates/goose/src/recipe/mod.rs。编辑 Recipegoose Desktop点击左上角侧边栏按钮打开侧边栏点击Recipes找到目标 Recipe 并点击编辑按钮SquarePen在对话框中编辑标题、描述、指令、活动等字段完成后可以复制分享链接、点击Save Recipe保存、或点击Save Run Recipe保存并立即运行。提示在会话中使用某个 Recipe 时也能打开编辑对话框——发送第一条消息后底部会出现菜谱按钮点击即可编辑当前使用的 Recipe。goose CLIRecipe 文件生成后直接用你习惯的文本编辑器打开并修改任意字段值即可。手动编辑后建议运行 校验命令 确认没有引入格式问题——这正是goose recipe validate的核心用途之一见 CLI 命令实现。使用 Recipegoose Desktop可通过直接链接、手动输入 URL 或 Recipe Library 打开直接链接点击别人分享给你的 Recipe 链接即可手动输入 URL将 Recipe 链接粘贴到浏览器地址栏回车后点击Open Goose.app提示Recipe Library打开侧边栏 →Recipes→ 在库中找到目标 Recipe → 点击Use斜杠命令在任意 goose 聊天会话中输入已配置的自定义斜杠命令。首次运行某个 Recipe 时goose 会弹出警告对话框展示该 Recipe 的标题、描述与指令供你审阅。若信任其内容点击Trust and Execute继续同一 Recipe 在未发生变化前不会再次提示。若 Recipe 包含参数则会在Recipe Parameters对话框中填写参数值后点击Start Recipe。其中必需参数以红色星号*标记可选参数展示可修改的默认值。随后 Recipe 会自动提交并开始执行若 Recipe 包含 prompt它会被作为第一条消息发送否则你可以点击活动气泡activity bubble或手动输入提示词启动。隐私与隔离每位使用者都会获得各自独立的私有会话不同用户之间不共享任何数据你的会话不会影响 Recipe 创建者的原始会话。goose CLI使用 CLI 涉及三件事配置 Recipe 位置、运行 Recipe、调度 Recipe。配置 Recipe 位置Recipe 可以存放在本地设备或GitHub 仓库中。可通过goose configure命令或配置文件两种方式配置。仓库结构约定每个 Recipe 应放在独立目录中目录名与你在命令中使用的 Recipe 名称保持一致Recipe 文件名为recipe.yaml或recipe.json。方式一goose configuregoose configure按提示依次选择┌ goose-configure │ ◆ What would you like to configure? │ ○ Configure Providers │ ○ Add Extension │ ○ Toggle Extensions │ ○ Remove Extension │ ● goose settings (Set the goose mode, Tool Output, Tool Permissions, Experiment, goose recipe github repo and more) │ ◇ What would you like to configure? │ goose settings │ ◆ What setting would you like to configure? │ ○ goose mode │ ○ Tool Permission │ ○ Tool Output │ ○ Toggle Experiment │ ● goose recipe github repo (goose will pull recipes from this repo if not found locally.) └ ┌ goose-configure │ ◇ What would you like to configure? │ goose settings │ ◇ What setting would you like to configure? │ goose recipe github repo │ ◆ Enter your goose recipe GitHub repo (owner/repo): eg: my_org/goose-recipes │ squareup/goose-recipes (default) └方式二配置文件在配置文件中加入GOOSE_RECIPE_GITHUB_REPO: owner/repo运行 Recipe本地 Recipe# 使用当前目录或 GOOSE_RECIPE_PATH 指向的目录下的 recipe 文件 goose run --recipe recipe.yaml # 使用完整路径 goose run --recipe ./recipes/my-recipe.yaml交互模式会逐项提示填写必填参数goose run --recipe recipe.yaml --interactive交互模式会提示必填值◆ Enter value for required parameter language: │ Python │ ◆ Enter value for required parameter style_guide: │ PEP8带参数运行goose run --recipe recipe.yaml --params languagePythonrun命令的更多用法与选项见 goose-cli-commands。此外Recipe 也可注册为自定义斜杠命令在任意聊天会话中触发。GitHub 仓库 Recipe配置好 GitHub 仓库后可按 Recipe 名称对应其所在目录名直接运行goose run --recipe recipe-name例如仓库结构如下my-repo/ ├── code-review/ │ └── recipe.yaml └── setup-project/ └── recipe.yaml则运行 code review Recipe 的命令为goose run --recipe code-review带参数提示的交互模式goose run --recipe code-review --interactive◆ Enter value for required parameter project_name: │ MyProject │ ◆ Enter value for required parameter language: │ Python其余--params用法与本地 Recipe 一致。值得补充的是CLI 对 GitHub 仓库的依赖需要 GitHub CLIgh已安装并完成认证这一限制的完整说明见 recipe-reference 中 Recipe Location 一节。校验 RecipeRecipe 校验目前仅通过 CLI 提供Desktop 端会提示前往 CLI。goose recipe validate会检查所有必填字段是否存在参数格式是否正确引用的扩展是否存在且有效YAML/JSON 语法是否正确。goose recipe validate recipe.yaml提示若要校验刚创建的 Recipe需要先退出当前会话再运行validate子命令。校验的典型使用场景排查 Recipe 运行不符合预期的问题手动编辑 Recipe 后确认没有引入错误在 CI/CD 流水线中做自动化测试。源码级依据校验逻辑实现在 crates/goose/src/recipe/validate_recipe.rs主要规则包括validate_prompt_or_instructionsinstructions与prompt至少存在其一、validate_json_schemaresponse.json_schema必须是合法 JSON Schema、validate_parameters_in_template模板变量必须都有对应参数定义且已定义参数必须被使用、不允许悬空参数、以及validate_optional_parameters可选参数必须有默认值file类型参数禁止携带默认值以防误导入敏感文件。这与 Recipe 反序列化路径crates/goose/src/recipe/mod.rs#L317-L341在同一套加载逻辑中强制执行同时也支撑了斜杠命令/Recipe 元数据的解析。分享 Recipe你可以通过Recipe 链接或Recipe 文件两种方式分享给其他 goose 用户。隐私与隔离每个接收者在运行时都会获得独立私有会话用户间不共享数据你的原始会话与 Recipe 不受影响。通过 Recipe 链接分享面向 Desktop 用户Desktop打开侧边栏 →Recipes→ 找到目标 Recipe 并点击链接按钮Link复制链接。CLI从 recipe 文件生成 deeplinkgoose recipe deeplink FILE也可通过参数预填Recipe Parameters对话框goose recipe deeplink FILE --param key1value1 --param key2value2他人点击该链接后会用你的 Recipe 配置打开 goose Desktop也可以利用该链接导入 Recipe 供后续使用。deeplink 的 CLI 实现在 crates/goose-cli/src/cli.rs#L746-L762。通过 Recipe 文件分享面向 Desktop 与 CLI 用户Desktop打开侧边栏 →Recipes→ 点击分享按钮Share2后选择Export to File将 Recipe 下载为.yaml文件Copy YAML将 Recipe 的 YAML 内容复制到剪贴板。其他 Desktop 用户可将该文件导入到自己的 Recipe Library。CLI导出/复制内容仅能在 Desktop 端完成但你可以直接复制本地 recipe 文件。CLI 用户可通过goose run --recipe FILE运行收到的 recipe 文件或用goose recipe open FILE直接在 goose Desktop 中打开对应 CLI 实现见 crates/goose-cli/src/cli.rs#L764-L778。调度 Recipe定时运行goose Desktop通过调度实现 Recipe 自动化。创建调度时可配置Name调度的描述性名称Source要运行的 RecipeExecution modeRecipe 在后台运行无窗口、结果保存还是前台运行goose Desktop 运行时打开窗口否则退化为后台Frequency and time运行频率与时间例如每 20 分钟、每周五上午 10 点goose 会将其转换为 cron 表达式。从 Recipe Library 创建调度打开侧边栏 →Recipes找到目标 Recipe 并点击时钟按钮Clock点击Create Schedule在对话框中配置调度Source已自动填入该 Recipe 链接点击Create Schedule。从 Scheduler 视图创建调度打开侧边栏 →Scheduler点击Create Schedule在对话框中选择.yaml/.yml文件或提供 Recipe 链接点击Create Schedule。管理已调度的 Recipe所有调度任务列于Scheduler页面点击某个调度可查看详情、最近运行时间并执行操作Run Schedule Now手动立即触发Edit Schedule修改频率Pause Schedule暂停自动运行。在Schedule Details底部可查看该调度创建的所有会话并可打开或恢复每个会话。goose CLI使用 cron 表达式调度 Recipe 定时运行# 新增一个每天上午 9 点运行的调度 goose schedule add --schedule-id daily-report --cron 0 0 9 * * * --recipe-source ./recipes/daily-report.yaml可以使用 5 位、6 位或 7 位 cron 表达式格式遵循秒 分 时 日 月 周 年以获得完整的调度精度。schedule命令的更多示例与选项见 goose-cli-commands。Recipe 的核心组成一个 Recipe 需要这些核心组件Instructions指令定义 Agent 的行为与能力边界。它相当于 Agent 的使命宣言让 Agent 准备好处理任何相关任务。若未提供 prompt则为必填。Prompt提示词可选自动开启对话。没有 prompt 时 Agent 会等待用户输入适合具体、即刻执行的任务。若未提供 instructions则为必填。Activities活动以可点击气泡形式出现的示例任务帮助用户快速理解该 Recipe 能做什么、并一键开始。这三者与 Recipe 渲染模型一致解析后instructions与prompt会拼接成会话的起始指令可参见 recipe_slash_command.rs 中resolve_command对两者的拼接逻辑。高级特性自动化重试逻辑Recipe 可以内嵌重试逻辑在未达到成功标准时自动重试直到成功或达到最大次数。特别适合需要确保成功完成的自动化工作流可能需要多次尝试的开发任务如反复运行测试需要校验与清理的系统操作。基础重试配置retry: max_retries: 3 checks: - type: shell command: test -f output.txt # Check if output file exists on_failure: rm -f temp_files* # Cleanup on failure工作流程Recipe 按指令正常执行执行完毕后由成功校验checks验证结果若校验失败且仍有重试次数可选地执行清理命令on_failureAgent 状态重置为初始条件重新开始执行 Recipe循环持续到成功或达到max_retries。完整的 retry 配置选项见 Recipe Reference Guide。在源码中重试配置对应RetryConfig类型并支持通过GOOSE_RECIPE_RETRY_TIMEOUT_SECONDS与GOOSE_RECIPE_ON_FAILURE_TIMEOUT_SECONDS两个环境变量做全局超时兜底Recipe 内的配置优先。面向自动化的结构化输出Recipe 可以强制输出结构化的 JSON 结果response 配置非常适合需要稳定解析 Agent 响应的自动化流水线。其收益包括可靠解析对脚本、自动化与 CI/CD 流水线而言格式始终一致内建校验确保输出与你的要求完全匹配易于提取最终输出以单行形式呈现便于直接解析。典型使用场景开发工作流代码分析报告、含通过/失败计数的测试结果、带部署就绪状态的构建状态数据处理带计数与校验状态的统计结果、带结构化发现的内容分析文档生成供进一步处理的一致元数据与结构化项目报告。结构化输出配置示例response: json_schema: type: object properties: build_status: type: string enum: [success, failed, warning] description: Overall build result tests_passed: type: number description: Number of tests that passed tests_failed: type: number description: Number of tests that failed artifacts: type: array items: type: string description: Generated build artifacts deployment_ready: type: boolean description: Whether the build is ready for deployment required: - build_status - tests_passed - tests_failed - deployment_ready工作机制Recipe 按指令正常执行goose 调用final_output工具传入符合你 schema 的 JSON输出按 JSON Schema 校验校验失败时 goose 会收到错误详情并修正输出最终通过校验的 JSON 会作为输出的最后一行便于提取。自动化提取示例# Run recipe and extract JSON output goose run --recipe analysis.yaml --params project_path./src output.log RESULT$(tail -n 1 output.log) echo Analysis Status: $(echo $RESULT | jq -r .build_status) echo Issues Found: $(echo $RESULT | jq -r .tests_failed)提示结构化输出在 CLI 与 Desktop 中运行 Recipe 时均受支持但json_schema配置目前需要手动在 recipe 文件中创建与编辑。从源码看response字段被建模为Response { json_schema: Optionserde_json::Value }见 crates/goose/src/recipe/mod.rs#L112-L116并在加载与校验阶段通过validate_json_schema进行合法性检查。隐私保护Recipe 捕获了什么、排除了什么复用一个会话 Recipe 前务必清楚其内容边界前面已详述包含清单与排除清单。核心结论是Recipe不携带你的记忆、凭据与系统设置因此依赖这些要素的 Recipe 在别人或未来的你手上运行时需要另行提供对应凭据或记忆上下文。这是 goose 刻意设计的隐私与安全边界也让 Recipe 可以在陌生人之间安全流转——配合首次运行时的Trust and Execute审阅对话框形成了一道完整的信任防线。更多资源关于 Recipe 的创建、编辑、存储与导入的完整生态可继续阅读 Recipes 总览、Recipe Reference Guide字段级参考、Storing Recipes存储与导入 与 Subrecipes子配方编排同时可在仓库中对照学习其核心实现Recipe 数据模型见 crates/goose/src/recipe/mod.rs校验规则见 crates/goose/src/recipe/validate_recipe.rs会话内生成逻辑的提示词模板见 crates/goose/src/prompts/recipe.mdRecipe 斜杠命令解析见 crates/goose/src/slash_commands/recipe_slash_command.rs。【免费下载链接】goosean open source, extensible AI agent that goes beyond code suggestions - install, execute, edit, and test with any LLM项目地址: https://gitcode.com/GitHub_Trending/goose3/goose创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询