Community程式設計與開發github.com

托管代理基礎設施

此技能應在設計托管或後台代理基礎設施時使用:沙箱執行、遠端編碼環境、溫池、會話持久性、多人協作或 Modal 風格的沙箱。

托管代理基礎設施 是什麼?

此技能專注於設計與實施托管代理基礎設施,這涉及在遠端沙箱環境中運行代理,而非本地機器。其核心優勢包括無限並發性、一致的執行環境以及多人協作能力。關鍵見解是會話速度應僅受模型提供者首次 Token 生成時間限制,所有基礎設施設置應在使用者開始會話前完成。此技能支援多種平台,如 Slack、Web 介面和 Chrome 擴充功能,並提供詳細指導,涵蓋沙箱基礎設施、代理框架選擇、速度優化、自生成代理、API 層、多人支援、驗證授權以及客戶端實作。它還提供實用指南,包括托管代理設計清單、後續訊息處理、關鍵指標追蹤和採用策略。此技能特別適合需要構建後台編碼代理、設計沙箱執行環境、實作多人代理會話以及建立多客戶端代理介面的開發人員。

相容平台~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。
  • 設計托管代理使用的工具,例如生成/狀態工具或 PR 工具:使用 tool-design。
  • 管理會話內的檔案備份狀態,而非托管執行環境本身:使用 filesystem-context。

核心概念

將代理執行移至遠端沙箱環境,以消除本地執行的基本限制:資源競爭、環境不一致和單一使用者限制。遠端沙箱解鎖無限並發性、可重現的環境和協作工作流程,因為每個會話獲得自己的隔離計算,並帶有已知良好的環境映像。

將架構設計為三層,因為每層可獨立擴展。建置沙箱基礎設施以進行隔離執行、API 層以進行狀態管理和用戶端協調,以及客戶端介面以進行跨平台使用者互動。保持這些層級清晰分離,使沙箱變更不會影響客戶端。

詳細主題

沙箱基礎設施

核心挑戰 消除沙箱啟動延遲,因為使用者認為任何超過幾秒鐘的時間都是故障。開發環境需要克隆儲存庫、安裝依賴項和執行建置步驟——在使用者提交提示之前完成所有這些工作。

映像登錄檔模式 定期預建環境映像(每 30 分鐘效果良好),因為這使與最新程式碼的同步成為快速增量,而非完整克隆。每個映像包含:

  • 在已知提交處克隆的儲存庫
  • 已安裝的所有執行時期依賴項
  • 已完成的初始設定和建置命令
  • 運行應用程式和測試套件後的快取檔案

啟動會話時,從最新映像啟動沙箱。儲存庫最多落後 30 分鐘,使剩餘的 git 同步快速。

快照與恢復 在關鍵點拍攝檔案系統快照,以便無需重新執行設定即可即時恢復後續提示:

  • 初始映像建置後(基本快照)
  • 代理完成變更後(會話快照)
  • 在可能後續追問的沙箱退出前

背景代理的 Git 配置 在每個沙箱中明確配置 Git 身份,因為背景代理在建置映像時不與特定使用者綁定:

  • 生成 GitHub App 安裝令牌,用於在克隆期間存取儲存庫
  • 在提交和推送變更時設定 git config user.name 和 user.email
  • 使用發起提示的使用者身份進行提交,而非應用程式身份

溫池策略 為高流量儲存庫維護預熱沙箱池,因為冷啟動是使用者不滿的主要來源:

  • 在使用者開始會話前準備好沙箱
  • 隨著新映像建置完成,過期並重新建立池項目
  • 在使用者開始打字時立即開始預熱沙箱(預測性預熱)

代理框架選擇

伺服器優先架構 將代理框架結構化為伺服器優先,TUI 和桌面應用程式作為輕量客戶端,因為這可防止跨表面重複代理邏輯:

  • 多個自訂客戶端共享一個代理後端
  • 所有互動表面的一致行為
  • 插件系統無需客戶端變更即可擴展功能
  • 事件驅動架構向任何已連接客戶端提供即時更新

程式碼作為事實來源 選擇代理可以讀取自身原始碼以了解行為的框架。優先考慮這一點,因為將程式碼作為事實來源可防止代理幻想自己的功能——這是 AI 開發中被低估的失敗模式。

插件系統要求 要求支援執行時期攔截的插件系統,因為這可以在不修改核心代理邏輯的情況下實現安全控制和可觀測性:

  • 監聽工具執行事件(例如 tool.execute.before)
  • 有條件地阻止或修改工具呼叫
  • 在執行時期注入上下文或狀態

速度優化

預測性預熱 在使用者開始輸入提示時立即開始預熱沙箱,而不是在提交時,因為打字間隔(5-30 秒)足以完成大部分設定:

  • 在使用者打字時並行克隆最新變更
  • 在使用者按 Enter 之前執行初始設定
  • 對於快速啟動,沙箱可在使用者完成打字前準備就緒

並行檔案讀取 允許代理立即開始讀取檔案,即使與最新基礎分支的同步尚未完成,因為在大型儲存庫中,傳入提示很少觸及最近變更的檔案:

  • 代理可以立即進行研究,無需等待 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 Webhook 通知 API PR 事件

客戶端實作

Slack 整合 優先考慮 Slack 作為內部採用的第一個分發渠道,因為它會建立病毒式傳播循環,因為團隊成員看到其他人使用它:

  • 無需語法,自然聊天介面
  • 建置一個分類器(帶有儲存庫描述的快速模型)以確定要在哪個儲存庫中工作
  • 包含常見儲存庫的提示;允許「未知」用於不明確的情況

Web 介面 建置具有以下功能的 Web 介面,因為它作為主要的進階使用者表面:

  • 在桌面和行動裝置上即時串流代理工作
  • 在沙箱內執行的托管 VS Code 實例
  • 用於視覺驗證的串流桌面檢視
  • PR 的前後對比螢幕截圖
  • 統計頁面:導致合併 PR 的會話(主要指標)、隨時間的使用情況、即時「人類正在提示」計數

Chrome 擴充功能 為非工程使用者建置 Chrome 擴充功能,因為提取 DOM/React 內部結構比原始螢幕截圖具有更高的精確度,且 Token 成本更低:

  • 帶有螢幕截圖工具的側邊欄聊天介面
  • 提取 DOM/React 內部結構,而非原始圖像
  • 透過受管裝置政策分發(繞過 Chrome 線上應用程式商店)

實用指南

托管代理設計檢查清單

在建置系統之前,明確決定這些基礎設施屬性:

  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. 同步死結:如果讀取和寫入同步未正確解耦,代理可能無限等待 git 同步。獨立解鎖。
  5. 費用意外:沒有預算上限的持久沙箱會導致大量雲端費用。建置成本上限和終止邏輯。
  6. 忽略後續追問:如果沒有快照和恢復,後續提示會重新執行整個設定。在關鍵點快照檔案系統。
  7. 無狀態客戶端:假設客戶端有狀態會導致使用者切換裝置時中斷。將所有客戶端建置為無狀態,API 管理會話狀態。
  8. 混合同步/非同步:混合模型讓使用者對回饋時間產生困惑。在所有地方使用即時串流,或明確標記非同步結果。
  9. 單點故障:如果沒有適當的訊號機制,失去與沙箱的連線會導致孤立進程。使用心跳和逾時。
  10. 忽略暖啟動路徑:為冷啟動最佳化但忽略後續提示的常見模式遵循不同的路徑。兩者都測試。

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.

相關技能