Community编程与开发github.com

托管代理基础设施

此技能用于设计托管或后台代理基础设施:沙盒化执行、远程编码环境、预热池、会话持久化、多人协作或 Modal 风格的沙盒。

托管代理基础设施 是什么?

该技能专注于设计和构建托管代理基础设施,其核心是将代理执行迁移到远程沙盒化环境,从而消除本地执行的基本限制,例如资源争用、环境不一致性和单用户约束。它详细阐述了如何通过预构建的环境镜像、快照恢复和 warm pool 策略来消除沙盒冷启动延迟,从而在用户开始会话前完成所有基础设施设置。技能覆盖了三层架构:沙盒基础设施(用于隔离执行)、API 层(用于状态管理和客户端协调)以及客户端接口(用于跨平台用户交互)。此外,它还深入探讨了速度优化(如预测性预热和并行文件读取)、自生成代理能力、实时流式传输、多人协作支持、基于 GitHub 的身份验证以及 Slack、Web、Chrome 扩展等客户端实现。最终目标是实现无限并发、一致执行环境和跨平台协作,以构建高可靠性和低延迟的托管代理系统。支持的平台包括但不限于 Claude Code、Cursor 和 Codex 等支持代理框架的环境。

兼容平台~Claude Code~Codex CLI~Cursor✓OpenCode
npx skills add https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main/skills/hosted-agents

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

托管代理基础设施 是做什么的?

托管代理在远程沙盒化环境中运行,而非本地机器上。设计得当的话,它们能提供无限的并发性、一致的执行环境和多人协作。关键洞察是:会话速度应仅受模型提供商的“首个 token 生成时间”限制,所有基础设施设置都应在用户开始会话之前完成。

何时激活

在以下情况下激活此技能:

  • 构建独立于用户设备的后台编码代理
  • 为代理工作负载设计沙盒化执行环境
  • 实现具有共享状态的多人代理会话
  • 创建多客户端代理接口(Slack、Web、Chrome 扩展)
  • 将代理基础设施扩展到本地机器限制之外
  • 构建代理可生成子代理以进行并行工作的系统

对于属于其他技能的相邻工作,不要激活此技能:

  • 设计自主研究循环、新颖性门控、回滚策略或合并边界:请使用 harness-engineering。
  • 选择监督者、群体或交接拓扑,而不涉及托管基础设施问题:请使用 multi-agent-patterns。
  • 设计托管代理使用的工具,例如 spawn/status 工具或 PR 工具:请使用 tool-design。
  • 在会话内部管理文件支持的状态,而非托管运行时本身:请使用 filesystem-context。

核心概念

将代理执行移至远程沙盒化环境,以消除本地执行的根本限制:资源争用、环境不一致性和单用户约束。远程沙盒可实现无限并发、可重复环境和协作工作流,因为每个会话都拥有自己的隔离计算环境和已知良好的环境镜像。

按三层架构进行设计,因为每一层都可以独立扩展。构建沙盒基础设施用于隔离执行,构建 API 层用于状态管理和客户端协调,构建客户端接口用于跨平台的用户交互。保持这些层清晰分离,以便沙盒的更改不会波及客户端。

详细主题

沙盒基础设施

核心挑战 消除沙盒启动延迟,因为用户认为超过几秒的延迟就是故障。开发环境需要克隆仓库、安装依赖项和运行构建步骤——所有这些都应在用户提交提示之前完成。

镜像注册表模式 按固定节奏(每 30 分钟效果良好)预构建环境镜像,因为这使与最新代码的同步成为快速增量更新,而非完整克隆。在每个镜像中包含:

  • 已知提交基础上的已克隆仓库
  • 所有运行时依赖项已安装
  • 初始设置和构建命令已完成
  • 运行一次应用程序和测试套件后的缓存文件

当启动会话时,从最近的镜像启动沙盒。仓库最多落后 30 分钟,这使得剩余的 git 同步速度快。

快照和恢复 在关键时间点获取文件系统快照,以便在后续提示时无需重新运行设置即可立即恢复:

  • 初始镜像构建后(基础快照)
  • 代理完成更改后(会话快照)
  • 在沙盒退出前,以备可能的后续操作

后台代理的 Git 配置 在每个沙盒中显式配置 git 身份,因为后台代理在镜像构建期间不与特定用户绑定:

  • 生成 GitHub App 安装令牌以在克隆期间访问仓库
  • 在提交和推送更改时设置 git 配置 user.name 和 user.email
  • 使用提示用户身份进行提交,而非应用身份

预热池策略 为高流量仓库维护一个预预热沙盒池,因为冷启动是用户挫折感的主要来源:

  • 在用户开始会话前准备好沙盒
  • 随着新镜像构建完成,过期并重新创建池条目
  • 在用户开始输入时即开始预热沙盒(预测性预热)

代理框架选择

服务器优先架构 将代理框架构建为服务器优先,TUI 和桌面应用作为瘦客户端,因为这可以防止在多个界面上重复代理逻辑:

  • 多个自定义客户端共享一个代理后端
  • 所有交互界面上的行为一致
  • 插件系统无需客户端更改即可扩展功能
  • 事件驱动架构向任何连接的客户端提供实时更新

代码即真理之源 选择代理可以读取自身源代码以理解行为的框架。优先考虑这一点,因为代码作为真理之源可防止代理幻觉其自身能力——这是 AI 开发中一个被低估的失败模式。

插件系统要求 要求支持运行时拦截的插件系统,因为这可以在不修改核心代理逻辑的情况下启用安全控制和可观察性:

  • 监听工具执行事件(例如 tool.execute.before)
  • 有条件地阻止或修改工具调用
  • 在运行时注入上下文或状态

速度优化

预测性预热 在用户开始输入提示时(而非提交时)即开始预热沙盒,因为输入间隔(5-30 秒)足以完成大部分设置:

  • 在用户输入时并行克隆最新更改
  • 在用户按回车前运行初始设置
  • 对于快速启动,沙盒可在用户完成输入前准备就绪

并行文件读取 允许代理在同步最新基础分支完成前立即开始读取文件,因为在大型仓库中,传入的提示很少触及时近更改的文件:

  • 代理可以立即进行研究,无需等待 git 同步
  • 阻止文件编辑(而非读取),直到同步完成
  • 这种分离是安全的,因为 30 分钟的读取数据过时对研究影响极小

最大化构建时工作 尽可能将所有工作移至镜像构建步骤,因为构建时间对用户不可见:

  • 完整依赖安装
  • 数据库架构设置
  • 初始应用程序和测试套件运行(填充缓存)

自生成代理

代理生成的会话 构建允许代理生成新会话的工具,因为前沿模型能够分解工作并协调子任务:

  • 跨不同仓库的研究任务
  • 大型更改的并行子任务执行
  • 一个主要任务产出多个较小的 PR

暴露三个基本原语:使用指定参数启动新会话,读取任何会话的状态(签到功能),以及在子会话并行运行时继续主要工作。

自生成代理的提示工程 设计提示,指导代理何时应生成子会话,而不是内联完成工作:

  • 需要跨仓库探索的研究任务
  • 将整体更改分解为较小的 PR
  • 并行探索不同方法

API 层

每会话状态隔离 隔离每个会话的状态(每个会话使用 SQLite 效果良好),因为跨会话干扰是一种微妙且难以调试的失败模式:

  • 每个会话专用数据库
  • 没有会话能影响其他会话的性能
  • 架构可处理数百个并发会话

实时流式传输 实时流式传输所有代理工作,因为高频反馈对于用户信任至关重要:

  • 来自模型提供商的 token 流
  • 工具执行状态更新
  • 文件更改通知

使用支持休眠 API 的 WebSocket 连接,以在空闲期间降低计算成本,同时保持连接开放。

跨客户端同步 构建一个跨所有客户端(聊天界面、Slack 机器人、Chrome 扩展、Web 界面、VS Code 实例)同步的单一状态系统,因为用户频繁切换界面并期望连续性。所有更改都同步到会话状态,实现无缝客户端切换。

多人支持

多人模式为何重要 从第一天起就为多人模式设计,因为有了合适的同步架构,添加此功能几乎零成本,并且它能解锁高价值工作流:

  • 教非工程人员有效使用 AI
  • 与多个团队成员进行实时 QA 会话
  • 即时 PR 评审并立即更改
  • 协作调试会话

实现要求 构建数据模型,以使会话不绑定到单个作者,因为如果作者身份被硬编码,多人模式会静默失败:

  • 将作者信息传递给每个提示
  • 将代码更改归因于提示用户
  • 共享会话链接以实现即时协作

身份验证和授权

基于用户的提交 使用 GitHub 身份验证代表用户(而非应用)打开 PR,因为这可以保留审计轨迹,并防止用户批准自己 AI 生成的更改:

  • 获取用户令牌用于 PR 创建
  • PR 显示为由人类(而非机器人)编写

沙盒到 API 流程 遵循以下序列,因为它使沙盒权限最小化,同时让 API 处理敏感操作:

  1. 沙盒推送更改(更新 git 用户配置)
  2. 沙盒向 API 发送事件,包含分支名称和会话 ID
  3. API 使用用户的 GitHub 令牌创建 PR
  4. GitHub webhooks 通知 API PR 事件

客户端实现

Slack 集成 优先将 Slack 作为内部采用的第一分发渠道,因为这会在团队成员看到其他人使用时产生病毒式传播循环:

  • 无需语法,自然的聊天界面
  • 构建一个分类器(快速模型配合仓库描述)以确定在哪个仓库中工作
  • 包含常见仓库的提示;允许“未知”以处理歧义情况

Web 界面 构建具有以下功能的 Web 界面,因为它作为主要的强力用户界面:

  • 在桌面和移动设备上实时流式传输代理工作
  • 运行在沙盒内的托管 VS Code 实例
  • 流式传输桌面视图以进行视觉验证
  • PR 的前/后截图
  • 统计页面:导致合并 PR 的会话(主要指标)、随时间变化的使用情况、实时“人类提示”计数

Chrome 扩展 为非工程用户构建 Chrome 扩展,因为提取 DOM/React 内部信息比原始截图精度更高,且 token 成本更低:

  • 侧边栏聊天界面,带有截图工具
  • 提取 DOM/React 内部信息,而非原始图像
  • 通过托管设备策略分发(绕过 Chrome Web Store)

实用指南

托管代理设计清单

在构建系统之前,明确决定以下基础设施属性:

  1. 沙盒生命周期:会话如何启动、快照、恢复、超时和终止。
  2. 镜像和预热池策略:镜像多久重建一次、哪些缓存被预计算、预热沙盒何时过期。
  3. 读/写同步:代理是否可以在仓库同步完成前读取,以及哪些事件解除写入阻塞。
  4. 每会话状态隔离:哪些存储属于一个会话、哪些是共享的,以及如何防止跨会话干扰。
  5. 认证和提交身份:哪些操作使用应用令牌、哪些使用用户令牌,以及提交如何归因。
  6. 输出提取:分支、PR、文件、日志、截图和会话摘要如何离开沙盒。
  7. 预算和清理:最大运行时间、成本上限、空闲策略和强制清理行为。

后续消息处理

选择在执行期间发送的后续消息是排队还是插入。优先考虑排队,因为它更易于管理,并且允许用户在代理工作时发送后续步骤的想法。构建一个必要时停止代理的机制,因为如果没有它,用户会感到受困。

重要指标

