In-place model update on a compiled create_agent and per-subagent model update for deep agents - is this possible?

Updating a model in-place on a compiled create_agent and per-subagent in deep agents?

Setup: Long-running web-socket sessions. On session connect, I build a deep agent with a main agent and several subagents — each can use a different model (Bedrock, Anthropic, in-house, etc.). Conversations can run 30+ minutes, longer than some of these providers’ credential lifetimes (STS, SSO, rotating tokens).

What I want: When credentials rotate mid-session, update the model on the already-compiled agent or on a specific subagent without rebuilding the graph.

# At t = 0
main_agent = create_agent(
    model=self.driver_model,
    system_prompt=self.system_prompt,
    tools=self.tools,
    middleware=self.middlewares,
    checkpointer=self.checkpointer,
    ...
)
# subagents constructed similarly, each with its own model

# At t = 30 min, after a credential refresh — what I'd like:
main_agent.update_model(fresh_model_with_cred)
main_agent.update_model(fresh_model_with_cred, subagent="research")

What I know already:

  • @wrap_model_call middleware with request.override(model=...) works as a runtime swap.

  • Rebuilding via create_agent(...) works but it could tear down checkpointer/MCP connections and recompile the graph — too heavy for a credential refresh.

  • Mutating model.client in place is provider-specific and brittle (e.g. ChatBedrockConverse has two boto3 clients, custom-headers event handlers, etc.).

Questions:

  1. Is there a supported way to update the bound model on a compiled create_agent (and on individual subagents in deepagents) without rebuilding?

  2. If not, is wrap_model_call with a model registry the intended pattern for credential rotation across multiple subagents — or is something better planned?

Thanks!

hi @NikhilKamathB

AFAIK there is no public update_model / set_model API on a graph compiled by create_agent, and none on the subagents that deepagentsSubAgentMiddleware creates. My search of the current langchain_v1 and deepagents sources returns zero matches for either name on the agent or middleware surface.

wrap_model_call + request.override(model=...) seems to be the intended runtime-swap pattern. It is the mechanism LangChain itself uses internally (e.g. ModelFallbackMiddleware), it is the only public knob for per-call model substitution, and it works equally well for the main agent and for each declarative subagent - as long as you attach the middleware to each subagent’s own middleware stack, or hand SubAgentMiddleware a CompiledSubAgent you built yourself. Direct attribute mutation on ModelRequest was explicitly deprecated in favour of request.override(...).

Caveat worth planning for: in deepagents, create_summarization_middleware(subagent_model, backend) binds a model outside the wrap_model_call chain, so summarization calls will keep using the original credentials. For 30-min sessions with stale STS/SSO tokens, plan credential rotation at a level that covers these out-of-band calls as well