Model configuration management.
Handles loading and saving model configuration from TOML files, providing a structured way to define available models and providers.
Directory for user-level Deep Agents configuration (~/.deepagents).
Path to the user's model configuration file (~/.deepagents/config.toml).
Well-known providers mapped to the env var that holds their API key.
Used by has_provider_credentials to verify credentials before model
creation, so the UI can show a warning icon and a specific error message
(e.g., "ANTHROPIC_API_KEY not set") instead of letting the provider fail at call
time.
Providers not listed here fall through to the config-file check or the langchain registry fallback.
Reset module-level caches so the next call recomputes from scratch.
Intended for tests and for a hypothetical "refresh models" UI action.
Get available models dynamically from installed LangChain provider packages.
Imports model profiles from each provider package and extracts model names.
Results are cached after the first call; use clear_caches() to reset.
Check if credentials are available for a provider.
Checks in order:
config.toml) — takes priority so user
overrides (e.g., custom api_key_env or base_url) are respected.PROVIDER_API_KEY_ENV mapping (anthropic, openai, etc.)._SUPPORTED_PROVIDERS registry — if the provider is known
to init_chat_model, credential status is unknown; the provider
itself will report auth failures at model-creation time.Return the env var name that holds credentials for a provider.
Checks the config file first (user override), then falls back to the
hardcoded PROVIDER_API_KEY_ENV map.
Update the default model in config file.
Reads existing config (if any), updates [models].default, and writes
back using proper TOML serialization.
Remove the default model from the config file.
Deletes the [models].default key so that future launches fall back to
[models].recent or environment auto-detection.
Check if a warning key is suppressed in the config file.
Reads the [warnings].suppress list from config.toml and checks
whether key is present.
Add a warning key to the suppression list in the config file.
Reads existing config (if any), adds key to [warnings].suppress,
and writes back using atomic temp-file rename. Deduplicates entries.
Update the recently used model in config file.
Writes to [models].recent instead of [models].default, so that /model
switches do not overwrite the user's intentional default.
Raised when model configuration or creation fails.
A model specification in provider:model format.
Configuration for a model provider.
The optional class_path field allows bypassing init_chat_model entirely
and instantiating an arbitrary BaseChatModel subclass via importlib.
Setting class_path executes arbitrary Python code from the user's
config file. This has the same trust model as pyproject.toml build
scripts — the user controls their own machine.
Parsed model configuration from config.toml.
Instances are immutable once constructed. The providers mapping is
wrapped in MappingProxyType to prevent accidental mutation of the
globally cached singleton returned by load().