kaxil opened a new pull request, #73967:
URL: https://github.com/apache/airflow/pull/73967

   `AnthropicHook.get_conn()` only returns the synchronous client. Async 
callers, such as an agent loop on `AsyncAnthropic` or a trigger, had to rebuild 
the client from the connection by hand. That meant re-implementing what the 
hook already resolves: the platform (`anthropic`, `bedrock`, `vertex`, `aws`, 
`foundry`), the base URL, `anthropic_client_kwargs` and Workload Identity 
Federation.
   
   `await hook.get_async_conn()` now returns the async counterpart of the 
client `get_conn()` would build: `AsyncAnthropic`, `AsyncAnthropicBedrock`, 
`AsyncAnthropicVertex`, `AsyncAnthropicAWS` or `AsyncAnthropicFoundry`. Each 
call builds a new client, and the caller closes it (`async with` or `await 
client.close()`), as with any `httpx` async client.
   
   ## Design rationale
   
   **One builder for both clients.** `get_conn()` and `get_async_conn()` pass 
their set of SDK classes to the same `_build_client`, so the sync and async 
clients read the connection the same way and cannot drift apart. The classes 
are looked up when the method is called, not bound at import time, so the 
existing tests that patch `hooks.anthropic.Anthropic` keep working. 
`get_conn()`'s behaviour is unchanged.
   
   **The connection is looked up asynchronously, through the hook, and once.** 
`get_async_conn()` fetches the connection with `get_async_connection(conn_id, 
hook=self)`, so a subclass that overrides the connection lookup is honoured, as 
#69140 did for the HTTP hook. It stores the result in the hook's cached 
connection. `hook.platform` and `hook.default_model`, the connection's `model` 
extra, then read that connection instead of making a second, blocking lookup 
from async code. The `hook=` argument arrived in 
`apache-airflow-providers-common-compat` 1.17.0, so this provider's floor on it 
moves from 1.12.0 to 1.17.0, the same floor the HTTP and InfluxDB providers 
already have.
   
   **Workload Identity Federation works unchanged on the async client.** The 
SDK's async client accepts the same synchronous credential and runs its token 
exchange in a worker thread, off the event loop. A test builds a real 
`AsyncAnthropic` from a WIF connection to pin this.
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to