[ PROMPT_NODE_23814 ]
managed-agents
[ SKILL_DOCUMENTATION ]
# 托管智能体 (Managed Agents) — cURL / 原生 HTTP
当用户需要发送原生 HTTP 请求或在没有 SDK 的情况下工作时,请使用这些示例。
## 设置
bash
export ANTHROPIC_API_KEY="your-api-key"
# 通用请求头
HEADERS=(
-H "Content-Type: application/json"
-H "x-api-key: $ANTHROPIC_API_KEY"
-H "anthropic-version: 2023-06-01"
-H "anthropic-beta: managed-agents-2026-04-01"
)
---
## 创建环境
bash
curl -X POST https://api.anthropic.com/v1/environments
"${HEADERS[@]}"
-d '{
"name": "my-dev-env",
"config": {
"type": "cloud",
"networking": { "type": "unrestricted" }
}
}'
### 限制网络访问
bash
curl -X POST https://api.anthropic.com/v1/environments
"${HEADERS[@]}"
-d '{
"name": "restricted-env",
"config": {
"type": "cloud",
"networking": {
"type": "package_managers_and_custom",
"allowed_hosts": ["api.example.com"]
}
}
}'
---
## 创建智能体 (必需的第一步)
> ⚠️ **没有内联智能体配置。** 在 `managed-agents-2026-04-01` 版本下,`model`(模型)、`system`(系统提示词)和 `tools`(工具)是 `POST /v1/agents` 的顶级字段,而不是会话(session)的字段。请务必先创建智能体 — 会话仅接受 `"agent": {"type": "agent", "id": "..."}`。
### 最小化配置
bash
# 1. 创建智能体
curl -X POST https://api.anthropic.com/v1/agents
"${HEADERS[@]}"
-d '{
"name": "Coding Assistant",
"model": "claude-opus-4-7",
"tools": [{ "type": "agent_toolset_20260401" }]
}'
# → { "id": "agent_abc123", ... }
# 2. 启动会话
curl -X POST https://api.anthropic.com/v1/sessions
"${HEADERS[@]}"
-d '{
"agent": { "type": "agent", "id": "agent_abc123", "version": "1772585501101368014" },
"environment_id": "env_abc123"
}'
### 包含系统提示词、自定义工具和 GitHub 仓库
bash
# 1. 创建智能体
curl -X POST https://api.anthropic.com/v1/agents
"${HEADERS[@]}"
-d '{
"name": "Code Reviewer",
"model": "claude-opus-4-7",
"system": "You are a senior code reviewer. Be thorough and constructive.",
"tools": [
{ "type": "agent_toolset_20260401" },
{
"type": "custom",
"name": "run_linter",
"description": "Run the project linter on a file",
"input_schema": {
"type": "object",
"properties": {
"file_path": { "type": "string", "description": "Path to lint" }
},
"required": ["file_path"]
}
}
}