Commit f17682d
committed
feat(models): add @extensible decorator to get_api_key()
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 — a workaround that is fragile and bypasses the existing
SecretsManager architecture.
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.
To avoid a circular import (settings.py imports models at module
level, and models importing helpers.extension triggers the cycle
settings -> models -> extension -> subagents -> plugins -> extension),
the top-level `import models` in settings.py is moved inside the
three functions that actually use it. This is the standard Python
pattern for breaking import cycles.
No behavioural change for existing users — the decorator only adds
extension hooks around the existing function, and the deferred
import in settings.py has no performance impact since Python caches
module imports after the first load.1 parent 30a9ed2 commit f17682d
2 files changed
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
223 | 222 | | |
224 | 223 | | |
225 | 224 | | |
| 225 | + | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
312 | 313 | | |
313 | 314 | | |
314 | 315 | | |
| |||
418 | 419 | | |
419 | 420 | | |
420 | 421 | | |
| 422 | + | |
421 | 423 | | |
422 | 424 | | |
423 | 425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
| 202 | + | |
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
| |||
0 commit comments