fix: update api_key in _try_activate_fallback for subagent auth (#3103)
When fallback activates (e.g. minimax → OpenRouter), self.provider, self.base_url, self.api_mode, and self._client_kwargs were all updated but self.api_key was not. delegate_tool.py reads parent_agent.api_key to pass credentials to child agents, so subagents inherited the stale pre-fallback key (e.g. a minimax key sent to OpenRouter), causing 401 Missing Authentication errors. Add self.api_key = ... in both the anthropic_messages and chat_completions branches of _try_activate_fallback().
This commit is contained in:
@@ -4018,6 +4018,7 @@ class AIAgent:
|
||||
# Build native Anthropic client instead of using OpenAI client
|
||||
from agent.anthropic_adapter import build_anthropic_client, resolve_anthropic_token, _is_oauth_token
|
||||
effective_key = (fb_client.api_key or resolve_anthropic_token() or "") if fb_provider == "anthropic" else (fb_client.api_key or "")
|
||||
self.api_key = effective_key
|
||||
self._anthropic_api_key = effective_key
|
||||
self._anthropic_base_url = getattr(fb_client, "base_url", None)
|
||||
self._anthropic_client = build_anthropic_client(effective_key, self._anthropic_base_url)
|
||||
@@ -4026,6 +4027,7 @@ class AIAgent:
|
||||
self._client_kwargs = {}
|
||||
else:
|
||||
# Swap OpenAI client and config in-place
|
||||
self.api_key = fb_client.api_key
|
||||
self.client = fb_client
|
||||
self._client_kwargs = {
|
||||
"api_key": fb_client.api_key,
|
||||
|
||||
Reference in New Issue
Block a user