Skip to content

Add Anthropic provider (apache-airflow-providers-anthropic)#69003

Merged
kaxil merged 3 commits into
apache:mainfrom
astronomer:add-anthropic-provider
Jul 3, 2026
Merged

Add Anthropic provider (apache-airflow-providers-anthropic)#69003
kaxil merged 3 commits into
apache:mainfrom
astronomer:add-anthropic-provider

Conversation

@kaxil

@kaxil kaxil commented Jun 26, 2026

Copy link
Copy Markdown
Member

New provider apache-airflow-providers-anthropic for the Anthropic Claude API, so Dag authors call Claude through the official Anthropic Python SDK instead of embedding SDK calls in task code.

It ships:

  • AnthropicHook — builds the right client for the configured platform: first-party API, Amazon Bedrock, Google Vertex AI, Claude Platform on AWS, and Microsoft Foundry. Supports keyless Workload Identity Federation (configured on the connection or resolved from the environment).
  • AnthropicBatchOperator (deferrable) + AnthropicBatchSensor + AnthropicBatchTrigger — the Message Batches API (submit → defer → collect).
  • AnthropicAgentSessionOperator (deferrable) + AnthropicAgentSessionTrigger — Managed Agents sessions (message and outcome runs).
  • Connection form fields (platform, default model, cloud region/resource) render as labelled inputs via declarative conn-fields, not raw Extra JSON.
image image image

Design rationale

  • Separate provider, not part of common.ai. common.ai is a provider-agnostic abstraction; this provider exposes Anthropic-specific surfaces (Message Batches, Managed Agents, token counting, the platform clients) that do not fit a neutral interface. Users who want a provider-agnostic layer keep using common.ai; users who want direct Claude/SDK features use this one.
  • Batch-centric operators. A one-shot message is a single hook call; the operator-level value is the asynchronous Message Batches workflow, which is what the operator/trigger/sensor model.
  • Airflow 3+ only. Airflow 2 is EOL; the provider uses the Task SDK execution model and the AF3 connection-form metadata.
  • Deferrable and synchronous paths stay symmetric. Deferrable mode releases the worker slot during long batches/sessions; deferrable=False mirrors the same cancel-on-timeout (batch) / archive-on-timeout (session) teardown so neither mode leaks a server-side resource.
  • model on the connection. The default model is read from extra['model'] so it changes without editing DAGs; it falls back to claude-opus-4-8.

Notes / gotchas

  • First-party-only endpoints (Message Batches, token counting, the Models API) are gated to platform in {anthropic, aws}; calling them on Bedrock/Vertex/Foundry raises a clear error rather than a raw 404.
  • Ships as state: not-ready / lifecycle: incubation while the Managed Agents beta surface stabilises.
  • Floors anthropic>=0.101.0 (introduced AnthropicAWS); verified against 0.109.x.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the 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) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@amoghrajesh amoghrajesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a static code review, I am taking it for a spin now to see how it goes.

Comment thread providers/anthropic/src/airflow/providers/anthropic/operators/anthropic.py Outdated
Comment thread providers/anthropic/tests/unit/anthropic/operators/test_agent.py Outdated
Comment thread providers/anthropic/docs/connections.rst Outdated
Comment thread providers/anthropic/docs/connections.rst
Comment thread providers/anthropic/docs/index.rst
Comment thread providers/anthropic/src/airflow/providers/anthropic/hooks/anthropic.py Outdated
Comment thread providers/anthropic/tests/system/anthropic/example_anthropic_agent.py Outdated
Comment thread providers/anthropic/tests/system/anthropic/example_anthropic_batch.py Outdated
Comment thread providers/anthropic/tests/system/anthropic/example_anthropic_agent.py Outdated
@kaxil
kaxil force-pushed the add-anthropic-provider branch from b64bf04 to 260a157 Compare June 26, 2026 12:10
Add a dedicated provider for the Anthropic Claude API so Dag authors can use
Claude through the official Anthropic Python SDK instead of hand-writing SDK
calls in tasks. It offers first-class connection management (first-party API,
Amazon Bedrock, Google Vertex AI, Claude Platform on AWS, Microsoft Foundry,
and keyless Workload Identity Federation) with labelled connection form fields,
plus deferrable Message Batches and Managed Agents session operators, a batch
sensor, and matching triggers.

Targets Airflow 3+ and ships as not-ready / incubation while the Managed Agents
beta surface stabilises.

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the anthropic provider!

Comment thread providers/anthropic/src/airflow/providers/anthropic/operators/agent.py Outdated
Comment thread providers/anthropic/src/airflow/providers/anthropic/hooks/anthropic.py Outdated
vatsrahul1001 and others added 2 commits July 3, 2026 17:54
- Pass aws_region to the AnthropicAWS (Claude Platform on AWS) client
- Cancel batch / archive session on the deferred error event, and on any
  post-submission failure in the synchronous path (billing/resource leak)
- Add async on_kill to both triggers to clean up killed deferred tasks (3.3+)
- Tolerate transient poll errors in the synchronous wait helpers
- Require both description and rubric in the agent outcome
- Rename the batch operators/sensors/triggers modules anthropic.py -> batch.py
  (and their tests) for agent.py/batch.py symmetry
@kaxil
kaxil merged commit a0c1c99 into apache:main Jul 3, 2026
280 of 281 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants