mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-03-17 02:43:09 +00:00
fix: propagate alternative API provider settings to agent subprocesses
When users configured GLM/Ollama/Kimi via the Settings UI, agents still used Claude because conflicting env vars leaked through subprocess env. Root cause: get_effective_sdk_env() set ANTHROPIC_AUTH_TOKEN for GLM but didn't clear ANTHROPIC_API_KEY, which leaked from os.environ. The CLI prioritized the wrong credential. Changes: - registry.py: Clear conflicting auth vars (API_KEY vs AUTH_TOKEN) and Vertex AI vars when building env for alternative providers - client.py: Replace manual os.getenv() loop with get_effective_sdk_env() so agent SDK reads provider settings from the database - autonomous_agent_demo.py: Apply UI-configured provider settings to process env so CLI-launched agents also respect Settings UI config - start.py: Pass --model from settings when launching agent subprocess - server/schemas.py: Allow non-Claude model names when an alternative provider is configured (prevents 422 errors for glm-4.7, etc.) - .env.example: Document env vars for GLM, Ollama, and Kimi providers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -44,8 +44,10 @@ from dotenv import load_dotenv
|
||||
# IMPORTANT: Must be called BEFORE importing other modules that read env vars at load time
|
||||
load_dotenv()
|
||||
|
||||
import os
|
||||
|
||||
from agent import run_autonomous_agent
|
||||
from registry import DEFAULT_MODEL, get_project_path
|
||||
from registry import DEFAULT_MODEL, get_effective_sdk_env, get_project_path
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
@@ -195,6 +197,14 @@ def main() -> None:
|
||||
# Note: Authentication is handled by start.bat/start.sh before this script runs.
|
||||
# The Claude SDK auto-detects credentials from ~/.claude/.credentials.json
|
||||
|
||||
# Apply UI-configured provider settings to this process's environment.
|
||||
# This ensures CLI-launched agents respect Settings UI provider config (GLM, Ollama, etc.).
|
||||
# Uses setdefault so explicit env vars / .env file take precedence.
|
||||
sdk_overrides = get_effective_sdk_env()
|
||||
for key, value in sdk_overrides.items():
|
||||
if value: # Only set non-empty values (empty values are used to clear conflicts)
|
||||
os.environ.setdefault(key, value)
|
||||
|
||||
# Handle deprecated --parallel flag
|
||||
if args.parallel is not None:
|
||||
print("WARNING: --parallel is deprecated. Use --concurrency instead.", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user