SPB Git

Repository Public Research preview

managed-agents.md 2.1 KB 38 lines markdown

1# Managed Agents (beta)23Anthropic runs the agent loop and a per-session sandbox (shell, files, code execution). The SDK4adds the beta header for `client.beta.agents`, `.environments`, `.sessions` calls.56Order: **environment** (once) → **agent** (once) → **session** (per run). Agents and environments7are persistent and versioned: create them in setup, store the ids, reuse them. Never create an8agent inside a request handler. Do not archive or delete resources the user did not ask you to.910```python11environment = client.beta.environments.create(12    name="my-env", config={"type": "cloud", "networking": {"type": "limited"}})13agent = client.beta.agents.create(14    name="My agent", model="claude-opus-5-5", system="…",15    tools=[{"type": "agent_toolset_20260401",16            "default_config": {"enabled": True, "permission_policy": {"type": "auto"}},17            "configs": [{"name": "web_fetch", "enabled": False}, {"name": "web_search", "enabled": False}]}])18session = client.beta.sessions.create(agent=agent.id, environment_id=environment.id)19```2021Talking to a session:22231. Open the event stream **first**: `client.beta.sessions.events.stream(session.id)`.242. Send: `client.beta.sessions.events.send(session.id, events=[{"type": "user.message", "content": [{"type": "text", "text": "…"}]}])`.253. Read events until `session.status_idle` whose `stop_reason.type` is not `requires_action`, or26   `session.status_terminated`.2728Events to handle: `agent.message` (text blocks), `agent.tool_use` / `agent.mcp_tool_use` (if29`evaluated_permission == "ask"`, answer with `user.tool_confirmation` `allow` or `deny`),30`agent.custom_tool_use` (answer with `user.custom_tool_result`).3132Safety defaults worth keeping: `limited` networking, web tools off unless the job needs the web,33the `auto` permission policy, and **deny** any paused tool call when nobody is watching the run.3435The `managed_agent` scaffold is a complete, tested example in both languages. This reference covers36the core flow only; outcomes, vaults, memory stores, scheduled deployments, multi-agent workflows37and webhooks were not exercised by this skill's tests — read the official documentation for them.38
Files main
Menu

Theme