Managed Deep Agents: can the model be chosen at runtime, without redeploying?

I’d like users of our app to pick between provider models (Gemini / GPT / Claude) on a deployed Managed Deep Agent. The model seems fixed at deploy time, and the two overrides I’d expect to work are accepted and then silently ignored.

Questions:

  1. Is runtime model selection on a deployed MDA supported by any route?
  2. Is one-deployment-per-model the intended pattern instead?

hi @dilip

I think runtime model selection on a deployed MDA is supported, but only through a wrap_model_call middleware in the agent definition. One deployment per model is not the intended pattern.

Why the overrides are ignored:

  • configurable.model is read only by compile_managed_agent_for_eval, the mda eval path. The deploy path compile_managed_agent never touches it
  • context.model does reach runtime.context (LangGraph passes it through even without a schema), but nothing in the stock Deep Agents stack consumes it

Try an async @wrap_model_call middleware that maps an allowlisted runtime.context.model value to init_chat_model(...), passed via define_deep_agent(middleware=[...], context_schema=Context). Clients then send context={"model": "gpt"} on runs.stream, or you create one assistant per model on the same deployment. Both are documented LangChain patterns and require one redeploy to add the hook.

The hook must be async (MDA only uses ainvoke/astream, sync-only hooks raise NotImplementedError). Subagents keep the deploy-time model unless they get the same middleware. The Deep Agents harness profile is chosen from the deploy-time model. Switching providers mid-thread can trip on provider-specific reasoning blocks.

Per-run context via wrap_model_call middleware:

One assistant per model on the same deployment:

@wrap_model_call
async def select_model(request, handler):
    spec = getattr(request.runtime.context, "model", None)
    if spec not in _MODELS:
        raise ValueError(f"Unsupported model {spec!r}.")
    return await handler(request.override(model=_MODELS[spec]))

agent = define_deep_agent(
    name="research-assistant",
    model="openai:gpt-5.5",
    middleware=[select_model],
    context_schema=Context,
)