Dev.to AI 🤖 Ai 👁 2 📖 5 min read

Claude Managed Agents Cookbook runs 16 agents on Anthropic’s cloud from a Jupyter notebook

I built the Claude Managed Agents Cookbook because the distance between a hello world and sixteen agents reviewing contracts in parallel is where all the interesting problems live, and none of them fit in a single-file e

Claude Managed Agents Cookbook runs 16 agents on Anthropic’s cloud from a Jupyter notebook

I built the Claude Managed Agents Cookbook because the distance between a hello world and sixteen agents reviewing contracts in parallel is where all the interesting problems live, and none of them fit in a single-file example.

Managed Agents is the part of the Claude API where Anthropic runs the agent loop. You do not own the while loop, you do not host the sandbox, and you do not write the retry logic. It is in beta, it is enabled by default for API accounts, and the SDKs attach the anthropic-beta: managed-agents-2026-04-01 header for you, so there is nothing to request before you start.

Seven modules, each one as a notebook: basics, multi-turn conversations, tools and permissions, files, session control, subagents, dynamic workflows. Every module also ships a -cli companion that does the same thing with Anthropic's ant CLI, if you would rather keep your agents as version-controlled files and run ant apply.

// Detect dark theme var iframe = document.getElementById('tweet-2109336873449455883-695'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2109336873449455883&theme=dark" }

Three objects, and only one of them is per task

The whole mental model is three resources with three different lifetimes.

  1. Environment: the sandboxed container where tools run. You create it once and reference its id. It is not versioned.
  2. Agent: the persisted config, meaning model, system prompt and tools. Created once, and versioned, with the version starting at 1 and incrementing every time you change the config.
  3. Session: an agent instance inside an environment. This is the per-task object. Several sessions can share one environment, each with its own sandbox.

In production you persist environment.id and agent.id. Recreating them on every run is the first mistake everyone makes, mine included.

Setup, and the two traps that cost me an evening

cp .env.example .env
python3 -m venv .venv
source .venv/bin/activate
pip install -U "anthropic>=1.13" python-dotenv jupyter

Python 3.10 or later, because the notebooks use match. In VS Code, pick .venv as the kernel. The notebooks call the real API, so they cost real money: modules 01 to 05 are cents each, while 06 and 07 run several agents and set a budget as a hard cap.

Two failures are worth knowing before you hit them. If every SDK call dies with APIConnectionError: Connection error., you have an old brotli: the HTTP client needs 1.2 or later to decode compressed responses, and the real TypeError is buried underneath. Run pip install -U "brotli>=1.2" and restart the kernel. And for the CLI notebooks, Jupyter's FORCE_COLOR corrupts ant's JSON and YAML output, so the setup cell clears it.

The stream-first rule and the money switch

A stream only delivers events emitted after it opens. Open it before you send anything, or you lose the early events to a race:

with client.beta.sessions.events.stream(session.id) as stream:
    client.beta.sessions.events.send(session.id, events=[...])
    for event in stream:
        ...

To reconnect you open a new stream first, catch up with events.list(), then tail and de-duplicate by event id. A fresh stream has no memory of what happened before it.

The budget is the control I would set first, every time:

# whole US cents, as a string, so this is a $5 cap
budget={"type": "limit", "max_list_cost": {"amount": "500", "currency": "USD"}}

Three things about it that the shape does not tell you. It measures list-price cost, not your billed spend. It is enforced between model requests, so each thread can overshoot by one request. And it can only be attached when the session is created: you can change it or remove it later, but you cannot add one to a session that started without it. When the cap lands, the session goes idle with stop_reason: budget_reached, you raise it with sessions.update(budget=...), and the paused work picks itself up.

Module 7 is the one to show people

Module 06 is delegation you control: a lead agent hands work to subagents you listed, each in its own session thread with isolated history and a shared sandbox. Delegation is one level deep, and a subagent cannot have a multiagent block of its own.

Module 07 is the one that changes how the job feels. You turn on workflows, and the agent writes a program that runs many agents in phases:

multiagent={
    "type": "multiagent_20261001",
    "workflows": {
        "type": "enabled",
        "predefined_agents": [{"type": "agent", "id": reader.id, "version": reader.version}],
    },
    "subagents": {"type": "disabled"},
}

No API call starts a run. You describe the work in a user.message and the agent decides. In the notebook, reviewing six contracts turns into six Haiku agents extracting in parallel, six Opus agents verifying the results, and four failed extractions retried automatically.

Sixteen agents, about seven minutes, under a dollar. Every agent, its timeline, its tokens and its cost show up in Claude Console while it runs, which is why I keep the notebook on the left and the console on the right.

// Detect dark theme var iframe = document.getElementById('tweet-2109439734292287668-160'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2109439734292287668&theme=dark" }

Follow the run with workflow_run.created, workflow_run.phase_started, workflow_run.phase_ended and workflow_run.status_ended. The finish line is the part people get wrong: end_turn while runs are still open means the lead ended its turn, not that the work is done.

You are finished when there are no open runs and then a session.status_idle with end_turn.

The documented ceilings: 64 threads working at once in a run (the API does not guarantee that number), 1,000 agents over a run’s lifetime before thread_limit_error, a 24 hour default run lifetime, and 10 runs open at once per session.

One thing to check before this goes near production work: Managed Agents is not eligible for Zero Data Retention or HIPAA BAA coverage.

Where the cookbook lives

// Detect dark theme var iframe = document.getElementById('tweet-2109336876004122710-512'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2109336876004122710&theme=dark" }

The repo has all seven modules, their CLI companions, the shared sample data, and a step-by-step PDF guide in English and Spanish that covers the VS Code setup and what to watch in the console as each module runs.

You can follow me on my social media:

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.