hive-skills 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +235 -0
  3. package/assets/LICENSE +32 -0
  4. package/assets/THIRD_PARTY_NOTICES.md +72 -0
  5. package/assets/manifest.json +1290 -0
  6. package/assets/skills/authored/code-review/composable/BUNDLE.md +192 -0
  7. package/assets/skills/authored/code-review/composable/INDEX.md +13 -0
  8. package/assets/skills/authored/code-review/composable/VERSION +1 -0
  9. package/assets/skills/authored/code-review/composable/mini/01-review-method.md +34 -0
  10. package/assets/skills/authored/code-review/composable/mini/02-security-review.md +20 -0
  11. package/assets/skills/authored/code-review/composable/mini/03-correctness-bugs.md +19 -0
  12. package/assets/skills/authored/code-review/composable/mini/04-concurrency.md +16 -0
  13. package/assets/skills/authored/code-review/composable/mini/05-error-handling.md +12 -0
  14. package/assets/skills/authored/code-review/composable/mini/06-performance.md +11 -0
  15. package/assets/skills/authored/code-review/composable/mini/07-api-design.md +20 -0
  16. package/assets/skills/authored/code-review/composable/mini/08-missing-tests.md +25 -0
  17. package/assets/skills/authored/code-review/composable/mini/09-refactoring-and-communication.md +32 -0
  18. package/assets/skills/authored/data-analysis/composable/BUNDLE.md +186 -0
  19. package/assets/skills/authored/data-analysis/composable/INDEX.md +13 -0
  20. package/assets/skills/authored/data-analysis/composable/VERSION +1 -0
  21. package/assets/skills/authored/data-analysis/composable/mini/01-data-quality-profiling.md +26 -0
  22. package/assets/skills/authored/data-analysis/composable/mini/02-aggregation-pitfalls.md +21 -0
  23. package/assets/skills/authored/data-analysis/composable/mini/03-time-series.md +19 -0
  24. package/assets/skills/authored/data-analysis/composable/mini/04-segmentation.md +23 -0
  25. package/assets/skills/authored/data-analysis/composable/mini/05-discount-pricing.md +17 -0
  26. package/assets/skills/authored/data-analysis/composable/mini/06-insight-generation.md +25 -0
  27. package/assets/skills/authored/data-analysis/composable/mini/07-executive-writing.md +26 -0
  28. package/assets/skills/authored/data-analysis/composable/mini/08-recommendations.md +20 -0
  29. package/assets/skills/authored/data-analysis/composable/mini/09-reproducibility-assumptions.md +20 -0
  30. package/assets/skills/authored/financial-analysis/composable/BUNDLE.md +1293 -0
  31. package/assets/skills/authored/financial-analysis/composable/INDEX.md +17 -0
  32. package/assets/skills/authored/financial-analysis/composable/VERSION +1 -0
  33. package/assets/skills/authored/financial-analysis/composable/mini/00-core.md +69 -0
  34. package/assets/skills/authored/financial-analysis/composable/mini/01-profitability-efficiency-ratios.md +173 -0
  35. package/assets/skills/authored/financial-analysis/composable/mini/02-liquidity-leverage-ratios.md +120 -0
  36. package/assets/skills/authored/financial-analysis/composable/mini/03-valuation-ratios-interpretation.md +107 -0
  37. package/assets/skills/authored/financial-analysis/composable/mini/04-dcf-projection-wacc.md +122 -0
  38. package/assets/skills/authored/financial-analysis/composable/mini/05-dcf-terminal-value-sensitivity.md +75 -0
  39. package/assets/skills/authored/financial-analysis/composable/mini/06-comparables-precedents.md +78 -0
  40. package/assets/skills/authored/financial-analysis/composable/mini/07-budget-variance-analysis.md +47 -0
  41. package/assets/skills/authored/financial-analysis/composable/mini/08-driver-based-forecasting-scenarios.md +111 -0
  42. package/assets/skills/authored/financial-analysis/composable/mini/09-rolling-forecasts-accuracy.md +114 -0
  43. package/assets/skills/authored/financial-analysis/composable/mini/10-reporting-exec-summary.md +58 -0
  44. package/assets/skills/authored/financial-analysis/composable/mini/11-industry-adaptations.md +130 -0
  45. package/assets/skills/authored/financial-analysis/composable/mini/12-toolkit-scripts-io.md +102 -0
  46. package/assets/skills/authored/python-api/composable/BUNDLE.md +389 -0
  47. package/assets/skills/authored/python-api/composable/INDEX.md +13 -0
  48. package/assets/skills/authored/python-api/composable/VERSION +1 -0
  49. package/assets/skills/authored/python-api/composable/mini/01-project-structure.md +44 -0
  50. package/assets/skills/authored/python-api/composable/mini/02-routing-and-app.md +38 -0
  51. package/assets/skills/authored/python-api/composable/mini/03-pydantic-models.md +45 -0
  52. package/assets/skills/authored/python-api/composable/mini/04-validation-and-errors.md +59 -0
  53. package/assets/skills/authored/python-api/composable/mini/05-dependencies-and-auth.md +60 -0
  54. package/assets/skills/authored/python-api/composable/mini/06-pagination-filtering.md +44 -0
  55. package/assets/skills/authored/python-api/composable/mini/07-async-performance.md +30 -0
  56. package/assets/skills/authored/python-api/composable/mini/08-testing.md +45 -0
  57. package/assets/skills/authored/python-api/composable/mini/09-middleware-observability.md +29 -0
  58. package/assets/skills/authored/tech-writing/composable/BUNDLE.md +220 -0
  59. package/assets/skills/authored/tech-writing/composable/INDEX.md +12 -0
  60. package/assets/skills/authored/tech-writing/composable/VERSION +1 -0
  61. package/assets/skills/authored/tech-writing/composable/mini/01-audience-analysis.md +26 -0
  62. package/assets/skills/authored/tech-writing/composable/mini/02-document-types.md +27 -0
  63. package/assets/skills/authored/tech-writing/composable/mini/03-readme-quickstart-changelog.md +22 -0
  64. package/assets/skills/authored/tech-writing/composable/mini/04-information-architecture.md +21 -0
  65. package/assets/skills/authored/tech-writing/composable/mini/05-style-clarity.md +29 -0
  66. package/assets/skills/authored/tech-writing/composable/mini/06-breaking-changes-migrations.md +33 -0
  67. package/assets/skills/authored/tech-writing/composable/mini/07-troubleshooting-security.md +30 -0
  68. package/assets/skills/authored/tech-writing/composable/mini/08-faq-voice-tone.md +32 -0
  69. package/assets/skills/converted/claude-api/composable/BUNDLE.md +14996 -0
  70. package/assets/skills/converted/claude-api/composable/INDEX.md +98 -0
  71. package/assets/skills/converted/claude-api/composable/VERSION +1 -0
  72. package/assets/skills/converted/claude-api/composable/mini/00-core.md +235 -0
  73. package/assets/skills/converted/claude-api/composable/mini/01-model-api-quick-reference.md +258 -0
  74. package/assets/skills/converted/claude-api/composable/mini/02-common-pitfalls.md +42 -0
  75. package/assets/skills/converted/claude-api/composable/mini/10-models.md +135 -0
  76. package/assets/skills/converted/claude-api/composable/mini/11-platform-availability.md +96 -0
  77. package/assets/skills/converted/claude-api/composable/mini/12-claude-platform-on-aws.md +59 -0
  78. package/assets/skills/converted/claude-api/composable/mini/13-live-sources.md +143 -0
  79. package/assets/skills/converted/claude-api/composable/mini/14-error-codes.md +256 -0
  80. package/assets/skills/converted/claude-api/composable/mini/15-prompt-caching.md +223 -0
  81. package/assets/skills/converted/claude-api/composable/mini/16-token-counting.md +56 -0
  82. package/assets/skills/converted/claude-api/composable/mini/17-tool-use-concepts.md +444 -0
  83. package/assets/skills/converted/claude-api/composable/mini/18-agent-design.md +101 -0
  84. package/assets/skills/converted/claude-api/composable/mini/19-anthropic-cli.md +246 -0
  85. package/assets/skills/converted/claude-api/composable/mini/20-model-migration.md +1301 -0
  86. package/assets/skills/converted/claude-api/composable/mini/30-managed-agents-overview.md +71 -0
  87. package/assets/skills/converted/claude-api/composable/mini/31-managed-agents-core.md +278 -0
  88. package/assets/skills/converted/claude-api/composable/mini/32-managed-agents-environments.md +219 -0
  89. package/assets/skills/converted/claude-api/composable/mini/33-managed-agents-tools.md +366 -0
  90. package/assets/skills/converted/claude-api/composable/mini/34-managed-agents-events.md +252 -0
  91. package/assets/skills/converted/claude-api/composable/mini/35-managed-agents-outcomes.md +106 -0
  92. package/assets/skills/converted/claude-api/composable/mini/36-managed-agents-multiagent.md +101 -0
  93. package/assets/skills/converted/claude-api/composable/mini/37-managed-agents-webhooks.md +123 -0
  94. package/assets/skills/converted/claude-api/composable/mini/38-managed-agents-memory.md +197 -0
  95. package/assets/skills/converted/claude-api/composable/mini/39-managed-agents-scheduled-deployments.md +146 -0
  96. package/assets/skills/converted/claude-api/composable/mini/40-managed-agents-client-patterns.md +211 -0
  97. package/assets/skills/converted/claude-api/composable/mini/41-managed-agents-onboarding.md +82 -0
  98. package/assets/skills/converted/claude-api/composable/mini/42-managed-agents-api-reference.md +441 -0
  99. package/assets/skills/converted/claude-api/composable/mini/43-managed-agents-self-hosted-sandboxes.md +174 -0
  100. package/assets/skills/converted/claude-api/composable/mini/50-python-readme.md +564 -0
  101. package/assets/skills/converted/claude-api/composable/mini/51-python-tool-use.md +590 -0
  102. package/assets/skills/converted/claude-api/composable/mini/52-python-streaming-batches-files.md +549 -0
  103. package/assets/skills/converted/claude-api/composable/mini/53-python-managed-agents.md +335 -0
  104. package/assets/skills/converted/claude-api/composable/mini/55-typescript-readme.md +404 -0
  105. package/assets/skills/converted/claude-api/composable/mini/56-typescript-tool-use.md +548 -0
  106. package/assets/skills/converted/claude-api/composable/mini/57-typescript-streaming-batches-files.md +384 -0
  107. package/assets/skills/converted/claude-api/composable/mini/58-typescript-managed-agents.md +358 -0
  108. package/assets/skills/converted/claude-api/composable/mini/60-csharp-readme.md +361 -0
  109. package/assets/skills/converted/claude-api/composable/mini/61-csharp-tool-use.md +163 -0
  110. package/assets/skills/converted/claude-api/composable/mini/62-csharp-streaming-batches-files.md +64 -0
  111. package/assets/skills/converted/claude-api/composable/mini/65-go-readme.md +185 -0
  112. package/assets/skills/converted/claude-api/composable/mini/66-go-tool-use.md +219 -0
  113. package/assets/skills/converted/claude-api/composable/mini/67-go-streaming-files.md +63 -0
  114. package/assets/skills/converted/claude-api/composable/mini/68-go-managed-agents.md +564 -0
  115. package/assets/skills/converted/claude-api/composable/mini/70-java-readme.md +237 -0
  116. package/assets/skills/converted/claude-api/composable/mini/71-java-tool-use.md +227 -0
  117. package/assets/skills/converted/claude-api/composable/mini/72-java-streaming-files.md +49 -0
  118. package/assets/skills/converted/claude-api/composable/mini/73-java-managed-agents.md +443 -0
  119. package/assets/skills/converted/claude-api/composable/mini/75-php-readme.md +173 -0
  120. package/assets/skills/converted/claude-api/composable/mini/76-php-tool-use.md +252 -0
  121. package/assets/skills/converted/claude-api/composable/mini/77-php-streaming-batches-files.md +53 -0
  122. package/assets/skills/converted/claude-api/composable/mini/78-php-managed-agents.md +443 -0
  123. package/assets/skills/converted/claude-api/composable/mini/80-ruby-readme.md +133 -0
  124. package/assets/skills/converted/claude-api/composable/mini/81-ruby-tool-use-streaming.md +56 -0
  125. package/assets/skills/converted/claude-api/composable/mini/82-ruby-managed-agents.md +394 -0
  126. package/assets/skills/converted/claude-api/composable/mini/85-curl-examples.md +255 -0
  127. package/assets/skills/converted/claude-api/composable/mini/86-curl-managed-agents.md +340 -0
  128. package/assets/skills/converted/claude-api/composable/presets/csharp.md +1151 -0
  129. package/assets/skills/converted/claude-api/composable/presets/curl.md +1154 -0
  130. package/assets/skills/converted/claude-api/composable/presets/go.md +1598 -0
  131. package/assets/skills/converted/claude-api/composable/presets/java.md +1523 -0
  132. package/assets/skills/converted/claude-api/composable/presets/php.md +1488 -0
  133. package/assets/skills/converted/claude-api/composable/presets/python.md +2605 -0
  134. package/assets/skills/converted/claude-api/composable/presets/ruby.md +1146 -0
  135. package/assets/skills/converted/claude-api/composable/presets/shared.md +6478 -0
  136. package/assets/skills/converted/claude-api/composable/presets/typescript.md +2261 -0
  137. package/assets/skills/converted/docx/composable/BUNDLE.md +617 -0
  138. package/assets/skills/converted/docx/composable/INDEX.md +12 -0
  139. package/assets/skills/converted/docx/composable/VERSION +1 -0
  140. package/assets/skills/converted/docx/composable/mini/00-core.md +26 -0
  141. package/assets/skills/converted/docx/composable/mini/01-reading-converting.md +36 -0
  142. package/assets/skills/converted/docx/composable/mini/02-creating-setup-layout.md +85 -0
  143. package/assets/skills/converted/docx/composable/mini/03-creating-elements.md +257 -0
  144. package/assets/skills/converted/docx/composable/mini/04-editing-existing.md +57 -0
  145. package/assets/skills/converted/docx/composable/mini/05-xml-reference.md +128 -0
  146. package/assets/skills/converted/internal-comms/composable/BUNDLE.md +220 -0
  147. package/assets/skills/converted/internal-comms/composable/INDEX.md +11 -0
  148. package/assets/skills/converted/internal-comms/composable/VERSION +1 -0
  149. package/assets/skills/converted/internal-comms/composable/mini/00-core.md +30 -0
  150. package/assets/skills/converted/internal-comms/composable/mini/01-3p-updates.md +49 -0
  151. package/assets/skills/converted/internal-comms/composable/mini/02-company-newsletter.md +67 -0
  152. package/assets/skills/converted/internal-comms/composable/mini/03-faq-answers.md +32 -0
  153. package/assets/skills/converted/internal-comms/composable/mini/04-general-comms.md +18 -0
  154. package/assets/skills/converted/mcp-builder/composable/BUNDLE.md +2460 -0
  155. package/assets/skills/converted/mcp-builder/composable/INDEX.md +23 -0
  156. package/assets/skills/converted/mcp-builder/composable/VERSION +1 -0
  157. package/assets/skills/converted/mcp-builder/composable/mini/00-core.md +43 -0
  158. package/assets/skills/converted/mcp-builder/composable/mini/01-workflow-research-planning.md +54 -0
  159. package/assets/skills/converted/mcp-builder/composable/mini/02-implementation-process.md +78 -0
  160. package/assets/skills/converted/mcp-builder/composable/mini/03-naming-conventions.md +33 -0
  161. package/assets/skills/converted/mcp-builder/composable/mini/04-response-formats.md +21 -0
  162. package/assets/skills/converted/mcp-builder/composable/mini/05-pagination.md +24 -0
  163. package/assets/skills/converted/mcp-builder/composable/mini/06-transport.md +47 -0
  164. package/assets/skills/converted/mcp-builder/composable/mini/07-annotations.md +20 -0
  165. package/assets/skills/converted/mcp-builder/composable/mini/08-security.md +35 -0
  166. package/assets/skills/converted/mcp-builder/composable/mini/09-error-handling.md +32 -0
  167. package/assets/skills/converted/mcp-builder/composable/mini/10-testing-and-documentation.md +21 -0
  168. package/assets/skills/converted/mcp-builder/composable/mini/11-python-implementation.md +432 -0
  169. package/assets/skills/converted/mcp-builder/composable/mini/12-python-advanced-and-checklist.md +233 -0
  170. package/assets/skills/converted/mcp-builder/composable/mini/13-node-implementation.md +717 -0
  171. package/assets/skills/converted/mcp-builder/composable/mini/14-node-advanced-and-checklist.md +200 -0
  172. package/assets/skills/converted/mcp-builder/composable/mini/15-evaluation-design.md +200 -0
  173. package/assets/skills/converted/mcp-builder/composable/mini/16-evaluation-running.md +198 -0
  174. package/assets/skills/converted/mcp-builder/composable/presets/node-server.md +1381 -0
  175. package/assets/skills/converted/mcp-builder/composable/presets/python-server.md +1129 -0
  176. package/assets/skills/converted/pdf/composable/BUNDLE.md +1284 -0
  177. package/assets/skills/converted/pdf/composable/INDEX.md +14 -0
  178. package/assets/skills/converted/pdf/composable/VERSION +1 -0
  179. package/assets/skills/converted/pdf/composable/mini/00-core.md +46 -0
  180. package/assets/skills/converted/pdf/composable/mini/01-creation.md +176 -0
  181. package/assets/skills/converted/pdf/composable/mini/02-extraction.md +178 -0
  182. package/assets/skills/converted/pdf/composable/mini/03-merge-split-manipulate.md +240 -0
  183. package/assets/skills/converted/pdf/composable/mini/04-images-ocr.md +168 -0
  184. package/assets/skills/converted/pdf/composable/mini/05-encryption.md +51 -0
  185. package/assets/skills/converted/pdf/composable/mini/06-forms.md +300 -0
  186. package/assets/skills/converted/pdf/composable/mini/07-libraries-reference.md +89 -0
  187. package/assets/skills/converted/pptx/composable/BUNDLE.md +911 -0
  188. package/assets/skills/converted/pptx/composable/INDEX.md +12 -0
  189. package/assets/skills/converted/pptx/composable/VERSION +1 -0
  190. package/assets/skills/converted/pptx/composable/mini/00-core.md +37 -0
  191. package/assets/skills/converted/pptx/composable/mini/01-reading.md +37 -0
  192. package/assets/skills/converted/pptx/composable/mini/02-creating-from-scratch.md +422 -0
  193. package/assets/skills/converted/pptx/composable/mini/03-editing-templates.md +207 -0
  194. package/assets/skills/converted/pptx/composable/mini/04-design.md +89 -0
  195. package/assets/skills/converted/pptx/composable/mini/05-qa-and-rendering.md +91 -0
  196. package/assets/skills/converted/pptx/composable/presets/creating.md +659 -0
  197. package/assets/skills/converted/pptx/composable/presets/editing.md +485 -0
  198. package/assets/skills/converted/skill-creator/composable/BUNDLE.md +1681 -0
  199. package/assets/skills/converted/skill-creator/composable/INDEX.md +21 -0
  200. package/assets/skills/converted/skill-creator/composable/VERSION +1 -0
  201. package/assets/skills/converted/skill-creator/composable/mini/00-core.md +59 -0
  202. package/assets/skills/converted/skill-creator/composable/mini/01-creating-a-skill.md +27 -0
  203. package/assets/skills/converted/skill-creator/composable/mini/02-skill-writing-guide.md +71 -0
  204. package/assets/skills/converted/skill-creator/composable/mini/03-test-cases.md +21 -0
  205. package/assets/skills/converted/skill-creator/composable/mini/04-running-and-evaluating.md +128 -0
  206. package/assets/skills/converted/skill-creator/composable/mini/05-improving-the-skill.md +30 -0
  207. package/assets/skills/converted/skill-creator/composable/mini/06-blind-comparison.md +5 -0
  208. package/assets/skills/converted/skill-creator/composable/mini/07-description-optimization.md +74 -0
  209. package/assets/skills/converted/skill-creator/composable/mini/08-packaging.md +11 -0
  210. package/assets/skills/converted/skill-creator/composable/mini/09-environment-specific.md +38 -0
  211. package/assets/skills/converted/skill-creator/composable/mini/10-scripts-and-references.md +34 -0
  212. package/assets/skills/converted/skill-creator/composable/mini/11-json-schemas.md +414 -0
  213. package/assets/skills/converted/skill-creator/composable/mini/12-agent-grader.md +225 -0
  214. package/assets/skills/converted/skill-creator/composable/mini/13-agent-comparator.md +204 -0
  215. package/assets/skills/converted/skill-creator/composable/mini/14-agent-analyzer.md +276 -0
  216. package/assets/skills/converted/skill-creator/composable/presets/authoring.md +198 -0
  217. package/assets/skills/converted/skill-creator/composable/presets/evaluating.md +1334 -0
  218. package/assets/skills/converted/skill-creator/composable/presets/optimizing.md +160 -0
  219. package/assets/skills/converted/skill-creator/composable/presets.json +5 -0
  220. package/assets/skills/meta/ccs-skill-creator/composable/BUNDLE.md +465 -0
  221. package/assets/skills/meta/ccs-skill-creator/composable/INDEX.md +8 -0
  222. package/assets/skills/meta/ccs-skill-creator/composable/VERSION +1 -0
  223. package/assets/skills/meta/ccs-skill-creator/composable/mini/00-core.md +46 -0
  224. package/assets/skills/meta/ccs-skill-creator/composable/mini/01-create-new-skill.md +167 -0
  225. package/assets/skills/meta/ccs-skill-creator/composable/mini/02-convert-existing-skill.md +120 -0
  226. package/assets/skills/meta/ccs-skill-creator/composable/mini/03-review-and-maintain.md +112 -0
  227. package/assets/skills/sources/anthropic/PROVENANCE.md +3 -0
  228. package/assets/skills/sources/anthropic/claude-api/LICENSE.txt +202 -0
  229. package/assets/skills/sources/anthropic/docx/LICENSE.txt +30 -0
  230. package/assets/skills/sources/anthropic/internal-comms/LICENSE.txt +202 -0
  231. package/assets/skills/sources/anthropic/mcp-builder/LICENSE.txt +202 -0
  232. package/assets/skills/sources/anthropic/pdf/LICENSE.txt +30 -0
  233. package/assets/skills/sources/anthropic/pptx/LICENSE.txt +30 -0
  234. package/assets/skills/sources/anthropic/skill-creator/LICENSE.txt +202 -0
  235. package/assets/skills/sources/financial-analyst/PROVENANCE.md +1 -0
  236. package/assets/tools/hive.py +728 -0
  237. package/dist/cli.js +7494 -0
  238. package/package.json +40 -0
