← 所有文章
claudeClaude

Ship AI Agents Without Building Infrastructure

Last month I built an agent that monitors our GitHub repos, writes weekly summaries, and posts them to Slack. The agent logic took a day. The infrastructure — sandboxing, credential management, retry logic, keeping it alive — took two weeks.
Claude Managed Agents is Anthropic's answer to that two-week gap. You define what the agent does. They handle where and how it runs.

What You'll Learn


What Problem Does This Solve?

The Messages API gives you Claude's brain. You still need to build the body: the sandbox to run code in, the tool execution layer, the retry logic, the credential store, the checkpoint system so long tasks survive failures.
Managed Agents bundles all of that. You get a container with pre-installed packages, network access, file operations, web browsing, and bash — all managed by Anthropic. Your agent runs in this container and you interact with it through events.
Think of it as the difference between renting a car and building one. The Messages API gives you the engine. Managed Agents gives you the car.

The Four Concepts

Agent — The definition: model, system prompt, tools, MCP servers, skills. Create once, reference by ID across sessions.
Environment — The container: pre-installed packages (Python, Node, Go), network access rules, mounted files. A template you can reuse.
Session — A running instance: one agent + one environment + one task. This is where work happens. Sessions persist file systems and conversation history.
Events — The communication layer: you send user messages, Claude streams back results. You can steer mid-execution or interrupt to change direction.

Getting Started

You need an API key and the beta header. Here's a minimal example:

import anthropic

client = anthropic.Anthropic()

# Create an agent
agent = client.agents.create(
    model="claude-opus-4-7-20260422",
    system="You analyze code repositories.",
    tools=[{"type": "bash"}, {"type": "file_operations"}]
)

# Start a session
session = client.sessions.create(
    agent_id=agent.id,
    environment={"packages": ["python3", "nodejs"]}
)

# Send a task
for event in client.sessions.stream(
    session_id=session.id,
    message="Analyze the repo at github.com/my-org/my-repo"
):
    print(event)

⚠️ Managed Agents is in beta. Add anthropic-beta: managed-agents-2026-04-01 to all API requests. The SDK sets this automatically.


What You're Paying For

$0.08 per session hour on top of standard Claude token pricing.
That session hour covers the container, the sandbox, the tool execution, and the infrastructure. Token costs are separate and follow normal API pricing.
For context: running your own equivalent infrastructure on AWS (EC2 + ECS + secrets manager + monitoring) costs roughly $0.15-0.30/hour before you factor in engineering time to build and maintain it.

💡 Sessions that finish quickly still bill for the minimum increment. If your agent takes 30 seconds, you're paying for less than a minute, not a full hour.


When to Use Managed Agents vs Messages API

Use Managed Agents when:

❌ Managed Agents doesn't support Bedrock, Vertex, or Foundry. It runs on Anthropic's cloud only.


Rate Limits


Building the agent is the creative part. Building the infrastructure to run it is the boring part. Managed Agents lets you skip the boring part.

← 所有文章OctoDock 首頁 →