预设与运行时 Bundle
同一个 harness,换一个 preset 就是另一个 Agent——自己的提示词、自己的工具集、互不泄漏的监听器。
运行时整体形状则由 bundle 决定。对应实现:src/Longe.Presets/ 与 src/Longe.Bundles/。
第一批职业
职业是 Longe 自有的 Agent 预设产品名。经典界面使用正规名称,远征外壳使用游戏名;两种界面读取同一份职业、实际执行与插件清单事实。
| id | 经典 | 远征 | 定位 |
|---|---|---|---|
| standard | 编码 | 行者 | 文件读写、持久终端、网页检索、Skills、子代理与工作流 |
| research | 调研 | 斥候 | 只调查、不改动:网页搜索与抓取、文件读取与检索、会话检索,结论注明出处 |
| cordis | 插件开发 | 工匠 | 编写、构建、安装并验证 Longe 插件;直接或代码调用工具 |
standard 是默认职业。三者都排除 echo;编码排除全部七个动态 cordis_* 工具,插件工程工具只在插件开发职业挂载。调研挂载网页、文件、文件检索与时间上下文,排除写入、终端、代码执行、插件管理、调度写操作与演化写操作。职业描述的是第一方能力组合,不是第三方工具的安全沙箱。
meeting(会议主持)是会议模式专有预设,由 dev.longe.bundle.meeting 组合包提供。它只读研读材料,通过结构化议程与投票记录用户决议,并把产出写入会议目录。该预设声明 hidden: true,不进入经典与远征外壳的普通预设或职业候选列表,但仍可通过 agentPreset: "meeting" 或 URL 参数显式选择——hidden 只是显示标记,不是访问控制。
frontier 是 Frontier Agent 预设,由可选组合包 dev.longe.bundle.frontier 提供(启用后方出现在候选)。它以单 Agent 基线为底:文件/终端/网页/调度/子代理/工作流工具,叠加 root 级 frontier-execution-policy 行(execution-policy,#948 回合与预算闸——preset generation 的 bounded context 放不下 raw 全局事件监听器,只能以 patch 行挂载;配 enforcedPresets: [frontier],约束只落在 frontier preset 会话及其 live 祖先链命中的子会话,非 frontier 会话等同未装配)、artifacts 工件区与 manifest,以及 Frontier 专属团队 job 工具(Team 服务由 base 的 agent-team 行提供,Team 即 root 子代理树,v0.47 #1133)(Lead-only 的 team_assign_job/team_collect_reports、成员可写的 team_submit_report)。artifacts 行装配后结构化文件工具(write/edit/str_replace_editor/present)被接入 IPathZoneAuthority 判定:inputs/ 只读、outputs/ 写与 present 需要会话持有 publisher grant(由 PublisherRoles 声明的 preset 身份获取;subagent/team worker 的 SubagentOrigin 非空时永远拿不到 grant——worker 受 zone 约束但无发布权)、其余根内路径(普通项目文件)算 workspace zone 可读写;约束只对 EnforcedPresets 声明的 preset-id 生效(frontier bundle 配 [frontier])——会话自身或沿 SubagentOrigin 父链上任一 live 祖先命中即受约束(父链不可解析按受约束 fail closed),其他会话行为等同未装配。shell 工具如实标注「不受 path-zone 约束」,需要约束时走 OS 级 sandbox_permissions。判定基于 realpath 身份,symlink/大小写变体不能绕开 zone。人工接管经 takeover/takeover-fence 行:暂停只能经受控用户入口发起(/takeover 斜杠命令:pause/resume/cancel/view/proposals/approve/reject;resume 会汇总暂停期间的人工与外部变化)。排空覆盖本 session 与 live 子会话中经 fence 准入的在途写者;外部编辑器、shell 后台进程等不经账本的写者不视为已静止,pause/view 输出如实标注覆盖范围。写工具在暂停期被围篱拒绝——模型不能自我批准;浏览器经典接管卡与远征扎营面板的按钮同样只走 /takeover 命令通道。设计参考自上游 Frontier(Apache-2.0),仅作设计参照,不复用其实现。#952 的 context recipe 刻意不进 bundle:替换 builtin compaction 是 root 级全局动作(对启用 bundle 的 profile 全部会话生效),且 assembly.contextWindowTokens 必须按实际模型定值——属运维决策,与 spill-policy 的 scopeIsolation 同处理;启用方法(手工 patch 两行:{ id: compaction, disabled: true } + frontier-recipes 挂 dev.longe.plugin.compaction-recipes.recipes 携带 retentionMode: tokenBudget + assembly 预算)见 extensions/longe-bundle-frontier/README.md;manifest replaces 不能完成替换(name-only swap 不携带 config,base 行 config 无法绑定 RecipeOptions)。spill-policy 的 scopeIsolation 同样刻意不启用——根级行对所有会话生效,无 per-preset 闸,启用需运维手工追加 config: { maxInlineTokens: 12500, scopeIsolation: true };llm-failover(llm-failover 行)不在 bundle 的 requires,属宿主级路由配置,由运维按 LLM 后端决定是否安装。
frontier 支持与限制
- 已验证平台:Windows(本机
Longe.Bundles.Tests+takeover-pause-flow.test.mjs,CIwindows-latestshard)、Linux(CIubuntu-latestshard);macOS 未在 CI 覆盖,未验证。 - 所需配置:启用
dev.longe.bundle.frontierbundle 即可——frontier.patch.yml里workspaceRoot: ${LONGE_WORKSPACE:-.}与enforcedPresets: [frontier]自含,无需额外环境变量;execution-policy的maxTurns: 128等参数可按需在 profile patch 覆盖。 fs-tools在 web 组合的可用性:web.yaml:11的replaceName: sandboxed-subprocess把 basesubprocess-local行换成sandboxed-subprocess——发行 web 挂SandboxedSubprocessPlugin,在src/Longe.Sandbox.Local/SandboxPlugins.cs:42Provide<IFileSystem>写共享 registry。fs-tools的Inject: [IFileSystem]满足,agentwrite/edit可用。takeover-fence在写成功后记AgentAttributedjournal 条目(before/after version + content),暂停基线覆盖 agent 写过的文件,resume 按 exact version 报告「modified externally during pause」;IChangeJournal.RevertAsync的受控 revert 对这些条目可用(exact-version 匹配才还原,不覆盖用户后续修改)。- 未交付增强:上下文配方(compaction-recipes #952)不进 bundle 默认安装(须运维手工 patch,见上段);
spill-policy scopeIsolation(全局影响,须手工开启);llm-failover(宿主级 LLM 路由,不属于 bundle 依赖)。
ptc 与 minimal 不再发行、不再出现在候选列表;仅作为历史标识保留。远征历史名分别为「符师」与「苦修者」。演化构建者等内部专用组合不属于这三个公共职业。
插件页每个职业一项。当前默认职业「内置 · 始终开启」,直接 API 同样拒绝禁用;非默认职业可以关闭与重开。已有会话保留已经取得的 exact generation,不会因开关被中途剥离。
Preset 声明
一个 preset 是一份声明式定义,经 agent-preset 组合行声明进 roster:
- id: preset-standard
name: agent-preset
config:
id: standard
order: 1
plugins:
- { name: persona, config: { prefix: "..." } }
- { name: scoped-tool-guidance, config: { toolPresentation: native, toolDenyList: [...] } }
- { name: terminal-tools }
persona 不再持有 includeRuntimeContext(已随 #908 删除):工作目录由 working-directory 的运行时上下文提供,不再由 persona 注入。
Longe 自有字段(prompt、toolAllowList/toolDenyList/toolPresentation 等)不留在 preset 顶层,而是落进 plugins 列表里 persona / scoped-tool-guidance 子行的 config。AgentPresetDefinitionValidation 做结构校验:行键只允许 id/name/disabled/config,group/isolate 作为无效拒绝(flat compositions),disabled 必须是布尔字面量,id 必须是 [A-Za-z0-9_-]+。结构问题以 PRESET_INVALID 让行本身失败;挂载失败则以 Broken 原因留在 roster 里——声明不阻止其余 preset 与组合启动。
AgentPresetRegistry(agent-preset-registry 行提供,注入 IAgentPresetRegistry/IAgentPresetPackages)是 roster 与选择的唯一权威:RegisterAsync/UnregisterAsync/List/ResolveDefaultId/AcquireAsync/SelectAsync/ComposeFromAsync/CompositionInventoryAsync。三个发行职业(standard/research/cordis)分别以 bundles/classes/*.patch.yaml 发行,由 web.yaml include;用户旧 *.preset.yaml 目录可经 legacyPresets 配置一次性导入为 patch 行。
name/description 是可选的展示元数据,不参与 generation 内容 hash。随包 preset 不声明它们:Web 客户端只把“没有 name 且 id 属于 standard/research/cordis”的行视为内置,按 id 显示本地化名称、说明与预设帮助;声明了 name 的 preset 归入“自定义”,原样显示自己的文案。agentPresets/list 与插件清单只发布声明过的元数据,不以 id 兜底。
实际职业与历史会话
agent-preset/selected 仍是记录职业的权威。恢复旧会话时,若原职业删除则回退到可用默认职业;同 id 内容变化则使用当前可用 generation;找不到任何可用职业时可保留无职业的恢复状态。
仅在下一步真正开始、且实际职业身份变化时,追加非模型可见的 agent-preset/effective 事件。字段为 recordedPresetId、recordedGeneration、effectivePresetId、effectiveGeneration 与 reason(removed / updated / restored)。同一身份不重复记录;仅查看、打开、加载历史或挂载不会制造执行事实。经典界面展示记录与实际 Agent 预设;远征展示职业更替与结算中的「旧职业 → 实际职业」。
Generation 化挂载
registry 把每个 preset 变成以规范化内容 hash 标识的 standing generation(PresetGenerationPool 拥有 revision):
- 注册即尝试从进程根挂载一个带注册边界的 generation Context;persona、tool 与 listener 必须登记进该 generation 的
AgentPipelineScope,试图向共享 root 注册会让该行失败并写入Broken。 - Agent publication 为 exact generation 取得 lease,并把自己的 pipeline scope 接到该 generation scope;不同 generation 的能力不会通过共享 Cordis registry 互串。
- 同 id 重新注册生成新 generation;健康的旧 generation 仍可按 stamp 取得(
AcquireAsync(id, expectedContentHash)),供 resume/cold rebind/subagent 继承父 exact generation(ComposeFromAsync)。已带失败行的 generation 不向新调用方宣称可用:无 hash 的 Acquire/Select 报NotFound,exact recorded 请求报GenerationMissing,ComposeFromAsync(新 child 准入)也报GenerationMissing;但既有 lease/durable pin 的续用(lease.Retain())不受影响,被替换的旧条目仍留在存活集合直到引用归零才卸载。 - 挂载完成后行仍可能因依赖补齐而失败(late failure):roster/composition 把这一代折叠为
Broken,同一健康谓词也用于新准入;同 id 同内容重注册会重新挂载而不是复用坏缓存,成功后只释放旧记录自己那一份 standing(活引用保留),被替换条目在 standing/lease/durable 全部归零后才卸载。 - 一个失效 generation 的 standing、live 与 durable 引用全部释放后,才按 EffectScope 生命周期卸载其 Context、listener、tool、persona 与 ALC 引用。
因此隔离依据不是“恰好创建了两个 Context”,而是 exact content-hash identity、显式 pipeline parent 与引用计数共同形成的 authority。
默认模型
AgentDefaultModelService 把”用户没显式指定模型时用什么”收敛成一个可写设置:
Base是编译进 bundle 的兜底(LONGE_DEFAULT_ROUTE/LONGE_DEFAULT_MODEL环境变量注入)。- 用户层设置命名空间(默认
agent)里保存的选择覆盖Base;SaveSelectionAsync写回设置层。
Agent 路由解析顺序:Agent 显式钉住的 AgentOptions → 默认模型服务 → bundle 兜底。
会话选模型与全局默认分离(#861 偏离说明)
在 upstream dsh 中,session/selectModel 每次调用都会无差别地写回全局默认模型;这导致远征启程、子代理或临时会话换模型时,意外改写用户在设置中配置的全局默认。
Longe 有意偏离 upstream 这一 wire 行为:
session/selectModel请求载荷新增可选参数persistDefault?: boolean,服务端默认值为false。- 经典界面为当前会话选模型(
ui-model-selection)时显式传persistDefault: true,保持「在经典里选的模型也会成为新会话默认」的现有体验;远征出发等其他调用不传,只改当前会话,避免全局配置被静默踩踏。 - 提取统一的
ISessionLifecycleOps.SelectModelAsync(SessionId, ModelSelection, bool persistDefault = false)接缝,与带图 prompt 准入共享串行锁(SerializeImageAdmissionAsync),保证并发模型切换与图片准入严格互斥。
运行时 Bundle
src/Longe.Bundles/bundles/ 里三份 YAML 是发行形状的声明:
| Bundle | 形状 |
|---|---|
base.yaml | 每个运行时都叠的第一层:会话/Agent 内核、JSONL session-store 与通用 Coordinator、settings / credentials / identity、attachment/spill、本地执行世界、multi-provider LLM、默认模型、title 与 telemetry。Preset roster(agent-preset-registry + agent-preset 行 + preset-selection)只在 web profile 发行 |
headless.yaml | base + replay LLM/default-model replacement;其它能力继续复用 base rows |
cli.yaml | base + replay LLM/default-model replacement + projection cache 与交互/CLI consumers |
Preset identity 已是 durable fact:SessionHeader(格式 v7 起)记录 session 的
initial preset stamp(<preset-id>@<content-hash>,hash 由 preset 文档内容铸造),
agent-preset/selected 事件在 publication fence 内、header mint 与 Agent 可见之前提交。
空白 session(日志中尚无 turn/start)可切换 preset:先 mount/validate 新 generation
再提交事件,失败保持原 identity;cold read、resume 与 fork 只从 header + ordered selected
事件解析 authoritative identity,不重读当前默认,header/event 冲突按 session corruption 处理。
preset 重新声明(新 revision)只影响随后创建/选择的 generation,已有 session 的 recorded identity 不重绑;
provider/preset service HMR 也不能使仍被 lease 或 durable pin 持有的 generation 消失。
会话恢复的分级容错(Generation-Missing 回退)
历史是 durable 数据,preset 是运行时配置;preset 的自然演化(如随版本新增默认能力行使 content hash 改变)绝不阻断历史读取。PresetSelection.PrepareLeaseUnderGatesAsync 实施分级回退策略:
- 精确认领:优先按历史记录的
(presetId, contentHash)获取 exact generation; - 版本演进回退(GenerationMissing):若该特定 hash 的 generation 已随版本升级注销,或该 exact generation 的行已失败(Broken),回退至同名 preset 的当前活跃 revision(
expectedContentHash: null);当前 revision 同样不健康时继续落到第 3/4 步; - 预设移除回退(NotFound):若原 preset 已被用户配置彻底删除、或回退到的当前 revision 同样不健康,回退至系统默认 preset;
- 兜底无预设启动:若连默认 preset 认领也失败,允许以无预设的裸 Agent 恢复会话,确保任何历史投影与会话轨迹永远能正常加载并可读。
- 持久化零篡改:回退仅影响内存中的运行时租约,绝不篡改底层已持久化的
SessionHeader.Preset或历史agent-preset/selected事件。
bundle 只声明 rows,patch 语义归 Cordis.Loader。所有路径用 $\{LONGE_HOME\} 等环境变量插值,与 dsh 的 profile/bundle 分层思路一致:bundle 插入的一切都可被它之上的层继续 patch。