Skip to content

fix(tasks): fall back to settings.json api_key when spawning local agents - #324

Open
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/309-subagent-api-key-fallback
Open

fix(tasks): fall back to settings.json api_key when spawning local agents#324
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/309-subagent-api-key-fallback

Conversation

@sridhar-3009

Copy link
Copy Markdown

Summary

Closes #309

create_agent_task() raised ValueError ("Local agent tasks require
ANTHROPIC_API_KEY...") when a user's API key was configured in
settings.json but not exported as an environment variable. The check
only looked at the explicit api_key argument and os.environ.

Add a lazy fallback that reads settings.json before raising:

effective_api_key = api_key or os.environ.get("ANTHROPIC_API_KEY")
if not effective_api_key:
    from openharness.config.settings import load_settings
    effective_api_key = load_settings().api_key or None
if not effective_api_key:
    raise ValueError(...)

The import is lazy (inside the branch) to avoid any circular-import risk
at module load time.

Test plan

  • Set api_key in ~/.openharness/settings.json, unset ANTHROPIC_API_KEY. Verify that spawning a local agent task succeeds.
  • Verify that an explicit api_key argument still takes precedence over both env var and settings.
  • Verify that ANTHROPIC_API_KEY still takes precedence over settings when both are set.
  • Verify that the ValueError is still raised when none of the three sources provides a key.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Subagent spawn fails with missing ANTHROPIC_API_KEY even when parent process has valid configuration

1 participant