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_callmiddleware withrequest.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.clientin place is provider-specific and brittle (e.g.ChatBedrockConversehas two boto3 clients, custom-headers event handlers, etc.).
Questions:
-
Is there a supported way to update the bound model on a compiled
create_agent(and on individual subagents indeepagents) without rebuilding? -
If not, is
wrap_model_callwith a model registry the intended pattern for credential rotation across multiple subagents — or is something better planned?
Thanks!