fix(tasks): fall back to settings.json api_key when spawning local agents - #324
Open
sridhar-3009 wants to merge 1 commit into
Open
fix(tasks): fall back to settings.json api_key when spawning local agents#324sridhar-3009 wants to merge 1 commit into
sridhar-3009 wants to merge 1 commit into
Conversation
…ents create_agent_task() only checked the explicit api_key argument and the ANTHROPIC_API_KEY environment variable. If a user configured their API key through settings.json (api_key field) without setting the env var, local agent tasks raised a ValueError even though the key was available. Add a third fallback: load settings.json and use its api_key value before giving up. The import is lazy to avoid adding a circular-import risk at module load time. Fixes HKUDS#309
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
Closes #309
create_agent_task()raisedValueError("Local agent tasks requireANTHROPIC_API_KEY...") when a user's API key was configured in
settings.jsonbut not exported as an environment variable. The checkonly looked at the explicit
api_keyargument andos.environ.Add a lazy fallback that reads
settings.jsonbefore raising:The import is lazy (inside the branch) to avoid any circular-import risk
at module load time.
Test plan
api_keyin~/.openharness/settings.json, unsetANTHROPIC_API_KEY. Verify that spawning a local agent task succeeds.api_keyargument still takes precedence over both env var and settings.ANTHROPIC_API_KEYstill takes precedence over settings when both are set.ValueErroris still raised when none of the three sources provides a key.