fix(settings): defer models import to prevent NameError after model config migration#1295
Open
Krashnicov wants to merge 1 commit intoagent0ai:developmentfrom
Open
fix(settings): defer models import to prevent NameError after model config migration#1295Krashnicov wants to merge 1 commit intoagent0ai:developmentfrom
Krashnicov wants to merge 1 commit intoagent0ai:developmentfrom
Conversation
…eError Three functions in helpers/settings.py reference the `models` module: - convert_out() - _get_api_key_field() - _load_sensitive_settings() The top-level `import models` creates a circular import risk between settings.py and models.py. When model configuration is moved to the _model_config plugin (PR agent0ai#1262) and the top-level import is eventually removed, these functions would crash with NameError. Fix: move the import into each function body, following the established pattern for circular dependency avoidance in the codebase.
Krashnicov
added a commit
to Deimos-AI/agent-zero-deimos
that referenced
this pull request
Mar 20, 2026
Add @extensible decorator to get_api_key() in models.py, enabling plugins to intercept or replace the API key resolution logic for any LLM provider. Currently, get_api_key() resolves API keys exclusively from OS environment variables via os.getenv(). This means external secrets backends (OpenBao/Vault, AWS Secrets Manager, Azure Key Vault, etc.) cannot provide API keys without injecting them into the process environment. With @extensible, a plugin can intercept the start hook to resolve API keys from any backend, falling through to the default dotenv behaviour when no plugin is active. No behavioural change for existing users — the decorator only adds extension hooks around the existing function. Note: the companion fix for the circular import this previously required (deferred import in settings.py) is submitted separately in PR agent0ai#1295.
Krashnicov
added a commit
to Deimos-AI/agent-zero-deimos
that referenced
this pull request
Mar 26, 2026
Add @extensible decorator to get_api_key() in models.py, enabling plugins to intercept or replace the API key resolution logic for any LLM provider. Currently, get_api_key() resolves API keys exclusively from OS environment variables via os.getenv(). This means external secrets backends (OpenBao/Vault, AWS Secrets Manager, Azure Key Vault, etc.) cannot provide API keys without injecting them into the process environment. With @extensible, a plugin can intercept the start hook to resolve API keys from any backend, falling through to the default dotenv behaviour when no plugin is active. No behavioural change for existing users — the decorator only adds extension hooks around the existing function. Note: the companion fix for the circular import this previously required (deferred import in settings.py) is submitted separately in PR agent0ai#1295.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After the _model_config plugin refactor (PR #1262), the top-level
import modelsinhelpers/settings.pycreates a circular import risk. Three functions still reference themodelsmodule directly:convert_out()— callsmodels.get_api_key()via_get_api_key_field()_get_api_key_field()— callsmodels.get_api_key(provider)_load_sensitive_settings()— callsmodels.get_api_key(provider)If the top-level import is removed (as would be natural during further cleanup), these functions crash with
NameError: name models is not defined.Even with the current code, the circular dependency between
settings.pyandmodels.pycan cause import-order issues in certain initialization sequences.Fix
Move
import modelsfrom the module top-level into each function body that uses it, following the established pattern for circular dependency avoidance already used elsewhere in the codebase (e.g.,from helpers import projectsinside functions).Changes
helpers/settings.py: Remove top-levelimport models, add deferredimport modelsinconvert_out(),_get_api_key_field(), and_load_sensitive_settings()Testing