The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: distinguish callable Anthropic bearer sources from OAuth text
Teknium4270e9ad103a
diff --git a/agent/client_lifecycle.py b/agent/client_lifecycle.pyindex acba3fc82fa..071b6c98553 100644--- a/agent/client_lifecycle.py+++ b/agent/client_lifecycle.py@@ -78,7 +78,10 @@ def _swap_fallback_clients(agent, fb_client, fb_provider: str, fb_model: str, fbagent.api_key = agent._anthropic_api_key = effective_keyagent._anthropic_base_url = fb_base_urlagent._anthropic_client = build_anthropic_client(effective_key, fb_base_url, timeout=timeout)- agent._is_anthropic_oauth = _is_oauth_token(effective_key) if is_anthropic else False+ agent._is_anthropic_oauth = (+ _is_oauth_token(effective_key)+ if is_anthropic and isinstance(effective_key, str) else False+ )agent.client, agent._client_kwargs = None, {}returnagent.api_key = credentialdiff --git a/tests/agent/test_fallback_dynamic_credential.py b/tests/agent/test_fallback_dynamic_credential.pyindex 7996dbc91c2..8444a88ea88 100644--- a/tests/agent/test_fallback_dynamic_credential.py+++ b/tests/agent/test_fallback_dynamic_credential.py@@ -33,3 +33,17 @@ def test_fallback_rebuild_preserves_rotating_and_static_credentials(mode, dynamifinally:client.close()rebuilt.close()+++def test_anthropic_fallback_keeps_callable_without_treating_it_as_oauth_text():+ source = lambda: "fixture-token" # noqa: E731+ client = OpenAI(api_key=source, base_url="http://localhost:1234/v1")+ agent = SimpleNamespace()+ try:+ _swap_fallback_clients(agent, client, "anthropic", "fixture", str(client.base_url), "anthropic_messages")+ assert agent.api_key is source+ assert agent._anthropic_api_key is source+ assert agent._is_anthropic_oauth is False+ agent._anthropic_client.close()+ finally:+ client.close()