fix(aux): resolve key_env: prefix in auxiliary task config - #24088
fix(aux): resolve key_env: prefix in auxiliary task config#24088DatTheMaster wants to merge 1 commit into
Conversation
_resolve_task_provider_model() reads per-task config from
auxiliary.<task>.api_key but ignores the key_env and api_key_env
fields, which are the documented way to reference an environment
variable by name instead of hardcoding the key value.
Every other code path that resolves provider credentials already
handles these fields:
- resolve_provider_client() — providers.<name>.key_env / api_key_env
- agent_init.py — fallback entries key_env / api_key_env
- chat_completion_helpers.py — fallback key_env / api_key_env
- hermes_cli/providers.py — provider registry key_env
This adds the same resolution to _resolve_task_provider_model(), so
that:
auxiliary:
title_generation:
provider: openrouter
base_url: https://openrouter.ai/api/v1
key_env: OPENROUTER_API_KEY
actually resolves the key from the environment, instead of silently
ignoring it and sending requests with no auth (HTTP 401).
Precedence matches the provider-level convention: an explicit api_key
value always wins over key_env. The api_key_env snake_case alias is
also accepted, matching resolve_provider_client() behavior.
Updated from original PR: removed the env var bridge changes in
cli.py and gateway/run.py (those 6 tasks read config.yaml directly
via _get_auxiliary_task_config(), no AUXILIARY_* env var bridge
needed). Changed from key_env: prefix convention to key_env /
api_key_env field pattern, matching the established convention used
by resolve_provider_client() and fallback entries.
7 tests covering: key_env resolution with/without base_url,
api_key_env alias, missing env var, explicit api_key precedence,
empty env var, and no-key-env baseline.
Closes NousResearch#20139
8b72267 to
38dd8c6
Compare
|
Rebased onto current |
|
Superseded by #36080 |
Summary
_resolve_task_provider_model()reads per-task config fromauxiliary.<task>.api_keybut ignores thekey_envandapi_key_envfields — the documented way to reference an environment variable by name instead of hardcoding the key value.Every other code path that resolves provider credentials already handles these fields:
resolve_provider_client()—providers.<name>.key_env/api_key_envagent_init.py— fallback entrieskey_env/api_key_envchat_completion_helpers.py— fallbackkey_env/api_key_envhermes_cli/providers.py— provider registrykey_envThis adds the same resolution to
_resolve_task_provider_model(), so that:actually resolves the key from the environment, instead of silently ignoring it and sending requests with no auth (HTTP 401).
What changed
Updated (rebased + trimmed): Removed the
cli.pyandgateway/run.pyenv var bridge changes for 6 auxiliary tasks — those tasks read config.yaml directly via_get_auxiliary_task_config()→load_config(), no env var bridge needed. Also changed from thekey_env:prefix convention to thekey_env/api_key_envfield pattern, matching the established convention used byresolve_provider_client()and fallback entries.agent/auxiliary_client.py— After readingcfg_api_keyfrom task config, resolvekey_env/api_key_envwhen no explicitapi_keyis set. 10 lines added.Testing
tests/agent/test_auxiliary_key_env_prefix.py:key_envresolution withbase_url(→ provider"custom")api_key_envalias resolved identicallykey_envwithoutbase_url(named provider resolves own creds)api_keyisNone(not the literal var name)api_keytakes precedence overkey_envapi_keyisNonekey_env, noapi_key→api_keystaysNonetest_auxiliary_client.pytests passingtest_auxiliary_config_bridge.pytests passingRelationship to upstream fixes
Two recent commits address related but different bugs:
d68a0ec38— passcfg_base_url/cfg_api_keywhen resolving named provider (was dropping them on return)b389796ae— resolveapi_key_envalias inresolve_provider_client()named custom provider pathBoth operate at the provider level (inside
resolve_provider_client()). This PR operates at the task config level (inside_resolve_task_provider_model()). They are complementary — this closes the remaining gap wherekey_env/api_key_envon an auxiliary task entry had no resolution path at all.Closes #20139