跟踪这些指标,因为它们指示真实价值而非虚荣使用量:

  • 导致合并 PR 的会话(主要成功指标)
  • 从会话开始到第一个模型响应的时间
  • PR 批准率和修订次数
  • 仓库中代理编写代码的百分比

采用策略

通过可见性而非强制推动内部采用,因为强迫使用会滋生反感:

  • 在公共空间(如 Slack 频道)工作以提高可见性
  • 让产品创造病毒式传播循环
  • 不要强迫用户使用而替代现有工具
  • 根据人们的需求构建,而非假设性需求

示例

示例 1:后台编码会话生命周期

用户提示
-> API 从当前镜像分配预热沙盒
-> 沙盒同步最新分支增量
-> 立即允许读取,同步完成前阻止写入
-> 在隔离工作区内代理编辑和测试
-> 沙盒快照最终文件系统
-> 分支被推送
-> API 使用用户令牌创建 PR
-> 会话摘要、日志和 PR URL 返回给客户端

此序列将设置工作置于用户可见路径之外,同时保留代码更改的可审计性和用户所有权。

示例 2:边界决策

如果任务是“使代理循环以锁定规则和 PR 批准运行数天”,请使用 harness-engineering。如果任务是“在具有预热池、会话快照、流式客户端和用户编写 PR 的远程沙盒中运行该循环”,请使用此技能。

指南

  1. 按固定节奏预构建环境镜像(30 分钟是一个好的默认值)
  2. 在用户开始输入时开始预热沙盒,而非提交时
  3. 允许在 git 同步完成前读取文件;仅阻止写入
  4. 将代理框架构建为服务器优先,客户端作为瘦包装器
  5. 每会话隔离状态,以防止跨会话干扰
  6. 将提交归因于提示的用户,而非应用
  7. 将合并的 PR 作为主要成功指标
  8. 从一开始就为多人模式构建;有了合适的同步架构,这几乎零成本

注意事项

  1. 冷启动延迟:首次沙盒启动需要 30-60 秒,用户会认为这是故障。使用预热池和预测性预热来解决此问题。
  2. git 同步竞争条件:在慢速网络下,同步可能滞后,导致用户看到陈旧代码。优先读取,并在同步期间阻止写入。
  3. 文件写入冲突:多个代理写入同一文件会导致合并冲突。使用隔离的工作区和文件锁。
  4. 状态泄漏:共享数据库或文件系统会在会话之间泄漏状态。强制严格隔离。
  5. 成本失控:预热沙盒和空闲会话会累积成本。实施严格的预算和清理策略。
  6. 用户身份冒充:如果用户令牌不用于 PR 创建,PR 将看起来像是应用编写的。始终使用用户令牌。
  7. 客户端粘性:用户期望在设备之间无缝切换。使用以会话为中心的同步状态。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

advanced-evaluation

This skill should be used for advanced LLM evaluation: LLM-as-judge systems, direct scoring, pairwise comparison, rubric calibration, evaluator bias mitigation, confidence scoring, and automated quality assessment.

bdi-mental-states

This skill should be used when modeling agent mental states with BDI concepts: beliefs, desires, intentions, RDF-to-belief transformations, rational agency traces, cognitive agents, BDI ontologies, and neuro-symbolic AI integration.

book-sft-pipeline

This skill should be used for book-to-SFT pipelines: ePub extraction, literary segmentation, author-voice dataset construction, style-transfer training, LoRA workflows, and model evaluation for voice replication.

compaction-control-profiling

This skill should be used when deciding, for a specific model and workload, whether the harness or the model should control compaction, and when qualifying or calibrating that choice with measurements: context-budget sweeps that compare harness-driven and model-driven compaction on one harness, the context-pressure regime where delegation pays, a per-model compaction behavior profile (interface uptake, compression factor per call, reopen rate of archived content, context fill at first compaction, response to pressure warnings), context anxiety and timing-instruction calibration, reversible collapse-and-archive interfaces, and re-qualification after a model or prompt change. Route the editable-file protocol, harness invariants, and edit-position cache cost of self-editing agents to self-managed-context, summary content to context-compression, harness thresholds and cache layout to context-optimization, and general evaluation design to evaluation.

