CLAUDE LABJP
AGENTS — When you create a Managed Agents session, pass agent_with_overrides to swap the model, system prompt, tools, MCP servers, or skills for that single sessionKEYS — API keys in the Claude Console can now carry an expiration (a preset, a custom duration, or Never), with an email reminder before keys that live 7 days or longer expireMCP — Admins can provision MCP connectors org-wide through their identity provider, starting with Okta, so users get connector access automatically on first loginWORKBENCH — The legacy Workbench at platform.claude.com/workbench retires on August 17, along with the experimental prompt generate, improve, and templatize APIsREVIEW — Claude Code adds a background /code-review so you can keep working while a review runs, with better MCP and Windows path handling alongsideFASTEND — Fast mode for Claude Opus 4.7 is removed today, July 24. Any speed: 'fast' calls need to move over to Opus 4.8AGENTS — When you create a Managed Agents session, pass agent_with_overrides to swap the model, system prompt, tools, MCP servers, or skills for that single sessionKEYS — API keys in the Claude Console can now carry an expiration (a preset, a custom duration, or Never), with an email reminder before keys that live 7 days or longer expireMCP — Admins can provision MCP connectors org-wide through their identity provider, starting with Okta, so users get connector access automatically on first loginWORKBENCH — The legacy Workbench at platform.claude.com/workbench retires on August 17, along with the experimental prompt generate, improve, and templatize APIsREVIEW — Claude Code adds a background /code-review so you can keep working while a review runs, with better MCP and Windows path handling alongsideFASTEND — Fast mode for Claude Opus 4.7 is removed today, July 24. Any speed: 'fast' calls need to move over to Opus 4.8
Articles/API & SDK
API & SDK/2026-07-24Advanced

Swapping Agent Config Per Session From One Shared Definition

A design pattern for running one base Managed Agent and overriding its model, prompt, tools, MCP servers, and skills per session with agent_with_overrides — with a validated factory and the operational traps I hit along the way.

Managed Agents3Agent SDK5MCP46Operations11Multi-tenant

Premium Article

As an indie developer, I run four blog sites with agents that behave almost identically.

The only differences are part of the system prompt, which MCP connectors they reach, and which skills they load. And yet, for a while, I kept a completely separate agent definition for each site.

Every time I fixed something shared, I had to sync four places by hand. Fix one and forget another, and a single night's batch would run on a stale prompt. Watching near-identical definitions drift apart, little by little, quietly wears you down.

Managed Agents' agent_with_overrides finally let me collapse this. One base agent definition. Then, only at the moment a session is created, I swap the model, system prompt, tools, MCP servers, and skills. No new definitions — just a coat of paint applied at runtime.

This article shares how I shaped that swapping into a form where nothing goes wrong, along with the validation code I actually use.

Why "swap per session" beats "add more definitions"

I had three real options.

ApproachSyncing shared partsClarity of the diffRisk of a permissions accident
Separate definition per siteManual, prone to driftGood (independent)Low, but definitions explode
One definition, branch inside the promptNonePoor (bloated)Medium (blurry boundaries)
One definition, override per sessionNoneGood (diff is explicit)Low if designed for it

What decided it was that the diff gathers into one place, as code.

"For this site, only this MCP and this skill" — that difference lines up right before session creation, in a form you can read. Far clearer than burying conditional branches deep inside a prompt.

But this approach has one thing you will trip over first.

The counterintuitive part: overrides replace, they do not merge

At first I assumed an override was "the base plus a diff."

The base agent allows four tools. In one session I wanted to swap one of them for a different tool, so I passed just that one tool in tools.

The result: the other three tools vanished for that session.

A field you specify in agent_with_overrides replaces that whole field. Even for arrays, elements are not merged individually. Pass a single element to tools, and that session has exactly one tool.

What you pass in the overrideResult for that session
Omit the fieldInherits the base value as-is
Empty array []That element becomes "none" (not inherited)
Only some of the elementsOnly the passed elements remain (the rest are gone)

Once stated, it is obvious behavior. But if you let the word "diff" pull you along, you end up with a night batch running with silently fewer tools. I only noticed from the logs.

The principle I took from this is simple. Always pass the final shape of the field. If you want partial add or remove, read the base value, compose it on your side, then pass the result. Composing that safely is the job of the factory below.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
A complete, validated session factory that makes per-session overrides safe
Why overrides replace rather than merge, and the trap that silently dropped my tools
How to decide override granularity so one base agent can drive four sites
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API & SDK2026-06-30
When a Tool Result Is Too Big and Melts Your Context Window: Designing Cursor-Based Pagination
When a list tool returns hundreds of rows at once, an agent's context can collapse in a single call. Here is a cursor-based pagination design that keeps tool output small and protects your token budget, with working code.
API & SDK2026-06-21
Connecting Managed Agents to Services You Don't Want to Expose: MCP Tunnel Design
How to connect Claude Managed Agents to an internal MCP server that is never exposed to the public internet. We cover the MCP tunnel, self-hosted sandboxes, authorization boundaries, and graceful degradation when things break.
API & SDK2026-07-24
When Memory Store Listings Returned Half the Rows: Migrating to agent-memory-2026-07-22
The Managed Agents memory listing behavior changed under agent-memory-2026-07-22: fixed ordering, stricter depth, and segment-based path_prefix matching. Here is how an audit script quietly dropped rows, and how to design a memory access layer that survives the change.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →