fix(agent): try fallback providers at init when primary credential pool is exhausted#17958
Closed
luyao618 wants to merge 1 commit into
Closed
fix(agent): try fallback providers at init when primary credential pool is exhausted#17958luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
…ol is exhausted (NousResearch#17929) When a provider's credential pool has a single entry in 429-cooldown, resolve_provider_client returns None and AIAgent.__init__ raises a misleading RuntimeError suggesting the API key is missing — even when valid fallback_providers are configured. This patch makes __init__ iterate the fallback chain before raising, mirroring the existing in-flight fallback logic in the request loop. If a fallback resolves, the agent initializes against it and sets _fallback_activated=True so _restore_primary_runtime can pick the primary back up after cooldown. Closes NousResearch#17929
Contributor
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.
Summary
When a provider's
credential_poolcontains only one entry and that entry is in 429-cooldown,resolve_provider_clientreturnsNoneandAIAgent.__init__raises a misleadingRuntimeErrorsuggesting the API key is missing — even when validfallback_providersare configured.This patch makes
__init__iterate the fallback chain before raising, mirroring the existing in-flight fallback logic in the request loop. If a fallback resolves, the agent initializes against it and sets_fallback_activated=Trueso_restore_primary_runtimecan pick the primary back up after cooldown.Changes
run_agent.py(~1465): Before raisingRuntimeErrorfor missing credentials, iteratefallback_modelentries and tryresolve_provider_clienton each. If one resolves, use it as the effective primary.run_agent.py(~1560): Preserve_fallback_activatedflag set during init-time fallback (was unconditionally reset toFalse).run_agent.py(~1501): Guard the "No provider configured" raise to skip when fallback was activated.Test plan
tests/run_agent/test_init_fallback_on_exhausted_pool.pywith two tests:test_init_tries_fallback_when_primary_returns_none— verifies agent initializes with fallback providertest_init_raises_when_no_fallback_configured— verifies original error is preserved when no fallback existstests/run_agent/tests passCloses #17929