comprehensive-research-agent

Ensure thorough validation, error recovery, and transparent reasoning in research tasks with multiple tool calls

context-compression

This skill should be used when long-running agent sessions need context compression, structured summarization, compaction, token-per-task optimization, or durable handoff summaries that preserve decisions, files, risks, and next actions.

context-degradation

This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion, attention-pattern issues, and agent performance degradation caused by accumulated or conflicting context.

context-fundamentals

This skill should be used to explain or reason about the foundational concepts of context engineering: what context is, the anatomy of a context window, how attention mechanics work, the U-shaped attention curve, why context quality matters more than quantity, and the mental models needed to interpret every other context-engineering decision. Use this for conceptual explanation, onboarding, and background reading. Route operational work to the specialized skills: debugging attention failures goes to context-degradation, token-efficiency work goes to context-optimization, conversation summarization goes to context-compression, and project-shape decisions go to project-development.

context-optimization

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

evaluation

This skill should be used when building agent evaluation systems: deterministic checks, regression suites, multi-dimensional rubrics, quality gates, production monitoring, baseline comparison, and outcome measurement for agent pipelines.

filesystem-context

This skill should be used when agent work needs file-backed context: durable scratchpads, tool-output offloading, just-in-time discovery, cross-agent handoff files, filesystem memory, or cleanup policies for context stored outside the prompt.

harness-engineering

This skill should be used when designing autonomous agent harnesses: research loops, evaluation scaffolds, locked and editable surfaces, durable logs, novelty gates, pruning, rollback, PR preparation, and human approval boundaries.

instruction-surface-security

Hardens agent runtimes against persistent prompt injection or unauthorized changes to instructions and permissions. Use to audit what agents auto-load, design reviewed activation for project rules, skills, memory, or tool configuration, and test whether trust boundaries hold after reload, restart, or delegation.

latent-briefing

This skill should be used when the user asks to "share memory between agents", "KV cache compaction for multi-agent", "orchestrator worker context", "latent briefing", "reduce worker tokens", "cross-agent memory without summarization", or discusses Attention Matching compaction, recursive language models with workers, or token explosion in hierarchical agents.

long-horizon-prompting

This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.

memory-systems

This skill should be used for persistent semantic memory in agent systems: cross-session knowledge retention, entity tracking, temporal validity, graph or vector retrieval, memory consolidation, and memory benchmark selection. Route file-backed scratchpads to filesystem-context, handoff summaries to context-compression, and token-efficiency tactics to context-optimization.

multi-agent-patterns

This skill should be used when designing multi-agent systems that need context isolation, supervisor or swarm coordination, explicit handoffs, parallel execution, or a decision on whether multiple agents are justified.

project-development

This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token and cost estimation, choosing between single-agent and multi-agent at the project level, structured output design for downstream parsing, and structuring agent-assisted iteration. Use this when the unit of work is a whole project or a multi-stage pipeline. Route individual tool design to tool-design and individual skill-loading or context-budget tactics to context-optimization.

self-improvement-loops

This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

self-managed-context

This skill should be used when a model gets read-write control over its own live context window instead of a harness-scheduled compaction policy: the context exposed as an editable file the model rewrites with code tools, model-driven eviction and in-place updates, the harness invariants that keep self-editing safe (pinned prefix, edit gate, edit receipts, budget readouts, rollback on overflow), the prefix-cache cost of mid-context edits, and steering or training the model's own context-editing strategy. Route note content and fixed-threshold summarization to context-compression, cache-stable layout under harness control to context-optimization, file offloading to filesystem-context, and loop governance to self-improvement-loops.

相关技能