@@ -0,0 +1,71 @@
1
+ # Managed Agents — Overview
2
+
3
+ Managed Agents provisions a container per session as the agent's workspace. The agent loop runs on Anthropic's orchestration layer; the container is where the agent's *tools* execute — bash commands, file operations, code. You create a persisted **Agent** config (model, system prompt, tools, MCP servers, skills), then start **Sessions** that reference it. The session streams events back to you; you send user messages and tool results in.
4
+
5
+ ## ⚠️ THE MANDATORY FLOW: Agent (once) → Session (every run)
6
+
7
+ **Why agents are separate objects: versioning.** An agent is a persisted, versioned config — every update creates a new immutable version, and sessions pin to a version at creation time. This lets you iterate on the agent (tweak the prompt, add a tool) without breaking sessions already running, roll back if a change regresses, and A/B test versions side-by-side. None of that works if you `agents.create()` fresh on every run.
8
+
9
+ Every session references a pre-created `/v1/agents` object. Create the agent once, store the ID, and reuse it across runs.
10
+
11
+ | Step | Call | Frequency |
12
+ |---|---|---|
13
+ | 1 | `POST /v1/agents` — `model`, `system`, `tools`, `mcp_servers`, `skills` live here | **ONCE.** Store `agent.id` **and** `agent.version`. |
14
+ | 2 | `POST /v1/sessions` — `agent: "agent_abc123"` or `{type: "agent", id, version}` | **Every run.** String shorthand uses latest version. |
15
+
16
+ If you're about to write `sessions.create()` with `model`, `system`, or `tools` on the session body — **stop**. Those fields live on `agents.create()`. The session takes a *pointer* only.
17
+
18
+ **When generating code, separate setup from runtime.** `agents.create()` belongs in a setup script (or a guarded `if agent_id is None:` block), not at the top of the hot path. If the user's code calls `agents.create()` on every invocation, they're accumulating orphaned agents and paying the create latency for nothing. The correct shape is: create once → persist the ID (config file, env var, secrets manager) → every run loads the ID and calls `sessions.create()`.
19
+
20
+ **To change the agent's behavior, use `POST /v1/agents/{id}` — don't create a new one.** Each update bumps the version; running sessions keep their pinned version, new sessions get the latest (or pin explicitly via `{type: "agent", id, version}`). See `shared/managed-agents-core.md` → Agents → Versioning. To change `tools`/`mcp_servers`/`vault_ids` on **one running session** without touching the agent object, use `sessions.update()` — see `shared/managed-agents-core.md` → Updating the agent configuration mid-session.
21
+
22
+ ## Beta Headers
23
+
24
+ Managed Agents is in beta. The SDK sets required beta headers automatically:
25
+
26
+ | Beta Header | What it enables |
27
+ | ------------------------------ | ---------------------------------------------------- |
28
+ | `managed-agents-2026-04-01` | Agents, Environments, Sessions, Events, Session Resources, Session Threads, Outcomes, Multiagent, Vaults, Credentials, Memory Stores, Deployments |
29
+ | `skills-2025-10-02` | Skills API (for managing custom skill definitions) |
30
+ | `files-api-2025-04-14` | Files API for file uploads |
31
+
32
+ **Which beta header goes where:** The SDK sets `managed-agents-2026-04-01` automatically on `client.beta.{agents,environments,sessions,vaults,memory_stores,deployments,deployment_runs}.*` calls, and `files-api-2025-04-14` / `skills-2025-10-02` automatically on `client.beta.files.*` / `client.beta.skills.*` calls. You do NOT need to add the Skills or Files beta header when calling Managed Agents endpoints. **Exception — session-scoped file listing:** `client.beta.files.list({scope_id: session.id})` is a Files endpoint that takes a Managed Agents parameter, so it needs **both** headers. Pass `betas: ["managed-agents-2026-04-01"]` explicitly on that call (the SDK adds the Files header; you add the Managed Agents one). See `shared/managed-agents-environments.md` → Session outputs.
33
+
34
+
35
+ ## Reading Guide
36
+
37
+ | User wants to... | Read these files |
38
+ | -------------------------------------- | ------------------------------------------------------- |
39
+ | **Get started from scratch / "help me set up an agent"** | `shared/managed-agents-onboarding.md` — guided interview (WHERE→WHO→WHAT→WATCH), then emit code |
40
+ | Understand how the API works | `shared/managed-agents-core.md` |
41
+ | See the full endpoint reference | `shared/managed-agents-api-reference.md` |
42
+ | **Create an agent** (required first step) | `shared/managed-agents-core.md` (Agents section) + language file |
43
+ | Update/version an agent | `shared/managed-agents-core.md` (Agents → Versioning) — update, don't re-create |
44
+ | Create a session | `shared/managed-agents-core.md` + `{lang}/managed-agents/README.md` (cURL/C#: `curl/managed-agents.md`) |
45
+ | Configure tools and permissions | `shared/managed-agents-tools.md` |
46
+ | Set up MCP servers | `shared/managed-agents-tools.md` (MCP Servers section) |
47
+ | Stream events / handle tool_use | `shared/managed-agents-events.md` + language file |
48
+ | Get notified of session state changes via webhook (no polling) | `shared/managed-agents-webhooks.md` — Console-registered endpoint, HMAC verify, thin payload + fetch |
49
+ | Define an outcome / rubric-graded iterate loop | `shared/managed-agents-outcomes.md` — `user.define_outcome` event, grader, `span.outcome_evaluation_*` events |
50
+ | Coordinate multiple agents / subagents / threads | `shared/managed-agents-multiagent.md` — `multiagent: {type: "coordinator", agents: [...]}` on the agent, session threads, cross-posted tool confirmations |
51
+ | Set up environments | `shared/managed-agents-environments.md` + language file |
52
+ | Run tool execution in your own infra / VPC (self-hosted sandbox) | `shared/managed-agents-self-hosted-sandboxes.md` — `config:{type:"self_hosted"}`, `ANTHROPIC_ENVIRONMENT_KEY`, `EnvironmentWorker.run()` / `ant beta:worker poll` |
53
+ | Upload files / attach repos | `shared/managed-agents-environments.md` (Resources) |
54
+ | Give agents persistent memory across sessions | `shared/managed-agents-memory.md` — memory stores, `memory_store` session resource, preconditions, versions/redact |
55
+ | Define agents/environments as version-controlled YAML; drive the API from the shell | `shared/anthropic-cli.md` — `ant beta:agents create < agent.yaml`, `--transform`, `@file` inlining |
56
+ | Store credentials (MCP auth, API keys for CLIs/SDKs) | `shared/managed-agents-tools.md` (Vaults section) — `mcp_oauth` / `static_bearer` / `environment_variable` |
57
+ | Call a non-MCP API / CLI that needs a secret | `shared/managed-agents-tools.md` (Vaults section) — `environment_variable` credential, substituted at egress. If that doesn't fit (e.g. self-hosted sandboxes), `shared/managed-agents-client-patterns.md` Pattern 9 keeps the secret host-side via a custom tool |
58
+ | Run an agent on a recurring cron schedule | `shared/managed-agents-scheduled-deployments.md` — deployments, deployment runs, pause/auto-pause |
59
+
60
+ ## Common Pitfalls
61
+
62
+ - **Agent FIRST, then session — NO EXCEPTIONS** — the session's `agent` field accepts **only** a string ID or `{type: "agent", id, version}`. `model`, `system`, `tools`, `mcp_servers`, `skills` are **top-level fields on `POST /v1/agents`**, never on `sessions.create()`. If the user hasn't created an agent, that is step zero of every example.
63
+ - **Agent ONCE, not every run** — `agents.create()` is a setup step. Store the returned `agent_id` and reuse it; don't call `agents.create()` at the top of your hot path. If the agent's config needs to change, `POST /v1/agents/{id}` — each update creates a new version, and sessions can pin to a specific version for reproducibility.
64
+ - **MCP auth goes through vaults** — the agent's `mcp_servers` array declares `{type, name, url}` only (no auth). Credentials live in vaults (`client.beta.vaults.credentials.create`) and attach to sessions via `vault_ids`. Anthropic auto-refreshes OAuth tokens using the stored refresh token. Vaults also hold `environment_variable` credentials for non-MCP services (CLIs, SDKs, direct API calls) — substituted at egress, never visible in the sandbox.
65
+ - **Reconcile resources before the first run** — a session with a clear ask but a missing tool, credential, data mount, or context will discover the gap mid-run, then flail and give up. Before creating the session, check that every action in the task maps to a configured tool/MCP server, every MCP server has a vault credential, and every referenced file/host is mounted/reachable. When helping a user set one up, run the reconciliation in `shared/managed-agents-onboarding.md` → §3 Pre-flight viability check.
66
+ - **Stream to get events** — `GET /v1/sessions/{id}/events/stream` is the primary way to receive agent output in real-time.
67
+ - **SSE stream has no replay — reconnect with consolidation** — if the stream drops while a `agent.tool_use`, `agent.mcp_tool_use`, or `agent.custom_tool_use` is pending resolution (`user.tool_confirmation` for the first two, `user.custom_tool_result` for the last one), the session deadlocks (client disconnects → session idles → reconnect happens → no client resolution happens). On every (re)connect: open stream with `GET /v1/sessions/{id}/events/stream` , fetch `GET /v1/sessions/{id}/events`, dedupe by event ID, then proceed. See `shared/managed-agents-events.md` → Reconnecting after a dropped stream.
68
+ - **Don't trust HTTP-library timeouts as wall-clock caps** — `requests` `timeout=(c, r)` and `httpx.Timeout(n)` are *per-chunk* read timeouts; they reset every byte, so a trickling connection can block indefinitely. For a hard deadline on raw-HTTP polling, track `time.monotonic()` at the loop level and bail explicitly. Prefer the SDK's `sessions.events.stream()` / `session.events.list()` over hand-rolled HTTP. See `shared/managed-agents-events.md` → Receiving Events.
69
+ - **Messages queue** — you can send events while the session is `running` or `idle`; they're processed in order. No need to wait for a response before sending the next message.
70
+ - **Environment `config.type` is `"cloud"` or `"self_hosted"`** — `cloud` runs the container on Anthropic's infrastructure; `self_hosted` moves tool execution to your own (see `shared/managed-agents-self-hosted-sandboxes.md`).
71
+ - **Archive is permanent on every resource** — archiving an agent, environment, session, vault, credential, or memory store makes it read-only with no unarchive. For agents, environments, and memory stores specifically, archived resources cannot be referenced by new sessions (existing sessions continue). Do not call `.archive()` on a production agent, environment, or memory store as cleanup — **always confirm with the user before archiving**.
@@ -0,0 +1,278 @@
1
+ # Managed Agents — Core Concepts
2
+
3
+ ## Architecture
4
+
5
+ Managed Agents is built around four core concepts:
6
+
7
+ | Concept | Endpoint | What it is |
8
+ |---|---|---|
9
+ | **Agent** | `/v1/agents` | A persisted, versioned object defining the agent's capabilities and persona: model, system prompt, tools, MCP servers, skills. **Must be created before starting a session.** See the Agents section below. |
10
+ | **Session** | `/v1/sessions` | A stateful interaction with an agent. References a pre-created agent by ID + an environment + initial instructions. Produces an event stream. |
11
+ | **Environment** | `/v1/environments` | A template defining the configuration for container provisioning. |
12
+ | **Container** | N/A | An isolated compute instance where the agent's **tools** execute (bash, file ops, code). The agent loop does not run here — it runs on Anthropic's orchestration layer and acts on the container via tool calls. |
13
+
14
+ ```
15
+ ┌─────────────────────────────────────┐
16
+ │ Anthropic orchestration layer │
17
+ Agent (config) ───────▶│ (agent loop: Claude + tool calls) │
18
+ └──────────────┬──────────────────────┘
19
+ │ tool calls
20
+
21
+ Environment (template) ──▶ Container (tool execution workspace)
22
+
23
+ Session ─┤
24
+ ├── Resources (files, repos, memory stores — attached at startup)
25
+ ├── Vault IDs (MCP credential references)
26
+ └── Conversation (event stream in/out)
27
+ ```
28
+
29
+ > **Agent creation is a prerequisite.** Sessions reference a pre-created agent by ID — `model`/`system`/`tools` live on the agent object, never on the session. Every flow starts with `POST /v1/agents`.
30
+
31
+ ---
32
+
33
+ ## Session Lifecycle
34
+
35
+ ```
36
+ rescheduling → running ↔ idle → terminated
37
+ ```
38
+
39
+ | Status | Description |
40
+ | -------------- | ------------------------------------------------------------------ |
41
+ | `idle` | Agent has finished the current task, and is awaiting input. It's either waiting for input to continue working via a `user.message` or blocked awaiting a `user.custom_tool_result` or `user.tool_confirmation`. The `stop_reason` attached contains more information about why the Agent has stopped working. |
42
+ | `running` | Session has starting running, and the Agent is actively doing work. |
43
+ | `rescheduling` | Session is (re)scheduling after a retryable error has occurred, ready to be picked up by the orchestration system. |
44
+ | `terminated` | Session has terminated, entering an irreversible and unusable state. |
45
+
46
+ - Events can be sent when the session is `running` or `idle`. Messages are queued and processed in order.
47
+ - The agent transitions `idle → running` when it receives a new event, then back to `idle` when done.
48
+ - Errors surface as `session.error` events in the stream, not as a status value.
49
+
50
+ Every session has a live trace view in the Anthropic Console at `https://platform.claude.com/workspaces/default/sessions/{session_id}`. Print this URL immediately after creating a session so the user can watch tool calls and messages stream in real time. The `default` workspace segment auto-resolves to the session's actual workspace on load, so you don't need the workspace id.
51
+
52
+ ### Built-in session features
53
+
54
+ - **Context compaction** — if you approach max context, the API automatically condenses session history to keep the interaction going
55
+ - **Prompt caching** — historical repeated tokens are cached, reducing processing time and cost
56
+ - **Extended thinking** — on by default, returned as `agent.thinking` events
57
+
58
+ ### Session operations
59
+
60
+ | Operation | Notes |
61
+ |---|---|
62
+ | List / fetch | Paginated list or single resource by ID |
63
+ | Update | Only `title` is updatable |
64
+ | Archive | Session becomes **read-only**. Not reversible. |
65
+ | Delete | Permanently deletes session, event history, container, and checkpoints. |
66
+
67
+ These are ops/inspection calls — typically made from a terminal, not application code. From the shell (see `shared/anthropic-cli.md`):
68
+
69
+ ```sh
70
+ ant beta:sessions list --transform '{id,title,status,created_at}' --format jsonl
71
+ ant beta:sessions retrieve --session-id "$SID"
72
+ ant beta:sessions:events stream --session-id "$SID" # watch events live
73
+ ant beta:sessions archive --session-id "$SID"
74
+ ant beta:sessions delete --session-id "$SID"
75
+ ```
76
+
77
+ ---
78
+
79
+ ## Sessions
80
+
81
+ A session is a running agent instance inside an environment.
82
+
83
+ ### Session Object
84
+
85
+ Key fields returned by the API:
86
+
87
+ | Field | Type | Description |
88
+ | --------------- | -------- | --------------------------------------------------- |
89
+ | `type` | string | Always `"session"` |
90
+ | `id` | string | Unique session ID |
91
+ | `title` | string | Human-readable title |
92
+ | `status` | string | `idle`, `running`, `rescheduling`, `terminated` |
93
+ | `created_at` | string | ISO 8601 timestamp |
94
+ | `updated_at` | string | ISO 8601 timestamp |
95
+ | `archived_at` | string | ISO 8601 timestamp (nullable) |
96
+ | `environment_id` | string | Environment ID |
97
+ | `agent` | object | Agent configuration |
98
+ | `resources` | array | Attached files, repos, and memory stores |
99
+ | `metadata` | object | User-provided key-value pairs (max 8 keys) |
100
+ | `usage` | object | Token usage statistics |
101
+
102
+ ### Creating a session
103
+
104
+ **A session is meaningless without an agent.** Sessions reference a pre-created agent by ID. Create the agent first via `agents.create()`, then reference it:
105
+
106
+ ```ts
107
+ // 1. Create the agent (reusable, versioned)
108
+ const agent = await client.beta.agents.create(
109
+ {
110
+ name: "Coding Assistant",
111
+ model: "claude-opus-4-8",
112
+ system: "You are a helpful coding agent.",
113
+ tools: [{ type: "agent_toolset_20260401"}],
114
+ },
115
+ );
116
+
117
+ // 2. Start a session that references it
118
+ const session = await client.beta.sessions.create(
119
+ {
120
+ agent: agent.id, // string shorthand → latest version. Or: { type: "agent", id: agent.id, version: agent.version }
121
+ environment_id: environmentId,
122
+ title: "Hello World Session",
123
+ },
124
+ );
125
+ ```
126
+
127
+ > 💡 **Watch it live in Console.** While developing, print a link so you can click through to the session UI instead of parsing the event stream: `https://platform.claude.com/workspaces/default/sessions/{session.id}`. The `default` workspace segment auto-resolves to the session's actual workspace on load, so you don't need to know the workspace id. Include this `print`/`console.log` in code you generate for users who are iterating locally.
128
+
129
+ **Session creation parameters:**
130
+
131
+ | Field | Type | Required | Description |
132
+ | --------------- | -------- | -------- | ---------------------------------------------- |
133
+ | `agent` | string or object | **Yes** | Three forms: string shorthand `"agent_abc123"` (latest version); pinned `{type: "agent", id, version}`; or `{type: "agent_with_overrides", id, version?, ...}` to override `model`/`system`/`tools`/`mcp_servers`/`skills` for this session only — see § Override agent configuration for a session |
134
+ | `environment_id`| string | **Yes** | Environment ID |
135
+ | `title` | string | No | Human-readable name (appears in logs/dashboards) |
136
+ | `resources` | array | No | Files, GitHub repos, or memory stores, attached to the container at startup. Memory stores are session-create-only (not addable via `resources.add()`). |
137
+ | `vault_ids` | array | No | Vault IDs (`vlt_*`) — MCP credentials with auto-refresh + `environment_variable` secrets substituted at egress. See `shared/managed-agents-tools.md` → Vaults. |
138
+ | `metadata` | object | No | User-provided key-value pairs |
139
+
140
+ **Agent configuration fields** (passed to `agents.create()`, not `sessions.create()`):
141
+
142
+ | Field | Type | Required | Description |
143
+ | ------------- | -------- | -------- | ---------------------------------------------- |
144
+ | `name` | string | **Yes** | Human-readable name (1-256 chars) |
145
+ | `model` | string or object | **Yes** | Claude model ID (bare string, or `{id, speed}` object). All Claude 4.5+ models supported. |
146
+ | `system` | string | No | System prompt — defines the agent's behavior (up to 100K chars) |
147
+ | `tools` | array | No | Encompasses three kinds: (1) pre-built Claude Agent tools (`agent_toolset_20260401`), (2) MCP tools (`mcp_toolset`), and (3) custom client-side tools. Max 128. |
148
+ | `mcp_servers` | array | No | MCP server connections — standardized third-party capabilities (e.g. GitHub, Asana). Max 20, unique names. See `shared/managed-agents-tools.md` → MCP Servers. |
149
+ | `skills` | array | No | Customized "best-practices" context with progressive disclosure. Max 20. See `shared/managed-agents-tools.md` → Skills. |
150
+ | `description` | string | No | Description of the agent (up to 2048 chars) |
151
+ | `multiagent` | object | No | `{type: "coordinator", agents: [...]}` — roster this agent may delegate to. See `shared/managed-agents-multiagent.md`. |
152
+ | `metadata` | object | No | Arbitrary key-value pairs (max 16, keys ≤64 chars, values ≤512 chars) |
153
+
154
+ ---
155
+
156
+ ## Agents
157
+
158
+ **This is where every Managed Agents flow begins.** The agent object is a persisted, versioned configuration — you create it once, then reference it by ID every time you start a session. No agent → no session.
159
+
160
+ ### Agent Object
161
+
162
+ The API is **flat** — `model`, `system`, `tools` etc. are top-level fields, not wrapped in an `agent:{}` sub-object.
163
+
164
+ | Field | Type | Required | Description |
165
+ | ------------------ | -------- | -------- | -------------------------------------------------- |
166
+ | `name` | string | Yes | Human-readable name |
167
+ | `model` | string | Yes | Claude model ID |
168
+ | `system` | string | No | System prompt |
169
+ | `tools` | array | No | Agent toolset / MCP toolset / custom tools |
170
+ | `mcp_servers` | array | No | MCP server connections |
171
+ | `skills` | array | No | Skill references (max 20) |
172
+ | `description` | string | No | Description of the agent |
173
+ | `multiagent` | object | No | Coordinator roster — see `shared/managed-agents-multiagent.md` |
174
+ | `metadata` | object | No | Arbitrary key-value pairs |
175
+
176
+ ### Lifecycle: create once, run many, update in place
177
+
178
+ The agent is a **persistent resource**, not a per-run parameter. The intended pattern:
179
+
180
+ ```
181
+ ┌─ setup (once) ─────────┐ ┌─ runtime (every invocation) ─┐
182
+ │ agents.create() │ │ sessions.create( │
183
+ │ → store agent_id │ ──→ │ agent={type:..., id: ID} │
184
+ │ in config/env/db │ │ ) │
185
+ └────────────────────────┘ └──────────────────────────────┘
186
+ ```
187
+
188
+ **Anti-pattern:** calling `agents.create()` at the top of every script run. This accumulates orphaned agent objects, pays create latency on every invocation, and defeats the versioning model. If you see `agents.create()` in a function that's called per-request or per-cron-tick, that's wrong — hoist it to one-time setup and persist the ID.
189
+
190
+ > **Recommended — define agents and environments as YAML + apply via the `ant` CLI.** The split is **CLI for the control plane, SDK for the data plane**: agents and environments are relatively static resources you manage with `ant` (version-controlled YAML, applied from CI); sessions are dynamic and driven by your application through the SDK. See `shared/anthropic-cli.md` → *Version-controlled Managed Agents resources* for the `ant beta:agents create < agent.yaml` / `update --version N` flow. The SDK `agents.create()` call shown elsewhere in this doc is the in-code equivalent — use it when you need to provision programmatically, but prefer the YAML flow for anything a human maintains.
191
+
192
+ ### Versioning
193
+
194
+ Each `POST /v1/agents/{id}` (update) creates a new immutable version (numeric timestamp, e.g. `1772585501101368014`). The agent's history is append-only — you can't edit a past version.
195
+
196
+ **Why version:**
197
+ - **Reproducibility** — pin a session to a known-good config: `{type: "agent", id, version: 3}`
198
+ - **Safe iteration** — update the agent without breaking sessions already running on the old version
199
+ - **Rollback** — if a new system prompt regresses, pin new sessions back to the prior version while you debug
200
+
201
+ **`version` is optional.** Omit it (or use the string shorthand `agent="agent_abc123"`) to get the latest version at session-creation time. Pass it explicitly (`{type: "agent", id, version: N}`) to pin for reproducibility.
202
+
203
+ **Getting the version to pin:** `agents.create()` and `agents.update()` both return `version` in the response. Store it alongside `agent_id`. To fetch the current latest for an existing agent: `GET /v1/agents/{id}` → `.version`.
204
+
205
+ **When to update vs create new:** Update (`POST /v1/agents/{id}`) when it's conceptually the same agent with tweaked behavior (better prompt, extra tool). Create a new agent when it's a different persona/purpose. Rule of thumb: if you'd give it the same `name`, update.
206
+
207
+ ### Agent Endpoints
208
+
209
+ | Operation | Method | Path |
210
+ | ---------------- | -------- | ------------------------------------- |
211
+ | Create | `POST` | `/v1/agents` |
212
+ | List | `GET` | `/v1/agents` |
213
+ | Get | `GET` | `/v1/agents/{id}` |
214
+ | Update | `POST` | `/v1/agents/{id}` |
215
+ | Archive | `POST` | `/v1/agents/{id}/archive` |
216
+
217
+ > ⚠️ **Archive is permanent.** Archiving makes the agent read-only: existing sessions continue to run, but **new sessions cannot reference it**, and there is no unarchive. Since agents have no `delete`, this is the terminal lifecycle state. Never archive a production agent as routine cleanup — confirm with the user first.
218
+
219
+ ### Using an Agent in a Session
220
+
221
+ Reference the agent by string ID (latest version) or by object with an explicit version:
222
+
223
+ ```python
224
+ # String shorthand — uses the agent's latest version
225
+ session = client.beta.sessions.create(
226
+ agent=agent.id,
227
+ environment_id=environment_id,
228
+ )
229
+
230
+ # Or pin to a specific version (int)
231
+ session = client.beta.sessions.create(
232
+ agent={"type": "agent", "id": agent.id, "version": agent.version},
233
+ environment_id=environment_id,
234
+ )
235
+ ```
236
+
237
+ ### Override agent configuration for a session
238
+
239
+ The third `agent` form, `agent_with_overrides`, replaces parts of the agent's configuration for **a single session** — try a different model or grant an extra tool without versioning the agent. Pass `id` (and optionally `version`; omitted = latest, same default as the other two forms) plus any of `model`, `system`, `tools`, `mcp_servers`, `skills`:
240
+
241
+ ```python
242
+ session = client.beta.sessions.create(
243
+ agent={
244
+ "type": "agent_with_overrides",
245
+ "id": agent.id,
246
+ "model": "claude-opus-4-8", # replace the agent's model for this session
247
+ "system": None, # clear the system prompt for this session
248
+ },
249
+ environment_id=environment_id,
250
+ )
251
+ ```
252
+
253
+ Each overridable field follows tri-state rules:
254
+ - **Omit** → the session inherits the value from the referenced agent version.
255
+ - **`null` (or `[]` for list fields)** → the session runs with that field cleared. Applies in full to `system`, `mcp_servers`, `skills`. Two exceptions: `model` is never clearable (`model: null` → 400 `agent_model_required`); clearing `tools` returns 400 when the session's effective `skills` is non-empty (skills require the `read` tool), otherwise `tools: null` / `tools: []` clears.
256
+ - **A value** → replaces the agent's value **in full**. Overrides never merge — a `tools` override must list every tool the session should have.
257
+
258
+ Overrides are session-local: they do **not** modify the agent resource or create a new agent version. The response's `agent` object reflects the post-override configuration, while its `id` and `version` still identify the base agent — so you can trace a session back to its base. In multiagent sessions, overrides apply to the coordinator and its `{type: "self"}` copies; roster agents referenced by ID always use their own as-created configuration (see `shared/managed-agents-multiagent.md`).
259
+
260
+ ### Updating the agent configuration mid-session
261
+
262
+ `sessions.update()` can change `agent.tools`, `agent.mcp_servers` (including permission policies), and `vault_ids` on an **existing** session. This is a **session-local override** — it does not create a new agent version and does not propagate back to the agent object. The provided arrays are **full replacements**; to append one tool, `GET` the session, modify, and `POST` back. The session must be `idle` — interrupt first if running.
263
+
264
+ Only `tools` and `mcp_servers` can change after a session is created — to run with a `model`, `system`, or `skills` other than the agent's values, use `agent_with_overrides` at create time (above). The agent's configured `system` field is fixed for the session's lifetime; you can still **replace the effective system prompt between turns** by sending a `system.message` event (see `shared/managed-agents-events.md` § Updating the system prompt mid-session).
265
+
266
+ ```python
267
+ client.beta.sessions.update(
268
+ session.id,
269
+ agent={
270
+ "tools": [
271
+ {"type": "agent_toolset_20260401"},
272
+ {"type": "mcp_toolset", "mcp_server_name": "linear"},
273
+ ],
274
+ "mcp_servers": [{"type": "url", "name": "linear", "url": "https://mcp.linear.app/sse"}],
275
+ },
276
+ vault_ids=["vlt_..."],
277
+ )
278
+ ```
@@ -0,0 +1,219 @@
1
+ # Managed Agents — Environments & Resources
2
+
3
+ ## Environments
4
+
5
+ Creating a session requires an `environment_id`. Environments are **reusable configuration templates** for spinning up containers in Anthropic's infrastructure — you might create different environments for different use cases (e.g. data visualization vs web development, with different package sets). Anthropic handles scaling, container lifecycle, and work orchestration.
6
+
7
+ **Environment names must be unique.** Creating an environment with an existing name returns 409.
8
+
9
+ ### Networking
10
+
11
+ | Network Policy | Description |
12
+ | ---------------- | ------------------------------------------------------------- |
13
+ | `unrestricted` | Full egress (except legal blocklist) |
14
+ | `limited` | Deny-by-default; opt in via `allowed_hosts` / `allow_package_managers` / `allow_mcp_servers` |
15
+
16
+ ```json
17
+ {
18
+ "networking": {
19
+ "type": "limited",
20
+ "allow_package_managers": true,
21
+ "allow_mcp_servers": true,
22
+ "allowed_hosts": ["api.example.com"]
23
+ }
24
+ }
25
+ ```
26
+
27
+ All three `limited` fields are optional. `allow_package_managers` (default `false`) permits PyPI/npm/etc.; `allow_mcp_servers` (default `false`) permits the agent's configured MCP server endpoints without listing them in `allowed_hosts`.
28
+
29
+ **MCP caveat:** Under `limited` networking, either set `allow_mcp_servers: true` or add each MCP server domain to `allowed_hosts`. Otherwise the container can't reach them and tools silently fail.
30
+
31
+ ### Creating an environment
32
+
33
+ The SDK adds `managed-agents-2026-04-01` automatically. TypeScript:
34
+
35
+ ```ts
36
+ const env = await client.beta.environments.create({
37
+ name: "my_env",
38
+ config: {
39
+ type: "cloud",
40
+ networking: { type: "unrestricted" },
41
+ },
42
+ });
43
+ ```
44
+
45
+ ### Self-hosted sandboxes
46
+
47
+ To run tool execution in **your own infrastructure** instead of Anthropic's, set `config: {type: "self_hosted"}` — the agent loop stays on Anthropic's side, but `bash` / file ops / code execute in a container you control via an outbound-polling worker. The `networking` block does not apply (you control egress). Resource mounting (`file`, `github_repository`) and memory stores behave differently — see `shared/managed-agents-self-hosted-sandboxes.md` for the worker, credentials, and cloud-vs-self-hosted comparison.
48
+
49
+ ### Environment CRUD
50
+
51
+ | Operation | Method | Path | Notes |
52
+ | ---------------- | -------- | ------------------------------------------ | ----- |
53
+ | Create | `POST` | `/v1/environments` | |
54
+ | List | `GET` | `/v1/environments` | Paginated (`limit`, `after_id`, `before_id`) |
55
+ | Get | `GET` | `/v1/environments/{id}` | |
56
+ | Update | `POST` | `/v1/environments/{id}` | Changes apply only to **new** containers; existing sessions keep their original config |
57
+ | Delete | `DELETE` | `/v1/environments/{id}` | Returns 204. |
58
+ | Archive | `POST` | `/v1/environments/{id}/archive` | Makes it **read-only**; existing sessions continue, new sessions cannot reference it. No unarchive — terminal state. |
59
+
60
+ ---
61
+
62
+ ## Resources
63
+
64
+ Attach files, GitHub repositories, and memory stores to a session. **Session creation blocks until all resources are mounted** — the container won't go `running` until every file and repo is in place. Max **999 file resources** per session. Multiple GitHub repositories per session are supported. For `type: "memory_store"` resources (persistent cross-session memory — max 8 per session), see `shared/managed-agents-memory.md`.
65
+
66
+ ### File Uploads (input — host → agent)
67
+
68
+ Upload a file first via the Files API, then reference by `file_id` + `mount_path`:
69
+
70
+ ```ts
71
+ // 1. Upload
72
+ const file = await client.beta.files.upload({
73
+ file: fs.createReadStream("data.csv"),
74
+ });
75
+
76
+ // 2. Attach as a session resource
77
+ const session = await client.beta.sessions.create({
78
+ agent: agent.id,
79
+ environment_id: envId,
80
+ resources: [
81
+ { type: "file", file_id: file.id, mount_path: "/workspace/data.csv" }
82
+ ],
83
+ });
84
+ ```
85
+
86
+ **`mount_path` is required** and must be absolute. Parent directories are created automatically. Agent working directory defaults to `/workspace`. Files are mounted read-only — the agent writes modified versions to new paths.
87
+
88
+ ### Session outputs (output — agent → host)
89
+
90
+ The agent can write files to `/mnt/session/outputs/` during a session. These are automatically captured by the Files API and can be listed and downloaded afterwards:
91
+
92
+ ```ts
93
+ // After the turn completes, list output files scoped to this session:
94
+ for await (const f of client.beta.files.list({
95
+ scope_id: session.id,
96
+ betas: ["managed-agents-2026-04-01"],
97
+ })) {
98
+ console.log(f.filename, f.size_bytes);
99
+ const resp = await client.beta.files.download(f.id);
100
+ const text = await resp.text();
101
+ }
102
+ ```
103
+
104
+ **Requirements:**
105
+ - The `write` tool (or `bash`) must be enabled for the agent to create output files.
106
+ - Session-scoped `files.list` / `files.download` captures outputs written to `/mnt/session/outputs/`.
107
+ - The filter parameter is **`scope_id`** (REST query param `?scope_id=<session_id>`). The SDK's files resource auto-adds only the `files-api-2025-04-14` header, so pass `betas: ["managed-agents-2026-04-01"]` explicitly (or both headers on raw HTTP) — without it the API may reject `scope_id` as an unknown field. Requires `@anthropic-ai/sdk` ≥ 0.88.0 / `anthropic` (Python) ≥ 0.92.0 — older versions don't type `scope_id`. The `ant` CLI does **not** expose this flag yet; use the SDK or curl.
108
+ - Pass the session ID returned by `sessions.create()` verbatim (e.g. `sesn_011CZx...`) — the API validates the prefix.
109
+ - There's a brief indexing lag (~1–3s) between `session.status_idle` and output files appearing in `files.list`. Retry once or twice if empty.
110
+
111
+ > **Fallback when `scope_id` filtering is unavailable** (older SDK, or endpoint returns an error): send a follow-up `user.message` asking the agent to `read` each file under `/mnt/session/outputs/` and return the contents. The agent streams the file bodies back as `agent.message` text. This works for text files only and costs output tokens — use it to unblock, not as the primary path.
112
+
113
+ This gives you a bidirectional file bridge: upload reference data in, download agent artifacts out.
114
+
115
+ ### GitHub Repositories
116
+
117
+ Clones a GitHub repository into the session container during initialization, before the agent begins execution. The agent can read, edit, commit, and push via `bash` (`git`). Multiple repositories per session are supported — add one `resources` entry per repo. Repositories are cached, so future sessions that use the same repository start faster.
118
+
119
+ Repositories are attached for the lifetime of the session — to change which repositories are mounted, create a new session. You **can** rotate a repository's `authorization_token` on a running session via `client.beta.sessions.resources.update(resource_id, {session_id, authorization_token})`; the resource `id` is returned at session creation and by `resources.list()`.
120
+
121
+ **Fields:**
122
+
123
+ | Field | Required | Notes |
124
+ |---|---|---|
125
+ | `type` | ✅ | `"github_repository"` |
126
+ | `url` | ✅ | The GitHub repository URL |
127
+ | `authorization_token` | ✅ | GitHub Personal Access Token with repository access. **Never echoed in API responses.** |
128
+ | `mount_path` | ❌ | Path where the repository will be cloned. Defaults to `/workspace/<repo-name>`. |
129
+ | `checkout` | ❌ | `{type: "branch", name: "..."}` or `{type: "commit", sha: "..."}`. Defaults to the repo's default branch. |
130
+
131
+ **Token permission levels** (fine-grained PATs):
132
+ - `Contents: Read` — clone only
133
+ - `Contents: Read and write` — push changes and create pull requests
134
+
135
+ **How auth works:** `authorization_token` is never placed inside the container. `git pull` / `git push` and GitHub REST calls against the attached repository are routed through an Anthropic-side git proxy that injects the token after the request leaves the sandbox. Code running in the container — including anything the agent writes — cannot read or exfiltrate it.
136
+
137
+ > ‼️ **To generate pull requests** you also need GitHub **MCP server** access — the `github_repository` resource gives filesystem + git access only. See `shared/managed-agents-tools.md` → MCP Servers. The PR workflow is: edit files in the mounted repo → push branch via `bash` (authenticated via the git proxy using `authorization_token`) → create PR via the MCP `create_pull_request` tool (authenticated via the vault).
138
+
139
+ **TypeScript:**
140
+
141
+ ```ts
142
+ // 1. Create the agent — declare GitHub MCP (no auth here)
143
+ const agent = await client.beta.agents.create(
144
+ {
145
+ name: 'GitHub Agent',
146
+ model: 'claude-opus-4-8',
147
+ mcp_servers: [
148
+ { type: 'url', name: 'github', url: 'https://api.githubcopilot.com/mcp/' },
149
+ ],
150
+ tools: [
151
+ { type: 'agent_toolset_20260401', default_config: { enabled: true } },
152
+ { type: 'mcp_toolset', mcp_server_name: 'github' },
153
+ ],
154
+ },
155
+ );
156
+
157
+ // 2. Start a session — attach vault for MCP auth + mount the repo
158
+ const session = await client.beta.sessions.create({
159
+ agent: agent.id,
160
+ environment_id: envId,
161
+ vault_ids: [vaultId], // vault contains the GitHub MCP OAuth credential
162
+ resources: [
163
+ {
164
+ type: 'github_repository',
165
+ url: 'https://github.com/owner/repo',
166
+ authorization_token: process.env.GITHUB_TOKEN, // repo clone token (≠ MCP auth)
167
+ checkout: { type: 'branch', name: 'main' },
168
+ },
169
+ ],
170
+ });
171
+ ```
172
+
173
+ **Python:**
174
+
175
+ ```python
176
+ import os
177
+
178
+ agent = client.beta.agents.create(
179
+ name="GitHub Agent",
180
+ model="claude-opus-4-8",
181
+ mcp_servers=[{
182
+ "type": "url",
183
+ "name": "github",
184
+ "url": "https://api.githubcopilot.com/mcp/",
185
+ }],
186
+ tools=[
187
+ {"type": "agent_toolset_20260401", "default_config": {"enabled": True}},
188
+ {"type": "mcp_toolset", "mcp_server_name": "github"},
189
+ ],
190
+ )
191
+
192
+ session = client.beta.sessions.create(
193
+ agent=agent.id,
194
+ environment_id=env_id,
195
+ vault_ids=[vault_id], # vault contains the GitHub MCP OAuth credential
196
+ resources=[{
197
+ "type": "github_repository",
198
+ "url": "https://github.com/owner/repo",
199
+ "authorization_token": os.environ["GITHUB_TOKEN"], # repo clone token (≠ MCP auth)
200
+ "checkout": {"type": "branch", "name": "main"},
201
+ }],
202
+ )
203
+ ```
204
+
205
+ ---
206
+
207
+ ## Files API
208
+
209
+ Upload and manage files for use as session resources, and download files the agent wrote to `/mnt/session/outputs/`.
210
+
211
+ | Operation | Method | Path | SDK |
212
+ | ---------------- | -------- | ------------------------------------- | --- |
213
+ | Upload | `POST` | `/v1/files` | `client.beta.files.upload({ file })` |
214
+ | List | `GET` | `/v1/files?scope_id=...` | `client.beta.files.list({ scope_id, betas: ["managed-agents-2026-04-01"] })` |
215
+ | Get Metadata | `GET` | `/v1/files/{id}` | `client.beta.files.retrieveMetadata(id)` |
216
+ | Download | `GET` | `/v1/files/{id}/content` | `client.beta.files.download(id)` → `Response` |
217
+ | Delete | `DELETE` | `/v1/files/{id}` | `client.beta.files.delete(id)` |
218
+
219
+ The `scope_id` filter on List scopes the results to files written to `/mnt/session/outputs/` by that session. Without the filter, you get all files uploaded to your account.