# ConfigurableModelMiddleware

> **Class** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/configurable_model/ConfigurableModelMiddleware)

Swap the model or per-call settings from `runtime.context`.

Reads two optional keys from the runtime context dict:

- `'model'` — a `provider:model` spec (e.g. `"openai:gpt-5"`).
    When present and different from the current model, the request is
    re-routed to the new model.
- `'model_params'` — a dict of extra model settings (e.g.
    `{"temperature": 0}`) that are shallow-merged into the
    request's `model_settings`.

This middleware is typically the outermost layer so it intercepts every
model call before provider-specific middleware (like
`AnthropicPromptCachingMiddleware`) runs.

## Signature

```python
ConfigurableModelMiddleware()
```

## Extends

- `AgentMiddleware`

## Methods

- [`wrap_model_call()`](https://reference.langchain.com/python/deepagents-code/configurable_model/ConfigurableModelMiddleware/wrap_model_call)
- [`awrap_model_call()`](https://reference.langchain.com/python/deepagents-code/configurable_model/ConfigurableModelMiddleware/awrap_model_call)

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/0412009c5441bef8d75a427e1da8909e33ab5b56/libs/code/deepagents_code/configurable_model.py#L238)